Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would the end-user access the Sphinx generated documentation for a Python package?

I have developed a package in python, and I have created documentation for it using Sphinx.

The relevant part of the folder structure is shown below:

my_package
  setup.py
  my_package
    my_module.py
  docs
    index.rst
    _build
      html
        index.html

The package will be hosted at some location in the LAN that's referred to by PYTHONPATH. My end user will be accessing my package with just import my_package. They wouldn't know where the documentation (or the package for that matter) is located. Using help(my_package) is only going to show the user the documentation within the module.

So, I am wondering how to allow my end-user to access the index.html file? I thought of coding in a method that opens the html file from a specified location, but I didn't like the idea of hardcoding in a path. Is there a standard way of doing this?

like image 369
bluprince13 Avatar asked Feb 21 '26 01:02

bluprince13


1 Answers

To expand on @pkqxdd-s suggestion:

You can easily obtain the path to documentation within modules of my_package

# my_module.py

def get_docs_index_path():
    import os
    my_package_root = os.path.dirname(os.path.dirname(__file__))
    docs_index = os.path.join(my_package_root, 'docs', '_build', 'html', 'index.html')
    return docs_index

Now you could add the path to my_module or my_package docstring, so that users who call help(my_module) will get something like

... 
# original my_module docstring
...

See sphinx docs at <path to your index>

See this question to learn how to add the path from get_docs_index_path() to the docstring.

like image 115
matusko Avatar answered Feb 23 '26 17:02

matusko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!