Hai Vu
Hai Vu

Reputation: 40773

How to customize module name for Sphinx

I am a newbie as far as Sphinx is concern. My project structure is as follow:

__init__.py looks like this:

from folder_actions import *
from ip_actions import *

folder_actions.py looks like this:

'''
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:

class folder_actions.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:

class argparse_actions.FolderCreateAction( ... )

Is there a way for me to achieve this?

Update

Update 2

I don't know why my changes are not pushed to BitBucket, but that irrelevant. please take a look at the same project, pushed to GitHub. I appreciate your help, mzjn.

Upvotes: 7

Views: 4021

Answers (2)

Nikhil Kumar
Nikhil Kumar

Reputation: 1252

Refer this answer which provides a solution.

You can modify your __init__.py file to:

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.

Upvotes: 0

Hai Vu
Hai Vu

Reputation: 40773

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:

.. module:: argparse_actions

Preferably, this line should be the first line of the module docstring.

Upvotes: 4

Related Questions