2010/05/21

pip に upgrade コマンドを追加する

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:
view raw gistfile1.diff hosted with ❤ by GitHub

追記

http://bit.ly/bGF0fe もしかしてPIP_CONFIG_FILEの設定(http://bit.ly/9NvkGx)で[install] upgrade=yes とすると常に--upgradeが実現できるんじゃないかな。あとでやってみようTue May 25 17:23:33 via web

laiso さんの tweet 見て試してみたらその通りだった。これが一番簡単です。

% touch .pip/pip.conf
% echo '[install]' > pip.conf
% echo 'upgrade = true' >> pip.conf

これで install コマンドで常に upgrade オプションが有効になります。 すでにインストール済みのパッケージが更新されていない場合でも再インストールが実行されちゃうのでちょっと微妙だけど、PyPI のフィードとか yolk とかで更新確認してるから問題にはならないかなーと思います。

2010/05/07

zsh で Leiningen コマンドの補完

書いた。これこそ無くてもいいけどあるとちょっとだけ楽よね?良かったら使って!

#compdef lein
local ret=1 state
_arguments ':subcommand:->subcommand' && ret=0
case $state in
subcommand)
subcommands=(
"clean:remove compiled files and dependencies from project"
"compile:ahead-of-time compile the project"
"deps:download and install all dependencies"
"help:display a list of tasks or help for a given task"
"install:install the project and its dependencies in your local repository"
"jar:create a jar file containing the compiled .class files"
"new:create a new project skeleton"
"pom:write a pom.xml file to disk for maven interop"
"test:run the project's tests"
"uberjar:Create a jar including the contents of each of deps"
"upgrade:upgrade leiningen to the latest stable release"
"version:print leiningen's version"
)
_describe -t subcommands 'leiningen subcommands' subcommands && ret=0
esac
return ret
view raw _lein hosted with ❤ by GitHub

2010/05/06

TextMate のインストールとセットアップ

うっかり TextMate のアプリと設定全部消しちゃったから環境再構築中。 とりあえず手順まとめとく。

まずはサイトから dmg イメージをダウンロード。http://macromates.com/

TextMate.app 起動したら Preferences > Software Update を開き、アップデート対象を "Cutting-Edge" にして Check Now をクリックして最新版に更新。 他の設定は適当に。

続いて Plugin をインストール。

  • ProjectPlus
  • AckMate

hetima さんので日本語入力できるようにしてもいいけど、とりあえず必要になってからでいいような気がするので今回はこのまま。

Bundle のインストールは GetBundles http://github.com/adamsalter/getbundles.tmbundle を使って必要なものだけ入れる。

$ cd ~/Library/Application Supports/TextMate/Bundles
$ git clone http://github.com/adamsalter/getbundles.tmbundle.git

簡単ですね!