Python のパッケージのイントールは最近だと pip を使うのが普通だと思いますが、この pip には何故か upgrade のサブコマンドが無いんですよねぇ。 いちいち pip install --upgrade package
ってやるの面倒だし自分で用意してみた。
とはいってもやることは簡単で、lib/pythonx.x/site-packages/pip/commands にある install.py をコピーして upgrade.py にして、中をちょっといじるだけ。 モジュール化って素敵ですね。

--- install.py 2010-05-10 00:23:59.000000000 +0900 | |
+++ upgrade.py 2010-05-26 02:29:47.000000000 +0900 | |
@@ -6,14 +6,14 @@ | |
from pip.basecommand import Command | |
from pip.index import PackageFinder | |
-class InstallCommand(Command): | |
- name = 'install' | |
+class UpgradeCommand(Command): | |
+ name = 'upgrade' | |
usage = '%prog [OPTIONS] PACKAGE_NAMES...' | |
- summary = 'Install packages' | |
+ summary = 'Upgrade packages' | |
bundle = False | |
def __init__(self): | |
- super(InstallCommand, self).__init__() | |
+ super(UpgradeCommand, self).__init__() | |
self.parser.add_option( | |
'-e', '--editable', | |
dest='editables', | |
@@ -86,11 +86,6 @@ | |
help='Check out --editable packages into DIR (default %s)' % src_prefix) | |
self.parser.add_option( | |
- '-U', '--upgrade', | |
- dest='upgrade', | |
- action='store_true', | |
- help='Upgrade all packages to the newest available version') | |
- self.parser.add_option( | |
'-I', '--ignore-installed', | |
dest='ignore_installed', | |
action='store_true', | |
@@ -123,6 +118,7 @@ | |
"If you are using an option with a directory path, be sure to use absolute path.") | |
def run(self, options, args): | |
+ options.upgrade = True | |
if not options.build_dir: | |
options.build_dir = build_prefix | |
if not options.src_dir: |
追記
http://bit.ly/bGF0fe もしかしてPIP_CONFIG_FILEの設定(http://bit.ly/9NvkGx)で[install] upgrade=yes とすると常に--upgradeが実現できるんじゃないかな。あとでやってみよう
laiso さんの tweet 見て試してみたらその通りだった。これが一番簡単です。
% touch .pip/pip.conf % echo '[install]' > pip.conf % echo 'upgrade = true' >> pip.conf
これで install コマンドで常に upgrade オプションが有効になります。 すでにインストール済みのパッケージが更新されていない場合でも再インストールが実行されちゃうのでちょっと微妙だけど、PyPI のフィードとか yolk とかで更新確認してるから問題にはならないかなーと思います。