Pythonの箱庭環境を作成するツールの一つにbuildoutというものがあります。
buildoutの環境を作るためのMakefileを書いてみました
始めに...
Pythonとvirtualenvがすでに使用できる環境であることを前提としています。
想定している操作
想定しているコマンドは次のとおりです。
- make build
- buildout環境を作成します。
- make clean
- buildout環境を削除します。
- make rebuild
- buildout環境を作り直します。
makeではmake buildが行なわれます。
Makefileとbuildout.cfg
Makefile
私はbuildoutを実行する際にMakefileをよく使います。
以下の例では必要最低限の必要な操作を記述しています。
Makefile
# -*- coding: utf-8 -*-
# Need virtualenv
.PHONY: all clean build rebuild
all: env bin/buildout build
echo "buildout finished..."
clean:
rm -rf bin parts eggs develop-eggs .installed env bootstrap.py
build: bin/buildout
bin/buildout -c buildout.cfg
rebuild: clean build
echo
bin/buildout: env
curl https://raw.githubusercontent.com/buildout/buildout/master/bootstrap/bootstrap.py | env/bin/python
env:
virtualenv --no-site-packages env
env/bin/pip install -U setuptools
buildout.cfg
buildout用の設定ファイルbuidout.cfgが必要です。
この設定は何もしません。
buildout.cfg
[buildout]
parts =
動かしてみる
構成
ファイルは前述のMakefileとbuildout.cfgを同じディレクトリに配置しています。
(py3k)$ ls
Makefile buildout.cfg
環境を作成する
make buildを作成してみます。
(py3k)$ make build
virtualenv --no-site-packages env
Using real prefix '/home/examples/.anyenv/envs/pyenv/versions/3.4.2'
New python executable in env/bin/python3.4
Also creating executable in env/bin/python
Installing setuptools, pip...done.
env/bin/pip install -U setuptools
You are using pip version 6.0.3, however version 6.0.6 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
DEPRECATION: --download-cache has been deprecated and will be removed in the future. Pip now automatically uses and configures its cache.
Collecting setuptools from https://pypi.python.org/packages/3.4/s/setuptools/setuptools-11.3.1-py2.py3-none-any.whl#md5=59cd761f2f2b926313bed7f83337e4d7
Downloading setuptools-11.3.1-py2.py3-none-any.whl (500kB)
100% |################################| 503kB 7.3MB/s
Installing collected packages: setuptools
Found existing installation: setuptools 8.2.1
Uninstalling setuptools-8.2.1:
Successfully uninstalled setuptools-8.2.1
Successfully installed setuptools-11.3.1
curl https://raw.githubusercontent.com/buildout/buildout/master/bootstrap/bootstrap.py > bootstrap.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6501 100 6501 0 0 17982 0 --:--:-- --:--:-- --:--:-- 18008
env/bin/python bootstrap.py
Creating directory '/home/examples/ng/var/src/develop/examples/buildout/simple/bin'.
Creating directory '/home/examples/ng/var/src/develop/examples/buildout/simple/parts'.
Creating directory '/home/examples/ng/var/src/develop/examples/buildout/simple/eggs'.
Creating directory '/home/examples/ng/var/src/develop/examples/buildout/simple/develop-eggs'.
Generated script '/home/examples/ng/var/src/develop/examples/buildout/simple/bin/buildout'.
bin/buildout -c buildout.cfg
(py3k)$
作業ディレクトリの中を確認してみましょう。
(py3k)$ ls
Makefile bin buildout.cfg develop-eggs eggs env parts
- Makefile
- buildoutを操作するためのMakefileです。先ほど自分で作成したものです。
- bin
- buildout環境にインストールしたコマンドなどがインストールされるディレクトリです。make buildしたときに作成されます。
- buildout.cfg
- buildout用の設定ファイルです。make buildした場合この設定ファイルが使用されます。
- develop-eggs
- 開発中の自身のパッケージがインストールされるディレクトリです。 pip -eで入れた状態と同じ状態でインストールされるため、 このディレクトリにはPythonのパッケージ用リンクが作成されます。
- eggs
- パッケージがインストールされるディレクトリです。
- parts
- パッケージの設定やツールなどパーツとなるようなファイルなどが配置されます。
環境を削除する
(py3k)$ make clean
rm -rf bin parts eggs develop-eggs .installed env bootstrap.py
削除したことを確認します。
(py3k)$ ls
Makefile buildout.cfg
このときvirualenvで作成した環境もします。もう根こそぎいっちゃいます。
環境を削除して作成する
ではbuild rebuildを実行してみます。
(py3k)$ make rebuild
rm -rf bin parts eggs develop-eggs .installed env bootstrap.py
virtualenv --no-site-packages env
Using real prefix '/home/examples/.anyenv/envs/pyenv/versions/3.4.2'
New python executable in env/bin/python3.4
Also creating executable in env/bin/python
Installing setuptools, pip...done.
env/bin/pip install -U setuptools
You are using pip version 6.0.3, however version 6.0.6 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
DEPRECATION: --download-cache has been deprecated and will be removed in the future. Pip now automatically uses and configures its cache.
Collecting setuptools from https://pypi.python.org/packages/3.4/s/setuptools/setuptools-11.3.1-py2.py3-none-any.whl#md5=59cd761f2f2b926313bed7f83337e4d7
Downloading setuptools-11.3.1-py2.py3-none-any.whl (500kB)
100% |################################| 503kB 3.4MB/s
Installing collected packages: setuptools
Found existing installation: setuptools 8.2.1
Uninstalling setuptools-8.2.1:
Successfully uninstalled setuptools-8.2.1
Successfully installed setuptools-11.3.1
curl https://raw.githubusercontent.com/buildout/buildout/master/bootstrap/bootstrap.py > bootstrap.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6501 100 6501 0 0 16741 0 --:--:-- --:--:-- --:--:-- 16755
env/bin/python bootstrap.py
Creating directory '/home/examples/ng/var/src/develop/examples/buildout/simple/bin'.
Creating directory '/home/examples/ng/var/src/develop/examples/buildout/simple/parts'.
Creating directory '/home/examples/ng/var/src/develop/examples/buildout/simple/eggs'.
Creating directory '/home/examples/ng/var/src/develop/examples/buildout/simple/develop-eggs'.
Generated script '/home/examples/ng/var/src/develop/examples/buildout/simple/bin/buildout'.
bin/buildout -c buildout.cfg
echo
(py3k)$
やっていることはmake cleanをしてからmake buildをしているだけです。