问题
I am writing a Sphinx documentation for a Python project with a single top-level package my_package
. To reference modules/classes in this package, I currently use
:mod:`my_package.my_module`
:class:`my_package.MyClass`
:class:`my_package.my_module.MyOtherClass`
These references are then generated as
my_package.my_module
my_package.MyClass
my_package.my_module.MyOtherClass
My question is: Is there a way of configuring Sphinx so that I can use shorter references, like
:mod:`my_module`
:class:`MyClass`
:class:`my_module.MyOtherClass`
which generate the references as
my_module
MyClass
my_module.MyOtherClass
In other words, can I make the top-level my_package
implicit?
回答1:
Include
.. currentmodule:: my_package
at the top of your rst files, then you can leave this out in references.
来源:https://stackoverflow.com/questions/26167097/shorter-references-in-a-sphinx-documentation-for-a-single-package-project