简体   繁体   English

如何为 Sphinx 自定义模块名称

[英]How to customize module name for Sphinx

I am a newbie as far as Sphinx is concern.就狮身人面像而言,我是新手。 My project structure is as follow:我的项目结构如下:

  • argparse_actions/ argparse_actions/
    • argparse_actions/ argparse_actions/
      • __init__.py __init__.py
      • folder_actions.py folder_actions.py
      • ip_actions.py ip_actions.py
    • doc/文档/
      • _build/ _建造/
      • index.rst ==> This is the starting point, home page, or root doc. index.rst ==> 这是起点、主页或根文档。
      • and more...和更多...

__init__.py looks like this: __init__.py 看起来像这样:

from folder_actions import *
from ip_actions import *

folder_actions.py looks like this: folder_actions.py看起来像这样:

'''
Folder Actions
==============

This module implements some reusable custom actions.

.. autoclass:: FolderExistsAction
.. autoclass:: FolderCreateAction
   :members:

'''

# The rest of the code

The generate HTML document looks fine except for this part:生成的 HTML 文档看起来不错,除了这部分:

class folder_actions .folder_actions FolderCreateAction ( ... ) FolderCreateAction ( ... )

I know that the folder_actions module prefix is correct, but I want to change it to use the package name instead, like this:我知道folder_actions模块前缀是正确的,但我想将其更改为使用包名称,如下所示:

class argparse_actions .argparse_actions FolderCreateAction ( ... ) FolderCreateAction ( ... )

Is there a way for me to achieve this?有没有办法让我实现这一目标?

Update更新

  • The root document is in doc/index.rst根文档在doc/index.rst
  • If I move the docstring from folder_actions.py to __init__.py , then the doc will look like this:如果我将文档字符串从folder_actions.py移动到__init__.py ,那么文档将如下所示:

     class __init__.FolderCreateAction( ... )
  • FYI, my project is now on BitBucket仅供参考,我的项目现在在BitBucket 上

Update 2更新 2

I don't know why my changes are not pushed to BitBucket, but that irrelevant.我不知道为什么我的更改没有推送到 BitBucket,但这无关紧要。 please take a look at the same project, pushed to GitHub .请看一下推送到GitHub的同一个项目。 I appreciate your help, mzjn .我感谢你的帮助, mzjn

After a few months of hiatus, I finally figured out the solution: by adding the following line to the docstring of folder_actions.py and ip_action.py modules:经过几个月的中断,我终于找到了解决方案:通过在folder_actions.pyip_action.py模块的文档字符串中添加以下行:

.. module:: argparse_actions

Preferably, this line should be the first line of the module docstring.最好,这一行应该是模块文档字符串的第一行。

Refer this answer which provides a solution.请参阅答案,答案提供了解决方案。

You can modify your __init__.py file to:您可以将__init__.py文件修改为:

from folder_actions import *
from ip_actions import *

__all__ = ['FolderCreateAction']

This lets Sphinx know you want FolderCreateAction to be part of the public API for the package, and will render it is argparse_actions.FolderCreateAction in the documentation.这让 Sphinx 知道您希望FolderCreateAction成为包的公共 API 的一部分,并将在文档中将其呈现为argparse_actions.FolderCreateAction

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM