2
我在使用Sphinx生成Flask應用程序的文檔時遇到問題。沒有進入應用程序的具體細節,其基本結構如下所示。使用Sphinx autodoc文檔Flask應用程序
__all__ = ['APP']
<python 2 imports>
<flask imports>
<custom imports>
APP = None # module-level variable to store the Flask app
<other module level variables>
# App initialisation
def init():
global APP
APP = Flask(__name__)
<other initialisation code>
try:
init()
except Exception as e:
logger.exception(str(e))
@APP.route(os.path.join(<service base url>, <request action>), methods=["POST"])
<request action handler>
if __name__ == '__main__':
init()
APP.run(debug=True, host='0.0.0.0', port=5000)
我在一個VENV安裝獅身人面像與所需的Web服務其他包一起,並生成文件夾是一個文檔的子文件夾,看起來像這樣
docs
├── Makefile
├── _build
├── _static
├── _templates
├── conf.py
├── index.rst
├── introduction.rst
└── make.bat
的conf.py
是由內部產生運行sphinx-quickstart
它包含行
autodoc_mock_imports = [<external imports to ignore>]
確保獅身人面像將忽略列出的外部進口。該index.rst
是標準
.. myapp documentation master file, created by
sphinx-quickstart on Fri Jun 16 12:35:40 2017.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to myapp's documentation!
=============================================
.. toctree::
:maxdepth: 2
:caption: Contents:
introduction
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
,我已經添加了一個introduction.rst
頁記錄應用程序的成員
===================
`myapp`
===================
Oasis Flask app that handles keys requests.
myapp.app
---------------------
.. automodule:: myapp.app
:members:
:undoc-members:
當我運行在docs
我得到HTML輸出在_build
子make html
,但我得到了以下警告
WARNING: /path/to/myapp/docs/introduction.rst:10: (WARNING/2) autodoc: failed to import module u'myapp.app'; the following exception was raised:
Traceback (most recent call last):
File "/path/to/myapp/venv/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 657, in import_object
__import__(self.modname)
File "/path/to/myapp/__init__.py", line 4, in <module>
from .app import APP
File "/path/to/myapp/app.py", line 139, in <module>
@APP.route(os.path.join(<service base url>, <request action>), methods=['GET'])
File "/path/to/myapp/venv/lib/python2.7/posixpath.py", line 70, in join
elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
,我沒有看到,我期待看到該應用的文檔成員像請求處理程序和應用程序init方法。
我不知道問題是什麼,任何幫助將不勝感激。