从setup.py安装sphinx compilated doc

时间:2015-02-25 13:45:56

标签: python python-sphinx setuptools restructuredtext setup.py

我想使用sphinx和python代码在site-package中安装一些HTML在线文档(使用rSt编译)。我想使用 setup.py

进行此操作

更具体地说,我想将我的*.rst文件压缩为HTML,然后在用户键入python setup.py install时从setup.py文件复制到site-package。

有人知道怎么做吗?我查看了sphinx和setuptools doc,但无法找到信息。

我想要这样做的原因是我的包是一个GUI工具,HTML是它的在线帮助。它显示在GUI的内部浏览器中。

2 个答案:

答案 0 :(得分:2)

如前所述,您需要一个MANIFEST.in文件来包含docs目录:

recursive-include docs *

现在,在您的setup.py中,您可以通过*.rst文件以编程方式生成sphinx文档。

以下是有关如何在python setup.py install运行时自动执行此操作的示例:

from distutils.core import setup

# set dependencies, we need sphinx to build doc
dependencies = ['sphinx']

setup(
    name='my_package'
    # rest of your setup
)

# auto-generate documentation
import sphinx

# automatically build html documentation
# For example:
#   format = 'html'
#   sphinx-src-dir = './doc'
#   sphinx-build-dir = './doc/build'
sphinx.build_main(['setup.py', '-b', '<format>', '<sphinx-src-dir>', '<sphinx-build-dir>'])

像这样,您可以根据需要运行sphinx-buildDocumentation)。

注意:最好在setup.py添加Custom command以分隔文档生成(fe python setup.py make_doc [params])并安装例程({ {1}})。这样,用户可以轻松提供参数python setup.py installformatsphinx-src-dir

答案 1 :(得分:1)

您可以将它们添加到MANIFEST.in中,然后构建包

recursive-include docs *

然后它将与你的鸡蛋一起分发