Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit namespace packages do not generate documentation #298

Open
Yoshanuikabundi opened this issue Jul 21, 2021 · 7 comments
Open

Implicit namespace packages do not generate documentation #298

Yoshanuikabundi opened this issue Jul 21, 2021 · 7 comments

Comments

@Yoshanuikabundi
Copy link

Hi! Thanks for your work on this package, it really saved me from a lot of autosummary-related misery.

I've noticed a bug: the autoapi_python_use_implicit_namespaces option is fantastic, but it doesn't create a page for implicit namespace packages. If I have a Python project with the following file layout:

- package1/
    - package2/
        - __init__.py
        - module1.py
        - package3/
            - module2.py
        - package4/
            - __init__.py
            - module3.py

autoapi with autoapi_python_use_implicit_namespaces=True generates the following documentation:

- package1/
    - package2/
        - index.rst
        - module1/
            - index.rst
        - package3/
            - module2/
                - index.rst
        - package4/
            - index.rst
            - module3/
                - index.rst

In other words, only modules and packages defined with __init__.py files (explicit packages) are documented with an index.rst. Implicit namespace packages, those defined according to PEP420 without __init__.py, are not documented. This leads to Sphinx warnings about their children not being included in any toctree.

According to PEP420, implicit namespace packages are true packages. The user of the library can't tell the difference without digging. I think implicit namespace packages therefore should be documented as true packages, whose members include only their child modules and packages. Ideally they would also have a docstring that suggests that they're implicit namespace packages!

So in my above example, my expected output would be:

- package1/
    - index.rst
    - package2/
        - index.rst
        - module1/
            - index.rst
        - package3/
            - index.rst
            - module2/
                - index.rst
        - package4/
            - index.rst
            - module3/
                - index.rst

Thanks!

@Yoshanuikabundi
Copy link
Author

Oh! Also this is on autoapi 1.6.0, which is the latest available on conda-forge. Sorry if this has been fixed since then! Would be great to get that updated.

@kaxil
Copy link

kaxil commented Mar 14, 2022

We are facing the same issue, any plans to fix this?

@jazzblue
Copy link

jazzblue commented Aug 11, 2022

Same here, facing same issue: autoapi_python_use_implicit_namespaces = True seems like not working and I also wonder if there are any plans to fix it?

@kaxil
Copy link

kaxil commented Aug 12, 2022

Same here, facing same issue: autoapi_python_use_implicit_namespaces = True seems like not working and I also wonder if there are any plans to fix it?

We used this custom template as a workaround and it has worked well for us. Check API reference at https://astronomer-providers.rtfd.io/

@chrisyeh96
Copy link

Still facing the same issue, as of autoapi version 2.1.1.

@mezhaka
Copy link

mezhaka commented Nov 22, 2023

For those who land here from a search engine: there's a --implicit-namespaces option in the sphinx-apidoc.

michael-christen added a commit to michael-christen/toolbox that referenced this issue Sep 20, 2024
## Description

Followed many twists and turns, but have documentation being generated
and published to https://michael-christen.github.io/toolbox/ !

Changes were largely based around getting an initial doc tree setup,
configuring various plugins, and getting published.
- Configuring doc generation to work with bazel by exporting ALL
python_sources as a secondary set of files via `filegroup`s. I'm not a
huge fan of this / prevents usage of the existing `py_*` targets and in
general the cache gets invalidated fairly easily.
- Pulled a random icon of a wrench from
https://www.flaticon.com/free-icon/wrench_4449037
- Vendored the autoapi templates for control over generated
documentation
- Working around a summary issue by modifying the autoapi templates:
  - https://bylr.info/articles/2022/05/10/api-doc-with-sphinx-autoapi/
  - readthedocs/sphinx-autoapi#298
- add `publish-docs` workflow to publish docs when committing to master
- fixed a `.gitignore` of the `build/` directory
- added a bunch of sphinx dependencies
- vendored in
https://github.com/agoessling/rules_sphinx/tree/3280f704d048dd85400334f7513d0ce11bcdc5f3
to build doc html with bazel

We're using a few tools:
- https://github.com/peaceiris/actions-gh-pages for publishing to github
pages
- readthedocs is a nice alternative that could get us mutliple version
support: https://app.readthedocs.org/projects/mchristen-toolbox &
https://docs.readthedocs.io/en/stable/builds.html (though I wasn't able
to get the bazel build working, I think I need to install go as a system
dependency, then bazelisk with that, tbd)
- https://myst-parser.readthedocs.io/en/latest/ is a pretty neat
extension to sphinx that allows you to write most of your documentation
in markdown, I've added a few examples for now
- for documenting python docstrings we've got:
https://github.com/readthedocs/sphinx-autoapi which is a definite
improvement over
https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html,
though looking into
https://github.com/sphinx-extensions2/sphinx-autodoc2#design-and-comparison-to-sphinx-autoapi
could be interesting

Followups:
- [Integrate with C++ autodocs (doxygen) and rust /
rustdoc](#115)
- [Consider only running with bazel, not building as
well](#116)
- We seem to lose all references to generated code; not sure if that's
ok or not, but it does prevent us from treating warnings as errors
#117
- #118
- #119
- #120
- #121
- #122

## Instructions

- To add new python files
- ensure `python_sources` created in the BUILD file and included in
`//docs:docs` sources
  - if new directory, add to `autoapi_dirs` in `docs/conf.py`
- To add new sphinx extensions, modify `docs/conf.py`, add to dep of
`//tools/sphinx:sphinx_build_wrapper`

## Test Plan

```
bazel build //docs:docs

xdg-open bazel-bin/docs/docs_html/index.html
```

To build and open the docs locally.
@momostein
Copy link

Is this issue still being looked at?

I too have this problem...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants