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

incremental mode e.g. for Bazel? #1864

Open
jsbucy opened this issue Feb 4, 2025 · 2 comments
Open

incremental mode e.g. for Bazel? #1864

jsbucy opened this issue Feb 4, 2025 · 2 comments

Comments

@jsbucy
Copy link

jsbucy commented Feb 4, 2025

Xoogler here, love this tool! I’m trying to write Bazel rules to run pytype which don’t seem to exist as open-source. My current solution effectively ends up running pytype from scratch on each py_library which scales poorly. Does anyone have a solution to this?

I’m imagining a way for the bazel rule impl to run pytype incrementally on one .py file plus the .pyi of the dependencies that bazel previously orchestrated inferring IOW skip analyze_project/ninja. The difficulty with using pytype-single is imports that we don’t want to infer e.g. because they are from @pypi, etc. analyze_project writes default.pyi entries for these in the imports file but with pytype-single these are just missing imports. pytype-single --disable=import-error seems to get around this but I’m not sure if this is actually doing what I want?

@martindemello
Copy link
Contributor

pytype-single will need an imports info file with the paths to the pyi files for all dependencies of the target file. you will likely need to have your bazel file recursively analyse dependencies the same way analyze_project does, and supply a default pyi for any missing ones.

@jsbucy
Copy link
Author

jsbucy commented Feb 5, 2025

Thanks Martin! It seems like there are (at least) 2 ways this could work:
1: run pytype-single with --pythonpath pointed at the tree of .pyi files. pytype throws import-error on the missing imports but this doesn't seem to be fatal, it seems to still infer the input and write the .pyi and if you pass --disable=import-error, it will exit(0) if there aren't any other errors. I'm not familiar enough with the pytype internals to know if this is degrading it in some more subtle way. Possibly there could be a command-line option to provide a default.pyi to use for missing imports?
2: run pytype-single with --imports_info. I had hoped that I could write a ~1-liner with importlab to generate the imports file but it seems like there's a lot more code in analyze_project that you need. If I was going to go this route, I would want to just run PytypeRunner.run() up to setup_build() to generate the imports file rather than try to reproduce all of that logic.

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

No branches or pull requests

2 participants