Python sphinx 使用狮身人面像进行非常基本的结构

Python sphinx 使用狮身人面像进行非常基本的结构,python-sphinx,restructuredtext,autodoc,Python Sphinx,Restructuredtext,Autodoc,这是我的文件层次结构: InfoRescue | |_src | |_包括 | |__ui1.py |__uui2.py |_ | |__uUtils | |__uu1.py |__uuuuuuu2.py |_ | |__uu_uu文件 | |_索引rst |_项目rst |__u u u u u |_api | |_api.rst |_包括.rst |__u utils.rst 我正在使用Sphinx生成文档。所有与斯芬克斯有关的东西都在doc目录中 我的索引。rst: .. InfoResc

这是我的文件层次结构:

InfoRescue
|
|_src
|
|_包括
|
|__ui1.py
|__uui2.py
|_
|
|__uUtils
|
|__uu1.py
|__uuuuuuu2.py
|_
|
|__uu_uu文件
|
|_索引rst
|_项目rst
|__u u u u u |_api
|
|_api.rst
|_包括.rst
|__u utils.rst

我正在使用Sphinx生成文档。所有与斯芬克斯有关的东西都在
doc
目录中

我的索引。rst:

.. InfoRescue documentation master file, created by
   sphinx-quickstart on Sun Sep 15 13:52:12 2013.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to InfoRescue's documentation!
======================================

Contents:
========

.. toctree::
   :maxdepth: 2

   project
   api/api
   contact

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
api.rst

InfoRescue API
**********

.. toctree::
    :glob:
    :maxdepth: 1

    **
现在在utils中有to.py文件。这两个文件都不包含类和直接代码,都只包含函数。要记录函数,我可以使用
。。autofunction::utils.u1.functionName
。这是正确的工作,但我必须这样写每一个函数有没有简单的方法来包含所有功能?

假设includes目录中的两个文件都不包含类和函数,只包含一些(直接)代码如何为it生成文档,即使用哪个自动指令?


此外,utils和includes目录中的init.py文件都是空的。我制作了这两个文件,以便可以从.rst文件访问这些目录中的文件是否有任何其他方法可以使我不必创建_init_uuuy.py文件?

Sphinx有一个名为的默认扩展名,它能够扫描源代码并自动生成包含必要的
自动功能
指令的Sphinx输入文件。

对于(直接)代码,您需要在文件的第一个docstring中提供该文档。

存在“\uuu init\uuu.py”文件将目录标记为Python包。你不需要为斯芬克斯这样做。相反,您可以通过编辑“src/doc/conf.py”文件,在“import sys,os”行之后添加行,将目录内容放置在Python路径上,例如:

sys.path.insert(0, os.path.abspath(os.path.join('..', '..', 'utils')))
sys.path.insert(0, os.path.abspath(os.path.join('..', '..', 'includes')))

当然,如果您将docstring放入“utils/\uu init\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuupy”和“includes/\uuuuuuuuuuu init\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

您可能更希望在.rst文件中使用类似的内容:

.. automodule:: i1
   :members:

改进了上面@BarryPie的答案,并且遇到了必须为所有子包添加所有
sys.path.insert
的问题,我在
conf.py
中使用了此代码:

for root, dirs, files in os.walk('../../src'): # path to my source code
    if '__pycache__' not in root: #__pycache__ folder excluded
        sys.path.insert(0, os.path.abspath(root))
所有的子包都是按要求导入的