Sphinx はドキュメントの作成ツール。reStructuredText を使って書くのです。
Python のドキュメントが Sphinx でかかれているらしい。
Overview — Sphinx v1.0 (hg) documentation
Python のインストール
Download Python | Python.org から。
パスを通すのを忘れずに。
easy install のインストール
Ruby で言う gem みたいなものだと思う。
http://peak.telecommunity.com/dist/ez_setup.py をファイルに保存して
> python ez_setup.py
でインストール開始。プロキシ使ってる人は環境変数 HTTP_PROXY 設定しておくこと。
Python インストールしたフォルダにある Scripts にパスを通しておくこと。
rst2pdf のインストール
> easy_install ret2pdf
pdf 作成
> rest2pdf index.rst
index.pdf ができあがり。簡単。
日本語に対応させる
Linux だとフォントの埋め込みしたほうがいいらしいけど、Windows は大丈夫っぽい。
以下の内容の ja.json ってファイルを作る。
{
"fontsAlias" : {
"stdFont": "meiryo",
"stdBold": "meiryob",
"stdItalic": "meiryo",
"stdBoldItalic": "meiryo",
"stdMono": "meiryo"
},
"styles" : [
["base" , {
"wordWrap": "CJK"
}],
["literal" , {
"wordWrap": "None"
}]
]
}
もう一度 PDF 作成
> rst2pdf -s ja --font-path=C:\Windows\fonts index.rst
Sphinx から pdf ができるようにする
ここからが難所。というか遭難中。
Sphinx プロジェクトの設定ファイルに PDF のための設定を追加する
conf.py
extensions = ['rst2pdf.pdfbuilder']
pdf_documents = [
('index', u'redmine-hudson', u'redmine-hudson', u'Toshiyuki Ando'),
]
pdf_stylesheets = ['sphinx','kerning','a4','ja']
pdf_font_path = ['C:\windows\fonts']
pdf_language = "ja"
# How many levels deep should the table of contents be?
pdf_toc_depth = 3
# Add section number to section references
pdf_use_numbered_links = False
# Background images fitting mode
pdf_fit_background_mode = 'scale'
バッチをPDFに対応させる
make.bat
if "%1" == "pdf" (
%SPHINXBUILD% -b pdf %ALLSPHINXOPTS% %BUILDDIR%/pdf
echo.
echo.Build finished. The PDF files are in %BUILDDIR%/pdf
goto end
)
Sphinx ビルド!
make pdf
でも、以下のエラーを吐いて終了。何故なんだろう?
pdfbuilder.py をのぞくしかないのか??
processing redmine-hudson... index [ERROR] pdfbuilder.py:120 BuildEnvironment instance has no attribute 'modules' Traceback (most recent call last): File "U:\Development\Python27\lib\site-packages\rst2pdf-0.15-py2.7.egg\rst2pdf\pdfbuilder.py", line 112, in write appendices=opts.get('pdf_appendices', self.config.pdf_appendices) or []) File "U:\Development\Python27\lib\site-packages\rst2pdf-0.15-py2.7.egg\rst2pdf\pdfbuilder.py", line 203, in assemble_ octree if self.config.pdf_use_modindex and self.env.modules: AttributeError: BuildEnvironment instance has no attribute 'modules' FAILED build succeeded.