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

Add recursive and lenient modes to stub generation #2183

Merged
merged 3 commits into from
Sep 27, 2016

Conversation

rtpg
Copy link
Contributor

@rtpg rtpg commented Sep 26, 2016

This is something I personally use for stub generation: whenever stubgen'ing a packages, you'll often want to generate modules inside of it.

If you pass in --recursive, then you'll generate stubs for provided modules and its included modules if its a package.

Also included is --lenient. This will ignore exceptions (just printing a warning) when some module gens fail. This will let you stubgen for larger modules, even if they include some issues. I was having trouble using --recursive without this.

@gvanrossum
Copy link
Member

gvanrossum commented Sep 26, 2016 via email

@@ -574,6 +575,16 @@ def get_qualified_name(o: Node) -> str:
return '<ERROR>'


def walk_packages(packages: List[str]):
for package_name in packages:
package = __import__(package_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not happy that this imports the target package name. At the very least you should honor the --no-import flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point! I don't believe importing is strictly necessary here, since at this point I'm simply trying to walk the packages. I'll look into re-implementing this function without __import__

@@ -664,6 +687,8 @@ def usage() -> None:

Options:
--py2 run in Python 2 mode (default: Python 3 mode)
--recursive traverse listed modules to generate inner package modules as well
--lenient ignore exceptions when trying to generate stubs for modules
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should have a different name, maybe --ignore-errors.

@rtpg
Copy link
Contributor Author

rtpg commented Sep 27, 2016

I renamed the lenient mode to --ignore-errors.

After looking at pkgutil.walk_packages was implemented, I saw that it itself is using __import__, so I decided to simply trigger an error when --no-import and --recursive are used together. It's surely possible to do this without __import__ but I'll leave that to someone who understands loading semantics.

@gvanrossum
Copy link
Member

gvanrossum commented Sep 27, 2016 via email

@gvanrossum gvanrossum merged commit 2c73db5 into python:master Sep 27, 2016
@gvanrossum
Copy link
Member

Thanks! If you want to work more on this just open a new PR. I'm looking to seeing more contributions from you.

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