Sphinx无法读取我的函数docString吗?

问题描述

我尝试auto docstring项目中的每个模块功能,但是sphinx-apidoc无法读取我的函数和文档字符串。

我的项目结构是这样的

mktpip
├── docs
│   ├── Makefile
│   ├── build
│   ├── make.bat
│   └── source
│       ├── _static
│       │   └── logo.jpg
│       ├── _templates
│       ├── conf.py
│       ├── index.rst
│       └── reference
│           ├── me.rst
│           └── modules.rst
├── mktpip
│   ├── __init__.py
│   ├── __init__.pyc
│   └── me
|.      |- my_module.py
│       └── __init__.py
├── run.py
├── setup.cfg
└── setup.py

我尝试自动进行文档记录的来源是mktpip/me/my_module.py,它具有类似这样的简单功能

def my_module(a,b):
    """Calculate two number
    
    Args:
        a (int): operand 1
        b (int): operand 2
    
    Returns:
        int: sum of a + b
    """
    return a+b

要自动生成文档字符串,我执行了以下步骤:

(venv) ➜  mktpip copy git:(dev) ✗ sphinx-apidoc -f -o docs/source/reference mktpip/me
Creating file docs/source/reference/me.rst.
Creating file docs/source/reference/modules.rst.

然后,我从*.rst个文件中生成了HTML

(venv) ➜  docs git:(dev) ✗ make clean && make html
Removing everything under 'build'...
Running Sphinx v1.8.5
making output directory...
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 31 source files that are out of date
updating environment: 31 added,0 changed,0 removed
/Users/narun/Documents/mktpip/venv/lib/python2.7/site-packages/sphinx/util/nodes.py:94: FutureWarning:                                                                                                                                        
   The iterable returned by Node.traverse()
   will become an iterator instead of a list in Docutils > 0.16.
  for classifier in reversed(node.parent.traverse(nodes.classifier)):

然后,我打开一个index.html文件,发现它没有读取模块me的功能

(venv) ➜  docs git:(dev) ✗ open build/html/index.html

这是输出:

enter image description here

没有我的函数my_module()及其docString。

conf.py里面,我添加了

docs_dir = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0,docs_dir)

除上述内容外,此处me.rst

的内容
me package
==========

Submodules
----------

me.my\_module module
--------------------

.. automodule:: mktpip.me.my_module
    :members:
    :undoc-members:
    :show-inheritance:


Module contents
---------------

.. automodule:: mktpip.me
    :members:
    :undoc-members:
    :show-inheritance:

这是怎么了?请帮助我,谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...