sphinx autodoc for python doesn't show anything (on readthedocs)

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-09 11:01:17

问题


I have this python package that I'd like to automatically document using Sphinx. I've inserted docstrings in every functions and classes.

I made an account on ReadTheDocs, and did the setup accordingly (i.e., a docs/ dir with a conf.py file). Then, basically, I've tried almost everything: every combination of autodoc::, autofunction::, autoclass::; I tried using the same conf.py file as other packages which documented API (with specific changes made according to my case, of course); but it just doesn't work, the API page remains inexorably empty...


回答1:


Try to add this to your conf.py :

########### TRICK FOUND ON SOME TUTORIAL : ADD IN THE MOCK_MODULES ANY EXTERNAL MODULE YOU'RE USING IN YOUR PACKAGE.

import mock

MOCK_MODULES = ['numpy', 'scipy', 'sklearn', 'matplotlib', 'matplotlib.pyplot', 'scipy.interpolate', 'scipy.special', 'math', '__future__', 'toolboxutilities']
for mod_name in MOCK_MODULES:
    sys.modules[mod_name] = mock.Mock()

In the MOCK_MODULES, add any single external import that your project uses. I had exactly the same problem and this solved it.

Also in the conf.py, don't forget to add the :

sys.path.insert(0, os.path.abspath('../..'))

In your case you already have it but I mention it in case someone else with the same problem would see my answer.



来源:https://stackoverflow.com/questions/40616447/sphinx-autodoc-for-python-doesnt-show-anything-on-readthedocs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!