【发布时间】:2019-03-07 19:05:56
【问题描述】:
我开始研究一个 python 模块,并想“就地”记录代码。所以我用 sphinx-quickstart 在一个子目录中设置了 sphinx,从而产生了这个目录结构(只显示了我编辑的文件):
- 我的项目/
- __init__.py
- main.py
- docs/(狮身人面像目录)
- 构建/
- 来源/
- conf.py
- index.rst
- setup.py
我的 index.rst 包含:
Welcome to My Module's documentation!
=====================================
.. toctree::
:maxdepth: 2
:caption: Contents:
.. automodule:: myproject
:members:
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
当我跑步时
make html
我得到一个缺少自动模块部分的文档,尽管我记录了 main.py 中的每个类和每个方法,如下所示:
class Thing:
"""This class represents Things
:param color: how the thing should look like
"""
def __init__(self, color):
pass
def color(self):
"""Tells you the color of the thing.
:returns: Color string
:rtype: str or unicode
"""
pass
Sys.path 也设置正确,因为它现在在制作时会抛出错误
sys.path.insert(0, os.path.abspath('../../'))
如果相关,我还包括 setup.py:
from setuptools import setup
setup(name='My Module',
version='0.1',
description='Internet of Things',
url='https://example.com',
author='Master Yoda',
author_email='yoda@example.com',
license='GPLv3',
packages=['mymodule'],
zip_safe=False)
我可以改变什么来使 autodoc 工作?
【问题讨论】:
-
我不明白
.. automodule:: mymodule是如何工作的。您没有具有该名称的模块。我希望.. automodule:: myproject.main能够工作。 -
@mzjn 你是对的!我必须编写“automodule::myproject.main”才能使其工作。太感谢了。你想回答这个问题吗? :)
-
我在我的问题中不小心写了
mymodule而不是myproject,但这并不是它在原始代码中不起作用的原因。但是我混合了模块和包并写了myproject而不是myproject.main。
标签: python module python-sphinx autodoc