在__init __.py中导入的狮身人面像隐藏模块

发布于 2025-02-08 17:24:53 字数 810 浏览 1 评论 0原文

我的软件包具有类似于以下内容的结构:

├── README.md
├── __init__.py
├── module1
│   └── submodule1.py
│   └── submodule2.py
├── module2
│   ├── __init__.py
│   ├── _hiden_submodule1.py
│   ├── _hiden_submodule2.py
│   └── _hiden_submodule3.py

我设法使用sphinx从docstrings中记录所有结构,并带有自动夏季和递归选项:

.. autosummary::
   :toctree: _autosummary
   :template: custom-module-template.rst
   :recursive:

   mymodule

这使我从模块到功能都非常好。

但是,_hiden_submodules*.py函数被导入到__ init __. py

from mymodule.module2._hiden_submodules1 import *
from mymodule.module2._hiden_submodules2 import *
from mymodule.module2._hiden_submodules3 import *

我希望这些函数直接出现在文档中,作为模块的一部分,而不是Module2.hiden_subModules*的一部分。我该如何实现?

My package has a structure, similar to the following:

├── README.md
├── __init__.py
├── module1
│   └── submodule1.py
│   └── submodule2.py
├── module2
│   ├── __init__.py
│   ├── _hiden_submodule1.py
│   ├── _hiden_submodule2.py
│   └── _hiden_submodule3.py

I have managed to document all of it from the docstrings using sphinx, with the autosummary and recursive option:

.. autosummary::
   :toctree: _autosummary
   :template: custom-module-template.rst
   :recursive:

   mymodule

which gives me very nice toctrees from modules to functions.

However, _hiden_submodules*.py functions are imported into the __init__.py of module2:

from mymodule.module2._hiden_submodules1 import *
from mymodule.module2._hiden_submodules2 import *
from mymodule.module2._hiden_submodules3 import *

I would like these functions to appear directly in the documentation as being part of module2, and not part of module2.hiden_submodules*. How can I achieve that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃颗糖壮壮胆 2025-02-15 17:24:53

只需

autosummary_imported_members = True  # Also documents imports in __init__.py

在您的conf.py文件中设置。参见在这里

Simply set

autosummary_imported_members = True  # Also documents imports in __init__.py

in your conf.py file. See here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文