我开始研究python模块,并希望将代码“就地”记录下来。所以我在sphinx-quickstart的子目录中设置sphinx,导致这个目录结构(只显示我编辑的文件):
我的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='[email protected]',
license='GPLv3',
packages=['mymodule'],
zip_safe=False)
我可以改变什么来使autodoc工作?
main
模块位于myproject
包中。要记录main
,您需要以下内容:
.. automodule:: myproject.main
:members: