牌語備忘録 -pygo

あくまでもメモです。なるべくオフィシャルの情報を参照してください。

牌語備忘録 -pygo

Sphinxでドキュメントを作ってみる

Python2.6から公式ドキュメントツールになったらしいSphinxをちょいと試してみる。
reStructuredTextを変換するっぽい。

sphinxインスコしとく

MacPortsの場合

sudo port install py25-sphinx

~/hoge/fugaディレクトリでquickstartしてみる

G5:~/hoge/fuga username$ sphinx-quickstart docs

いろいろ聞いてくる。

よくわかんないので選択のはデフォルトで(そのままRET)
Project name、Author nameは適当に。
Project versionはとりあえず1で。

Welcome to the Sphinx 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]: 

Inside the root directory, two more directories will be created; ".templates"
for custom HTML templates and ".static" for custom stylesheets and other
static files. Since the leading dot may be inconvenient for Windows users,
you can enter another prefix (such as "_") to replace the dot.
> Name prefix for templates and static dir [.]: 

The project name will occur in several places in the built documentation.
> Project name: projectname
> Author name(s): authorname

Sphinx has the notion of a "version" and a "release" for the
software. Each version can have multiple releases. For example, for
Python the version is something like 2.5 or 3.0, while the release is
something like 2.5.1 or 3.0a1.  If you don't need this dual structure,
just set both to the same value.
> Project version: 1
> Project release [1]: 

The file name suffix for source files. Commonly, this is either ".txt"
or ".rst".  Only files with this suffix are considered documents.
> Source file suffix [.rst]: 

One document is special in that it is considered the top node of the
"contents tree", that is, it is the root of the hierarchical structure
of the documents. Normally, this is "index", but if your "index"
document is a custom template, you can also set this to another filename.
> Name of your master document (without suffix) [index]: 

Please indicate if you want to use one of the following Sphinx extensions:
> autodoc: automatically insert docstrings from modules (y/N) [n]: 
> doctest: automatically test code snippets in doctest blocks (y/N) [n]: 
> intersphinx: link between Sphinx documentation of different projects (y/N) [n]: 

If you are under Unix, a Makefile can be generated for you so that you
only have to run e.g. `make html' instead of invoking sphinx-build
directly.
> Create Makefile? (Y/n) [y]: 

Finished: An initial directory structure has been created.

You should now populate your master file ./index.rst and create other documentation
source files. Use the sphinx-build script to build the docs, like so:

   make <builder>
何が出来たか見てみる
G5:~/hoge/fuga username$ ls -a
.               .build          .templates      conf.py
..              .static         Makefile        index.rst

make htmlしてみる

index.rstをhtmlに

G5:~/hoge/fuga username$ make html
mkdir -p .build/html .build/doctrees
sphinx-build -b html -d .build/doctrees   . .build/html
Sphinx v0.5, building html
loading pickled environment... not found
building [html]: targets for 1 source files that are out of date
updating environment: 1 added, 0 changed, 0 removed
reading sources... index 
pickling environment... done
checking consistency... done
preparing documents... done
writing output... index 
writing additional files... genindex search
copying static files... done
dumping search index... done
dumping object inventory... done
build succeeded.

Build finished. The HTML pages are in .build/html.
なに出来たか見てみる2
G5:~/hoge/fuga username$ ls -a
.               .build          .templates      conf.py
..              .static         Makefile        index.rst

htmlファイルの場所

G5:~/hoge/fuga username$ cd .build/
G5:~/hoge/fuga/.build username$ ls
doctrees        html
G5:~/hoge/fuga/.build username$ cd html
G5:~/hoge/fuga/.build/html username$ ls
_sources        genindex.html   objects.inv     searchindex.js
_static         index.html      search.html

ブラウザで見てみる

G5:~/hoge/fuga/.build/html username$ open -a firefox index.html 


ほほぉぅ

参考サイト