Can I use sphinx automodule but drop the module name in the signature?

时光总嘲笑我的痴心妄想 提交于 2019-12-25 00:56:42

问题


I have a module mod with some submodule submod and use .. automodule:: mod.submod to generate documentation for it.

The signatures of the elements (functions, classes etc.) in the modules now look like mod.submod.my_function(*args, **kwargs).

I would instead like Sphinx to just show the name of the function, i.e. the signature my_function(*args, **kwargs).

Do I have any way to drop the leading module and submodules in the signature?


回答1:


Yes, try this in docs/mod/submod.rst:

.. automodule:: mod.submod

    .. autofunction:: my_function

See example HTML build and reST source in Pyramid documentation.

Bonus: see the Sphinx docs for 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.



来源:https://stackoverflow.com/questions/55750917/can-i-use-sphinx-automodule-but-drop-the-module-name-in-the-signature

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