简体   繁体   中英

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 .

在此处输入图像描述

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)?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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