[Python] Sphinx Autodoc Without Submodules

Discussão em 'Python' iniciado por Stack, Agosto 15, 2025.

  1. Stack

    Stack Membro Participativo

    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.

    [​IMG]

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

    Continue reading...

Compartilhe esta Página