-
-
Notifications
You must be signed in to change notification settings - Fork 636
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 mypy plugins and 3rdpary type definitions. #8328
Conversation
@gtrak if you have time to review, thanks in advance. |
The code looks reasonable given 0 experience on this codebase. Is there a way I can point the pants script to this particular commit and run mypy against my product code repo? |
@gtrak Yes. See 'Running from sources' here: https://www.pantsbuild.org/howto_develop.html To encapsulate that a bit, this script in your repo with a #!/usr/bin/env bash
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
# Run pants from sources. Useful for debugging.
# Assumes you have the pantsbuild/pants repo checked out in a sibling dir of this dir, named
# 'pants' but overridable with PANTS_SOURCE.
PANTS_SOURCE="${PANTS_SOURCE:-../pants}"
# When running pants from sources you are likely to be modifying those sources, so
# you won't want pantsd running. You can override this by setting ENABLE_PANTSD=true.
ENABLE_PANTSD="${ENABLE_PANTSD:-false}"
backend_packages=(
"pants.contrib.mypy"
)
pythonpath=(
"${PANTS_SOURCE}/contrib/mypy/src/python"
)
# A list of strings matching the [GLOBAL] plugins in your pants.ini
# save for the one represented by live sources above.
plugins=(
)
function string_list() {
eval local -r list_variable="\${$1[@]}"
echo -n "["
for item in ${list_variable}; do
echo -n "\"${item}\","
done
echo -n "]"
}
export PANTS_VERSION="$(cat "${PANTS_SOURCE}/src/python/pants/VERSION")"
export PANTS_PLUGINS="$(string_list plugins)"
export PANTS_PYTHONPATH="+$(string_list pythonpath)"
export PANTS_BACKEND_PACKAGES="+$(string_list backend_packages)"
export PANTS_ENABLE_PANTSD="${ENABLE_PANTSD}"
export no_proxy=*
exec "${PANTS_SOURCE}/pants" "--no-verify-config" "$@" |
Tried a couple things and got stuck: pantsbuild.pants.contrib.mypy in the plugins section:
Again with just 'pants.contrib.mypy' in the script plugins section minus the
pants.contrib.mypy in the 'backend' section:
Whereas the main pants binary takes about 5 seconds with different output:
Notably, it has a [mypy] [mypy] [check] goal tree, but I can't seem to make the other script do that. |
@gtrak I think I just caused un-needed confusion. Leave |
That matches my scenario 3 I've tried already. It still doesn't actually seem to be running mypy. I went back to pants master and had the same result, so it seems unrelated to the code change in the PR. Running it with:
|
@gtrak I did not read closely enough. The mypy task is installed in the umbrella pants/contrib/mypy/src/python/pants/contrib/mypy/register.py Lines 9 to 10 in 1c85b46
So run |
It works! Here's proof, when I have an incorrect config, it is loading the plugin:
When I add back to mypy.ini:
When I remove the django plugin from mypy.ini, I get all the old type errors as expected. Is there anything else that would be helpful to test here? Curiously, I tried to remove the django-stubs dep from my project, but mypy still works. Is that intentional? |
Looking at the code again, it seems we are hardcoding django-stubs as a dep for the mypy task. I'm not sure if that can have any ill effects down the line. It seems to work for me. |
That should not be the case.
This is not true. Can you provide a pointer to this? Keep in mind the |
Add support to the Pants mypy contrib plugin for loading type definitions and mypy plugins from requirements in the transitive closure of targets being checked. Fixes pantsbuild#8263.
574e8b7
to
6f172ae
Compare
Re-based to resolve conflict. No code changes. |
Hmm, you're right, I was looking at /examples. Still, I'm not passing the flag, so it makes sense that removing django-stubs from requirements would have no effect.
I'll dig in later and try to see where it's grabbing the plugin from. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay, thank you!
Just to close the loop on this, I'm not really sure about my issue in #8328 (comment) . I thought it was caching related, initially. However, I'm finding that this command reliably works: Thanks for fixing it! |
Add support to the Pants mypy contrib plugin for loading type
definitions and mypy plugins from requirements in the transitive closure
of targets being checked.
Fixes #8263.