【发布时间】:2018-09-27 01:27:13
【问题描述】:
我有一个具有以下结构的项目(我想保留):
my_project
├── build # here is where sphinx should dump into
├── requirements.txt
├── make.bat
├── Makefile
├── ... # more config files
├── doc # this is where I want sphinx files to live
│ ├── conf.py
│ └── index.rst
├── src
│ └── my_project
│ ├── __init__.py
│ ├── module_1
│ │ ├── __init__.py
│ │ └── ...
│ └── util
│ ├── __init__.py
│ └── ...
└── tests
├── module_1
│ ├── __init__.py
│ └── ... # testing module 1
└── util
├── __init__.py
└── ... # testing util stuff
我重新创建了on github,可以通过在里面执行my_setup.sh来重新创建结果。
我想从文档字符串构建文档。我使用 sphinx 的快速入门来生成必要的配置,但是当我调用 make hmtl 时,生成的文档不包含来自我的源代码的任何文档字符串,即 my_project/src/my_project 中的所有内容。 Sphinx 的文档有点压倒性,因为我觉得我正在尝试设置一些非常基本的东西。
配置文件中的相关信息(如果我忘记了重要内容,请告诉我):
生成文件
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = my_project
SOURCEDIR = doc
BUILDDIR = build
...
make.bat
set SOURCEDIR=doc
set BUILDDIR=build
set SPHINXPROJ=my_project
...
conf.py
import os
import sys
sys.path.insert(0, os.path.abspath('../src/my_project'))
...
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.coverage',
]
...
我也试过this,但它首先将一堆构建文件放入doc,我宁愿不在那里,而且它也没有找到任何模块(通过省略@987654334来修复@参数):
$ sphinx-apidoc -F -o doc/ src/my_project/
$ cd doc
$ make html
Running Sphinx v1.7.2
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 2 changed, 0 removed
reading sources... [100%] my_project.util
WARNING: autodoc: failed to import module 'my_project'; the following exception was raised:
No module named 'my_project'
WARNING: autodoc: failed to import module 'my_project.util.test_file'; the following exception was raised:
No module named 'my_project'
WARNING: autodoc: failed to import module 'my_project.util'; the following exception was raised:
No module named 'my_project'
looking for now-outdated files... none found
pickling environment... done
checking consistency... /home/arne/workspace/git/my_project/doc/my_project.rst: WARNING: document isn\'t included in any toctree
done
preparing documents... done
writing output... [100%] my_project.util
generating indices... genindex
writing additional pages... search
copying static files... done
copying extra files... done
dumping search index in English (code: en) ... done
dumping object inventory... done
build succeeded, 4 warnings.
【问题讨论】:
-
问题可能是您使用 sphinx-quickstart 创建的原始 Sphinx 项目被覆盖。当您使用
-F选项时,sphinx-apidoc 会创建一个新的 Sphinx 项目(具有不同的 conf.py、Makefile 等)。 -
@mzjn 这绝对是个问题,使用
sphinx-apidoc -o build src/my_project将文件放在正确的位置并使用原始makefile。但是生成的页面仍然不会包含任何文档字符串信息。 -
您需要为每个模块设置一个
automodule指令。您可以在 index.rst 中手动添加它们(例如),或者让 sphinx-apidoc 使用这些指令创建其他 rst 文件。你的automodule指令是什么样的? -
my_module.rst,my_module.util.rst。里面还有modules.rst,但没有任何自动模块信息。 -
这令人困惑。在您的项目结构图中,没有任何名称为
my_module。它说您有一个名为my_project的包,其中包含module_1和util子模块。
标签: python python-sphinx