Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 273
s3rvac Avatar asked Dec 10 '25 09:12

s3rvac


1 Answers

Include

.. currentmodule:: my_package

at the top of your rst files, then you can leave this out in references.

like image 183
joris Avatar answered Dec 12 '25 21:12

joris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!