Shorter references in a Sphinx documentation for a single-package project

允我心安 提交于 2019-12-24 05:49:05

问题


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

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