'Sphinx Documentation for Python project: Excluding module names from the functions in the index
I am trying to build sphinx documentation for a set of utility functions that are run out of an ipython notebook as a pip package.
The main thing I want out of this is a searchable. alphabetized index of the function names that somone can click on and look at their docstrings. I am able to generate this with the standard sphinx html setup but when I go to the index page on my documentation the functions look like this
function1() (in module support_utils.users.utils)
function2() (in module support_utils.documents.utils)
function3() (in module support_utils.documents.utils)
function4() (in module support_utils.reports.utils)
function5() (in module support_utils.formatting.utils)
The module that they are part of is really not relevant here as this is being imported into an Ipython notebook, and in some of the themes this extra info practically breaks the CSS and makes it unreadable. I'd like to exclude everything except the function names from the index. I've been scouring the sphinx documentation site for some sort of option that I can put in the configuration to do this.
Right now I have this awful hack that I put in the conf.py file
def replace_module(app, exception):
import re
with open(os.path.join(DOC_DIRECTORY, 'genindex.html'), 'r') as f:
data = f.read()
new_content = re.sub('\(in module.*\)', '', data)
with open(os.path.join(DOC_DIRECTORY, 'genindex.html'), 'w') as f:
f.write(new_content)
def setup(app):
app.connect('build-finished', replace_module)
While this technically works it's a terrible practice as it's running a script in the conf file, and relies on a hardcoded doc directory. If I make this it's own extension it no longer has access hte DOC_DIRECTORY variable so I'd have a hidden hardcoded directory which is even worse. I know that Sphinx supports custom extension development and there is a way to probably run this regex on individual nodes of the documents before it finishes building, so I do not need to supply the output directory, but I'm wondering if there is some prebuilt configuration option in Sphinx to not show the module names in the Index so I do not have to go through the trouble of developing this extension. This is an internal document
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
