[英]How to use multiple paths for Python modules documentation in different directories using Sphinx autodoc?
I am using Sphinx autodoc
to document Python modules in multiple directories.我正在使用 Sphinx
autodoc
来记录多个目录中的 Python 模块。 I already have the rst files for each Python module and can use autodoc
when declaring a path to one directory with the Python modules but I am trying to document Python modules from two different directories.我已经有了每个 Python 模块的 rst 文件,并且可以在使用 Python 模块声明一个目录的路径时使用
autodoc
,但我正在尝试记录来自两个不同目录的 Python 模块。 In the conf.py
file, I used:在
conf.py
文件中,我使用了:
sys.path.insert(0, os.path.abspath("../python_modules_A"))
but would like to have a path to both python_modules_A
and python_modules_B
, since my modules are in both directories.但想要同时拥有
python_modules_A
和python_modules_B
的路径,因为我的模块都在两个目录中。
Given the structure of my project team, I would like to avoid having to restructure the modules into one directory since they are separated by helper functions in python_modules_A
and main objects/classes in python_modules_B
鉴于我的项目团队的结构,我想避免将模块重组到一个目录中,因为它们被
python_modules_A
的辅助函数和python_modules_A
主要对象/类python_modules_B
Below is how my directories are configured:以下是我的目录的配置方式:
sphinx_documentation_setup
conf.py
index.rst
a1.rst
b1.rst
a2.rst
b2.rst
python_modules_A
a1.py
b1.py
python_modules_B
a2.py
b2.py
Just figured out a solution.刚刚想了个办法。 I was able to fix the problem by specifying the path in the automodule directives.
我能够通过在 automodule 指令中指定路径来解决这个问题。 For example, beforehand my automodule directives were as follows:
例如,事先我的自动模块指令如下:
.. automodule:: a1
.. automodule:: a2
but when I switched it to但是当我切换到
.. automodule:: python_modules_A.a1
.. automodule:: python_modules_B.a2
and declared the pathway in the conf.py as:并将 conf.py 中的路径声明为:
sys.path.insert(0, os.path.abspath(".."))
sphinx was able to find my python modules in both directories. sphinx 能够在两个目录中找到我的 python 模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.