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

pdoc could (should?) ignore __main__.py #438

Closed
mfrigerio17 opened this issue Sep 18, 2022 · 2 comments
Closed

pdoc could (should?) ignore __main__.py #438

mfrigerio17 opened this issue Sep 18, 2022 · 2 comments

Comments

@mfrigerio17
Copy link

Problem Description

I have a package which contains a command line tool. Thus, for convenience, I have a __main__.py module, to allow to "execute" my package with python -m. That module simply runs the main() function defined elsewhere.

Because pdoc imports all the modules to extract documentation, it actually executes my main function (which starts the tool), obviously causing errors.

Proposal

I suggest that pdoc skips all the __main__.py modules. Or, even better, that an option to choose is added.
The __main__.py modules are added for the sole purpose of making a package "excutable", therefore are not likely to contain useful API documentation.

Alternatives

The issue could probably be circumvented with the guard if __name__ == "__main__" in __main__.py
However, that "if" is not necessary for the regular usage of the package, and the docs also suggest that.

We should not need to change working source code in order to make pdoc work.

Thank you

mhils added a commit to mhils/pdoc that referenced this issue Sep 20, 2022
@mhils
Copy link
Member

mhils commented Sep 20, 2022

Thanks for the pointer to the official docs, I somehow thought that __main__.py files should also have if __name__ == "__main__" guards. If the docs say that's not necessary we should absolutely respect that and ignore those files by default.

@mhils
Copy link
Member

mhils commented Sep 20, 2022

#439 fixes this. If you explicitly want __main__ to be documented, you can include it when invoking pdoc like so:

pdoc my_module my_module.__main__

@mhils mhils closed this as completed in 33f9a57 Sep 20, 2022
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

2 participants