sphinx-apidoc 不在路径中包含根目录
sphinx-apidoc to not include root directory in path
假设我有一个文件夹结构
A\__init__.py
A\math\__init__.py
A\math\others.py
A\stats\__init__.py
A\stats\andthese.py
我的 python 路径中有 A
,所以通常我会 import math.others
,但 import A.math.others
会失败。
现在在文件夹 A
中,我
sphinx-apidoc -o ./documentation ./ --full --force
生成配置文件,如
A\documentation\A.rst
A\documentation\A.math.rst
A\documentation\A.math.others.rst
然后在 A\documentation
我做 make html
。这将失败,因为它无法导入 A.math.others
(我不想让 A 的父文件夹成为 python 路径。)
如何使 sphinx-apidoc
生成配置文件而不包含导入路径中的根目录?
我自己想出来了。
在生成的 A\documentation\conf.py
中,取消注释第 18-20 行
import os
import sys
sys.path.insert(0, u'D:/A')
并将最后一行修改为
sys.path.insert(0, u'D:')
现在所有导入都可以使用了。
假设我有一个文件夹结构
A\__init__.py
A\math\__init__.py
A\math\others.py
A\stats\__init__.py
A\stats\andthese.py
我的 python 路径中有 A
,所以通常我会 import math.others
,但 import A.math.others
会失败。
现在在文件夹 A
中,我
sphinx-apidoc -o ./documentation ./ --full --force
生成配置文件,如
A\documentation\A.rst
A\documentation\A.math.rst
A\documentation\A.math.others.rst
然后在 A\documentation
我做 make html
。这将失败,因为它无法导入 A.math.others
(我不想让 A 的父文件夹成为 python 路径。)
如何使 sphinx-apidoc
生成配置文件而不包含导入路径中的根目录?
我自己想出来了。
在生成的 A\documentation\conf.py
中,取消注释第 18-20 行
import os
import sys
sys.path.insert(0, u'D:/A')
并将最后一行修改为
sys.path.insert(0, u'D:')
现在所有导入都可以使用了。