问题
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