【问题标题】:Install sphinx compilated doc from setup.py从 setup.py 安装 sphinx 编译的文档
【发布时间】:2015-02-25 13:45:56
【问题描述】:
我想安装一些使用sphinx 制作的 HTML 在线文档(理解为从 rSt 编译)以及 python 代码到站点包中。我想使用 setup.py。
更具体地说,我想将我的 *.rst 文件编译为 HTML,然后在用户键入 python setup.py install 时从 setup.py 文件复制到 site-package。
有人知道怎么做吗?我查看了 sphinx 和 setuptools 文档,但找不到信息。
我想这样做的原因是我的包是一个 GUI 工具,而 HTML 是它的在线帮助。它显示在 GUI 的内部浏览器中。
【问题讨论】:
标签:
python
python-sphinx
setuptools
restructuredtext
setup.py
【解决方案1】:
如前所述,您需要一个 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-build (Documentation)。
注意:最好将Custom command 添加到您的setup.py 以分离文档生成(例如python setup.py make_doc [params])和安装例程(python setup.py install)。这样用户可以很容易地提供参数format、sphinx-src-dir和sphinx-build-dir。
【解决方案2】:
您可以将它们添加到您的 MANIFEST.in 中,然后构建包
recursive-include docs *
然后它会和你的鸡蛋一起分发