问题
Will the Sphinx documentation engine successfully generate documentation on a project that doesn't import well? In particular my project has an exotic dependency. I don't want document generation to depend on this dependency.
Does Sphinx need to import my module and use introspection or does it parse?
回答1:
If you're using the autodoc extension, then yes, your project must be importable. But sometimes it's possible to mock out dependencies in your conf.py
(since, presumably, at the time of import, the dependencies are needed in name only). The Read the Docs documentation has an example of how to do this.
回答2:
Core Sphinx doesn't touch your code at all. The autodoc extension does, and it indeed imports it:
For Sphinx (actually, the Python interpreter that executes Sphinx) to find your module, it must be importable.
来源:https://stackoverflow.com/questions/17368747/will-sphinx-work-with-code-that-doesnt-import-well