0

I have a file layout that looks like:

/my_module
    __init__.py
    submodule1.py
    submodule2.py

I use Sphinx's automodule directive like:

.. automodule:: my_module.submodule1

It produces documents that say my command name is something like: my_module.submodule1.my_function. But my __init__ pulls submodule1 into the my_module namespace. So what I really want is for the documentation to say my_module.my_function instead. Leave out the submodule1, since that's not what users are going to use.

Is there a way to do this?

Paul Vincent Craven
  • 2,027
  • 3
  • 19
  • 24
  • Looks similar to https://stackoverflow.com/q/15115514/407651 and https://stackoverflow.com/q/22096187/407651 – mzjn Nov 13 '17 at 22:04

1 Answers1

0

Not exactly, but you can get close. There is the ~ (tilde) in standard cross-referencing syntax.

If you prefix the content with ~, the link text will only be the last component of the target. For example,

:py:meth:`~Queue.Queue.get`

will refer to Queue.Queue.get but only display get as the link text. This does not work with all cross-reference roles, but is domain specific.

You might be able to use substitutions or the raw directive, but that would bypass the advantage of using autodoc and its directives.

Community
  • 1
  • 1
Steve Piercy
  • 13,693
  • 1
  • 44
  • 57