Pythonのタスク実行フレームワークInvokeを試す
2013-10-07 - ⧖ 1.0 minInvoke は簡単に言えばMakeやRake的なものです。 まだベータ的な感じですが、今後 Fabric にも 取り入れられていくみたい です。 同じような用途に pynt とかもあります。今日はさわりだけ。
Installation
$ pip install invoke
Usage
以下のようなMakefileがあったとして、Invoke用に置き換えてみます。
all :
python setup.py build
.PHONY: test
test :
nosetests
example:
make clean;
easy_install -ZU .
cd examples && python store.py && python search.py && python remove_and_search.py
pypireg:
python setup.py register
python setup.py sdist upload
clean:
rm -rf build dist *.egg-info temp setup.cfg
rm -f */*.pyc
Invokeでは tasks.py が Makefile の役割をします。
from invoke import run , task
@task
def build ():
run ("python setup.py build" )
@task
def test ():
run ("nosetests" )
@task
def example ():
clean ()
run ("easy_install -ZU ." )
run ("cd examples && python store.py && python search.py && python remove_and_search.py" )
@task
def pypireg ():
run ("python setup.py register" )
run ("python setup.py sdist upload" )
@task
def clean ():
run ("rm -rf build dist *.egg-info temp setup.cfg" )
run ("rm -f */*.pyc" )
実行してみます。
$ invoke build
or
$ inv build
結構かんたんに使えます。
Misc
Zsh補完関数書こうかと思いましたが、 $HOME/.zshrc あたりに以下を追加しておけば、まぁなんとかなるでしょう。
compdef _gnu_generic inv invoke
一度使ってみてはいかがでしょうか。でわ。