今日、buildoutでハマったこと

はじめに

先日 エキスパートPythonプログラミング読書会 で教わってきた zc.buildout を使って簡単に Sphinx が実行できる環境を整えるための方法を模索しているわけなのですが、今日はその中で自分が躓いた(というかモノを知らなかっただけ)ところをメモ。

ざっくり環境について

やったこと

bootstrap.py を手に入れてinitまで

まず最初に、何は無くともこれを手に入れて環境を作るところから。

$ cd ~
$ mkdir buildout
$ cd buildout
$ wget "http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py"
$ ls 
buildout

$ python -V
Python 2.4.3
$ python bootstrap.py -d init
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.14.tar.gz
Extracting in /tmp/tmpuJpIrj
Now working in /tmp/tmpuJpIrj/distribute-0.6.14
Building a Distribute egg in /tmp/tmpTjLePX
/tmp/tmpTjLePX/distribute-0.6.14-py2.4.egg
install_dir /tmp/tmpTjLePX
      :
      :
Generated script '/home/USER/buildout/bin/buildout'.
buildout.cfg を書く

Sphinxの実行環境をつくる (http://www.freia.jp/taka/docs/buildout/sphinx.html) にある記述を元にして、以下のように記述。

[buildout]
parts = app docutils
versions = versions

extensions = buildout.dumppickedversions
dump-picked-versions-file = versions.cfg

extends = versions.cfg

[app]
recipe = z3c.recipe.scripts
eggs = 
        sphinx

interpreter = sphinx-py

[docutils]
recipe = zc.recipe.egg:scripts
eggs = 
        docutils

[versions]
#lxml = 2.2.8
buildout実行

設定が書き終わったらbuildoutを実行。

$ touch versions.cfg   #=> ファイルがないと怒られるので、空のファイルを作っておく。
$ bin/buildout
Getting distribution for 'buildout.dumppickedversions'.
install_dir /home/USER/buildout/eggs/tmpSu3nvA
Got buildout.dumppickedversions 0.4.
Getting distribution for 'z3c.recipe.scripts'.
install_dir /home/USER/buildout/eggs/tmpCqwZdF
Got z3c.recipe.scripts 1.0.1.
Getting distribution for 'zc.recipe.egg>=1.3.0'.
install_dir /home/USER/buildout/eggs/tmp20ZVNr
Got zc.recipe.egg 1.3.2.
Installing app.
Getting distribution for 'sphinx'.
Got Sphinx 1.0.7.
Getting distribution for 'Jinja2>=2.2'.
install_dir /home/USER/buildout/eggs/tmpfO0ShP
      :
      :
docutils.parsers.rst.directives.misc: module references __file__
docutils.writers.html4css1.__init__: module references __file__
docutils.writers.pep_html.__init__: module references __file__
docutils.writers.s5_html.__init__: module references __file__
docutils.writers.latex2e.__init__: module references __file__
docutils.writers.newlatex2e.__init__: module references __file__
docutils.writers.odf_odt.__init__: module references __file__
Got docutils 0.7.
*********************************************
Overwriting versions.cfg
*********************************************

$ cat versions.cfg
[versions]
Jinja2 = 2.5.5
Pygments = 1.4
Sphinx = 1.0.7
distribute = 0.6.14
docutils = 0.7
z3c.recipe.scripts = 1.0.1
zc.buildout = 1.5.2
zc.recipe.egg = 1.3.2

これで環境ができました。ついでに、出来上がったbinディレクトリをPATHに追加します。

$ export PATH=~/buildout/bin:$PATH
$ echo $PATH
/home/skumagai/buildout/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin
ところが。。。
$ sphinx-quickstart
Traceback (most recent call last):
  File "/home/skumagai/buildout/bin/sphinx-quickstart", line 17, in ?
    import sphinx.quickstart
  File "/home/skumagai/buildout/eggs/Sphinx-1.0.7-py2.4.egg/sphinx/quickstart.py", line 18, in ?
    from sphinx.util.osutil import make_filename
  File "/home/skumagai/buildout/eggs/Sphinx-1.0.7-py2.4.egg/sphinx/util/__init__.py", line 22, in ?
    import docutils
ImportError: No module named docutils

エラーメッセージを見るとdocutilsが読めていない様子。「あれ?」と思って確認。

$ sphinx-py
Python 2.4.3 (#1, Sep 17 2008, 16:04:01)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-41)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import sys
>>> from pprint import pprint
>>> pprint(sys.path)
['',
 '/home/skumagai/buildout/parts/app',
 '/usr/lib/python24.zip',
 '/usr/lib/python2.4',
 '/usr/lib/python2.4/plat-linux2',
 '/usr/lib/python2.4/lib-tk',
 '/usr/lib/python2.4/lib-dynload',
 '/home/skumagai/buildout/eggs/Sphinx-1.0.7-py2.4.egg',
 '/home/skumagai/buildout/eggs/Jinja2-2.5.5-py2.4.egg',
 '/home/skumagai/buildout/eggs/Pygments-1.4-py2.4.egg',
 '/usr/lib/python2.4/site-packages',
 '/usr/lib/python2.4/site-packages/Numeric',
 '/usr/lib/python2.4/site-packages/gtk-2.0']
>>>

と、なんとdocutilsのeggが入っていない、という事態。
Ububtu10.10, Python2.6.6 の環境で同じbuildout.cfg使ったときは何の問題もなかったんだけどなー。と思いつつ、しみずかわ先生のbuildoutで開発0: zc.buildout で環境を作る — 清水川Web を見ながらbuildout.cfgを書き換える。

[buildout]
parts = app
versions = versions

extensions = buildout.dumppickedversions
dump-picked-versions-file = versions.cfg

extends = versions.cfg

[app]
recipe = z3c.recipe.scripts
eggs = 
        docutils
        sphinx

interpreter = sphinx-py

[versions]
#lxml = 2.2.8

そしてリトライ。

$ bin/buildout
Uninstalling docutils.
Uninstalling app.
Installing app.
Generated script '/home/skumagai/buildout/bin/sphinx-build'.
Generated script '/home/skumagai/buildout/bin/sphinx-quickstart'.
Generated script '/home/skumagai/buildout/bin/sphinx-autogen'.
Generated interpreter '/home/skumagai/buildout/bin/sphinx-py'.
*********************************************
Overwriting versions.cfg
*********************************************
$
$ sphinx-quickstart
Welcome to the Sphinx 1.0.7 quickstart utility.

Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).

Enter the root path for documentation.
> Root path for the documentation [.]:

You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.
> Separate source and build directories (y/N) [n]: y

Inside the root directory, two more directories will be created; "_templates"
for custom HTML templates and "_static" for custom stylesheets and other static
files. You can enter another prefix (such as ".") to replace the underscore.
> Name prefix for templates and static dir [_]:
      :
      :
Finished: An initial directory structure has been created.

You should now populate your master file ./source/index.rst and create other documentation
source files. Use the Makefile to build the docs, like so:
   make builder
where "builder" is one of the supported builders, e.g. html, latex or linkcheck.

$

とゆことで、めでたくSphinxでプロジェクトが作成できましたとさ。

残った疑問

buildout.cfg の書き方の違いが意味するものは何?
というか、きっと単純にbuildoutのドキュメントに書いてありそうな話ではある。ドキュメント読めってことなんでしょうなァ。。。