I have a project structure like this:
package/ __init__.py module.py
__init__.py
contains:
from .module import Class
module.py
contains:
class Class: pass
Using sphinx-apidoc -o package/docs/ package/
and sphinx-build package/docs/ package/docs/_build
, the documentation for Class
looks like this:
class package.module.Class
Bases: object
I'd like to have this output instead:
class package.Class
Bases: object
Or, even better, without the package name:
class Class
Bases: object
The user doesn't have to know in which file the class is defined; this information is completely irrelevant, if not confusing. Since __init__.py
is importing Class
directly into the package's namespace, users will import this class as from package import Class
, not as from package.module import Class
, and I want the docs to reflect that.
Is there a way to have sphinx output the path relative to the package's namespace?
autodoc imports the modules to be documented. If any modules have side effects on import, these will be executed by autodoc when sphinx-build is run. If you document scripts (as opposed to library modules), make sure their main routine is protected by a if __name__ == '__main__' condition.
This is because our conf.py file is located in simpleble-master/docs/source , while our Python source codes, in this case the file simpleble.py , are located inside simpleble-master/simpleble .
Try adding add_module_names = False
in conf.py
While adding add_module_names = False
(refer this answer) makes Sphinx render package.module.Class
as Class
, it does not help if you wanted to render package.module.Class
as package.Class
(i.e., document the class as part of the package
namespace).
If you want Sphinx to document package.module.class
as package.Class
, include the following lines in the __init__.py
for the package (refer this answer):
# This lets you use package.module.Class as package.Class in your code. from .module import Class # This lets Sphinx know you want to document package.module.Class as package.Class. __all__ = ['Class']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With