2

My question is very similar to the one here: Remove package and module name from sphinx function

Is there a way to remove/hide package and module names in sphinx only for a single function or at least for each function in a file (basically changing the global conf.py settings locally), meanwhile they are displayed for the rest of the project?

I've looked for options, like the ones for automodule (:members:, :undoc-members: etc.), but I couldn't find any directive to hide this information.

Community
  • 1
  • 1
phev8
  • 3,493
  • 2
  • 13
  • 23

1 Answers1

3

One option is to use reST markup for cross referencing syntax like so:

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.

Community
  • 1
  • 1
Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
  • 2
    Thanks for your reply. It works well if I want to reference the function somewhere. Does that work somehow for the autodoc directive (.. autofunction:: package1.subpack1.subpack2.mymodule1.function1). The generated line for the function is huge, it would make sense to hide package and subpackage names there. – phev8 Apr 29 '17 at 10:16
  • AFAIK, you can set this globally with [add_module_names](http://www.sphinx-doc.org/en/stable/config.html#confval-add_module_names), but not on a per-file or -function basis. You might look into post-processing the output. – Steve Piercy Apr 29 '17 at 11:58