我在用着Sphinx
版本1.4.5
.
我的项目结构如下:
+ src > main.py
+ docs (generated with sphinx-quickstart)
即使在添加路径后src
文件夹中docs/conf.py
:
sys.path.insert(0, os.path.abspath('../src'))
并生成第一个文件src/main.py
(i.e. docs/src.rst
and docs/modules.rst
) with:
$ sphinx-apidoc -fo docs src
当我尝试构建html
网页包含:
$ make clean
$ make html
它找不到两个src
模块和src/main.py
:
WARNING: autodoc: failed to import module u'src.main'; the following exception was raised
我喜欢在中使用以下代码conf.py
确切地知道当前目录是什么以及目标模块在哪里(以获取文档):
current_dir = os.path.dirname(__file__)
target_dir = os.path.abspath(os.path.join(current_dir, "../../src"))
sys.path.insert(0, target_dir)
print(target_dir)
在本例中,我希望为我的 src 创建文档,请参阅上下文树:
main
├── docs
│ ├── build
│ ├── make.bat
│ ├── Makefile
│ └── source
│ ├── conf.py
│ └── index.rst
│
└── src
├── __init__.py
├── target_module
├── requirements.txt
└── setup.py
接下来,从您的终端:
[user@localhost docs]$ sphinx-apidoc -f -o source/ ../src/target_module
[user@localhost docs]$ make html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)