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

Support documenting namespace packages #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

davidselassie
Copy link

I am hoping to use sphinx-autodoc2 to document PEP 420 namespace packages. These are packages which are assembled together via multiple "distributions" which each provide a submodule within the namespace package. The way this is encoded in the package definition on the filesystem is that the directory which defines the namespace package contains submodules, but does not contain an __init__.py to define it as a module itself.

sphinx-autodoc2 walks the directory tree of all packages and assumes that there will be a Python file for each module that is then parsed by Astroid. Normal packages have the __init__.py but namespace packages do not. This PR changes the module enumeration code to detect when it has been instructed to find all modules in a namespace package and encode that in the module list as the directory path itself represents the module. Then (conveniently) we can use some existing Astroid namespace module builder code to produce the same AST stuff for the rest of the documentation generation pipeline.

@zeehio
Copy link

zeehio commented Sep 22, 2024

Hi,

I wanted to try sphinx-autodoc2 on a package that uses this namespace package.

I was happy to see this PR, and I decided to give it a try.

I got a TypeError exception because at some point the sphinx-docutils package through its system_message function was trying to call our get_source_and_line() with an li value set to None. For context:

This is the implementation of get_source_and_line (in this package):

document.reporter.get_source_and_line = lambda li: (
source_path,
li + source_offset,
)

This is the caller function:

https://sphinx-docutils.readthedocs.io/en/latest/_modules/docutils/utils.html#system_message

So I had to patch this pull request with the following commit:

zeehio@564b716

I guess that since a namespace pkg does not have a file, it's one of the few cases where sphinx-docutils sets li to None, and autodoc2 wasn't expecting that None.

I sent a PR to your branch @davidselassie to include my small patch in your branch so it appears in this PR

@zeehio
Copy link

zeehio commented Sep 22, 2024

Besides my small commit, everything else in this PR worked great for me.

@zeehio zeehio mentioned this pull request Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants