35

it's any way to remove the package and or module name from sphinx doc?

Example: if exist a function called waa inside the module foo.bar, the rst code

.. automodule:: foo.bar :members: 

will generate

foo.bar.waa() 

and i want to output

waa() 

2 Answers 2

55

You can change add_module_names to False in the file conf.py:

# If true, the current module name will be prepended to all description # unit titles (such as .. function::). add_module_names = False 

Then foo.bar.my_function() will display as my_function().

Sign up to request clarification or add additional context in comments.

3 Comments

is there a way to do this per-automodule, rather than at the conf.py level?
This does it for the function/module/class itself, but not for arguments with type annotations. See stackoverflow.com/q/51394955/965332
To do it for specific objects and not globally, see: stackoverflow.com/a/74078513/939364
3

I have a package with submodules and I wanted to still display the submodule name in navigation, as there are multiple duplicate function names across submodules.

For

foo.bar.baz() 

I need to display

bar.baz() 

This makes

  • Navigation is easier as everything does not start with the same letter from the package name

  • Shorter names are more readable without repeating

For this, I created a custom Jinja filter and then modified autosummary's core templates to use it. The filter is injected through a monkey-patch in Sphinx's conf.py.

An example conf.py:

# Monkey-patch autosummary template context from sphinx.ext.autosummary.generate import AutosummaryRenderer def smart_fullname(fullname): parts = fullname.split(".") return ".".join(parts[1:]) def fixed_init(self, app, template_dir=None): AutosummaryRenderer.__old_init__(self, app, template_dir) self.env.filters["smart_fullname"] = smart_fullname AutosummaryRenderer.__old_init__ = AutosummaryRenderer.__init__ AutosummaryRenderer.__init__ = fixed_init 

Then here is the example from _templates/autosummary/module.rst:

{{ fullname | smart_fullname | escape | underline}} Documentation for `{{ fullname }}` module. .. automodule:: {{ fullname }} 

See the full documentation for further examples.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.