-
Notifications
You must be signed in to change notification settings - Fork 541
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
Mypy and pip-installed type stubs #1337
Comments
FYI I'm adding mypy to rules_lint: https://github.com/aspect-build/rules_lint/issue/79 |
Thank, I'll keep an eye on that. Working link: aspect-build/rules_lint#79. In the meantime I found a workaround - running mypy from a stub python script, rather than using the entry_point. py_test sets up the environment so that mypy can find everything, including the type stubs if specified.
Then as before:
and the test passes. |
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. |
I'll keep this open for pyi file inclusion in py_library. I am not sure if there is a good story yet, so it may be useful to consider these in rules_python. |
I'm trying to write a test that runs mypy. I thought I had the following working in rules_python 0.22.0:
I would then do the following:
$ touch requirements_lock.txt $ bazel run --enable_bzlmod :requirements.update $ bazel test --enable_bzlmod :all
...and the mypy test would pass. Now it turns out this only ever worked because I was running
bazel test
from inside a virtualenv where I'd runpip install -r requirements.txt
. I.e. because I was using the system python, not a hermetic toolchain,types-tabulate
installed in the virtualenv was leaking into the test environment, and the test was passing. If I deactivate the virtualenv, the test fails - and addingrequirement("types-tabulate")
to the library doesn't help.Switching to rules_python 0.24.0, with the following diff:
...and running:
$ bazel run --enable_bzlmod :requirements.update $ bazel test --enable_bzlmod :all
...the test fails, regardless of whether I'm in the virtualenv or not, with:
...because the new version of rules_python uses a toolchain by default, and isn't leaking types-tabulate from the virtualenv into the test environment. Note that the standard library import and local import work fine, only the pip-installed stubs are missing.
I'd like to use a toolchain anyway, so I can pin a specific python version, so now my question is: how do I do this properly? Is using a stub shell script the right way to call an entry_point in a test, and how do I get mypy to find the pip-installed stubs?
I'm doing a similar thing with a pylint test, and it's failing with errors like
[E0401(import-error), ] Unable to import 'tabulate'
. On the other hand, linters that don't follow imports (e.g. black) work fine.OS: Ubuntu 22.04
Bazel version: 6.2.1
rules_python version: 0.24.0
The text was updated successfully, but these errors were encountered: