Danny
Danny

Reputation: 35

Sphinx Autodoc Without Submodules

I'm developing a Python package that allows users to import its functions like this:

import mymodule
mymodule.afunction()

I'm documenting the code with sphinx. I first ran sphinx-quickstart, then I changed conf.py to include sys.path.insert(0, os.path.abspath(‘../../src/mymodule’)). Then I ran sphinx-apidoc -f -o source ../src/mymodule and make html. The directory structure is like this:

├── doc
│   ├── Makefile
│   ├── build
│   ├── make.bat
│   └── source
│       ├── _static
│       ├── _templates
│       ├── conf.py
│       ├── index.rst
│       ├── modules.rst
│       └── mymodule.rst
└── src
    └── mymodule
        ├── __init__.py
        └── modulecode.py

The output lists a "mymodule.modulecode" submodule. But because of my __init__py, users don't explicitly import modulecode.

enter image description here

Is there an automated way of making the sphinx documentation list the function mymodule.afunction() (which is accessed by the user), instead of mymodule.modulecode.afunction() (which the user doesn't call)?

Upvotes: 0

Views: 1672

Answers (1)

Danny
Danny

Reputation: 35

Thanks to mzjn for the helpful comments on my original question! As discussed in the comments, I needed to do 2 things:

  1. Add __all__=[list of defined functions] to my __init__.py
  2. Delete the entire mymodule.modulecode module section from mymodule.rst.

Upvotes: 1

Related Questions