-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
Move MyPy from isolated goal into 'lint' goal and add MyPy whitelist/opt-in type checking #8099
Move MyPy from isolated goal into 'lint' goal and add MyPy whitelist/opt-in type checking #8099
Conversation
Registers MyPy as a 'lint' goal, and implements opt-in 'whitelist' system for type checking. Targets to be type checked are tagged according to the '--whitelisted-tag-name' option, defaults to `type_checked` as used from pantsbuild#7886. Add new mypy_tests for new logic, and update old tests and mypy instances to reflect lint goal change. New mypy logic added to accomodate new opt-in strategy. Mypy will acts according to the following: 1. Filter out non-whitelisted target root 2. Check if all targets now in context are whitelisted, if not we throw an error 3. Continue as normal, collecting python source files and running mypy See pantsbuild#7886 and pantsbuild#6742 for more context
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.
Thanks Mohammed!
contrib/mypy/tests/python/pants_test/contrib/mypy/tasks/test_mypy.py
Outdated
Show resolved
Hide resolved
build-support/bin/mypy.py
Outdated
@@ -6,7 +6,7 @@ | |||
|
|||
|
|||
def main() -> None: | |||
subprocess.run(["./pants", "--tag=+type_checked", "mypy", "::"], check=True) | |||
subprocess.run(["./pants", "--tag=+type_checked", "--lint-skip", "--no-lint-mypy-skip", "lint", "::"], check=True) |
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.
I think you can instead set this to lint.mypy
and ignore the --lint-skip
etc. Also, with your new whitelist feature, the --tag=+type_checked
should be removed.
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.
Turns out lint.mypy isn't enough to just run mypy–one must specify to skip all lint tasks except mypy. Feel free to correct me if that's not the case, though a quick way to see this is to run ./pants lint.mypy
versus ./pants --lint-skip --no-lint-mypy-skip lint
.
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.
Yep, @mabdi3 is right: all tasks in a goal run if any do.
Change tests to reflect new logic General code review fixes
deprecated_options_scope = 'mypy' | ||
deprecated_options_scope_removal_version = '1.20.0.dev2' | ||
|
||
WARNING_MESSAGE = None |
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.
added this field for testing purposes, didn't seem worth spending a lot of time trying to figure out a way to keep track of logging/warning messages, so I used this workaround for now.
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.
You can hardcode the value here.
WARNING_MESSAGE = "[WARNING]: All targets in context should be whitelisted for mypy to run"
@mabdi3 : Are you looking for review on this one? The title still says WIP, so confirming. |
Yeah, just took the [WIP] off. Thanks for the heads up! |
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.
Thanks @mabdi3! Looks mostly good. Just some minor issues.
deprecated_options_scope = 'mypy' | ||
deprecated_options_scope_removal_version = '1.20.0.dev2' | ||
|
||
WARNING_MESSAGE = None |
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.
You can hardcode the value here.
WARNING_MESSAGE = "[WARNING]: All targets in context should be whitelisted for mypy to run"
contrib/mypy/tests/python/pants_test/contrib/mypy/tasks/test_mypy.py
Outdated
Show resolved
Hide resolved
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.
Thanks! Looks great.
will merge once the linty issue is fixed.
|
f1e6697
to
dff9175
Compare
…d include verbose in ci lint check
…di3/pants into mabdi3-mabdi/move-mypy-to-lint-goal
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.
Thanks! just a nit thing
build-support/githooks/pre-commit
Outdated
@@ -62,7 +62,7 @@ if git rev-parse --verify "${MERGE_BASE}" &>/dev/null; then | |||
echo "* Checking lint" | |||
./pants --exclude-target-regexp='testprojects/.*' --changed-parent="${MERGE_BASE}" lint || exit 1 | |||
|
|||
echo "* Checking types for targets marked \`type_checked\`" | |||
echo "* Checking types for targets marked \`type_checked\`" |
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.
nit: let's leave this this file untouched.
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.
Please do not merge until reverting the changes to default --config-file
. Not formally requesting changes because I won't be able to re-review promptly with teaching.
Almost there 🎉!
Next, if any transitive targets from the filtered roots are not whitelisted, a warning | ||
will be printed. | ||
|
||
'In context' meaning in the sub-graph where a whitelisted target is the root |
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.
I think this message might be better moved inline. Out of context, I was confused.
One possibility: end the sentence at line 34 and then line 35 has parentheses with this message.
@@ -34,8 +55,12 @@ def prepare(cls, options, round_manager): | |||
@classmethod | |||
def register_options(cls, register): | |||
register('--mypy-version', default='0.710', help='The version of mypy to use.') | |||
register('--config-file', default=None, | |||
register('--config-file', default='build-support/mypy/mypy.ini', |
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.
Bad change. This should default to None still. We don't expect every Pants user to have a file at build-support/mypy/mypy.ini
. This is how Pants itself happens to do it, but should only be configured in our local pants.ini
- not in the default settings that get used by everyone.
@@ -62,7 +62,6 @@ backend_packages: +[ | |||
"pants.contrib.googlejavaformat", | |||
"pants.contrib.jax_ws", | |||
"pants.contrib.scalajs", | |||
"pants.contrib.mypy", |
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.
Why make this change?
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.
This is needed because the existing
./pants --exclude-target-regexp='testprojects/.*' --changed-parent="${MERGE_BASE}" lint
will fail on c++ related code on resolving different markdown versions, and we don't have a good way to avoid it. You can sanity check by
./pants --pants-backends=pants.contrib.mypy --exclude-target-regexp='testprojects/.*' lint ::
Internally we can still enable it by default because we don't lint/test a bunch unrelated c++ targets in the same context.
@@ -302,9 +301,6 @@ skip: True | |||
[pycheck-newstyle-classes] | |||
skip: True | |||
|
|||
[mypy] | |||
config_file: build-support/mypy/mypy.ini |
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.
See above about reverting this.
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.
I totally agree, a lot of these changes were to subvert a failing lint shard in ci, but this way I don't think mypy works as intended anymore.
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.
Mypy isn't used much in pants, so I think we're sticking with this for now. We should eventually find a way to avoid the c++ resolving issue(s).
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.
I think that we do actually need to configure this right now.
If we were going to temporarily stop configuring it, the right way to do that would be with a TODO
here that disables it and points to a ticket for re-enabling it. But as Eric said, I don't think we should do that without more discussion.
…opt-in type checking (pantsbuild#8099) ### Problem We want to move MyPy into the lint goal and allow for users to opt-in into type_checking for the new whitelisting/opt-in logic, we can make use of the lint goal capabilities instead of rebuilding the wheel See pantsbuild#7886 and pantsbuild#6742 for more context. ### Solution Registers MyPy as a 'lint' goal, and implements opt-in 'whitelist' system for type checking. Targets to be type checked are tagged according to the `--whitelisted-tag-name` option, defaults to `type_checked` as used from pantsbuild#7886. Add new mypy_tests for new logic, and update old tests and mypy instances to reflect lint goal change. New mypy logic added to accommodate new opt-in strategy. Mypy will acts according to the following: 1. Filter out non-whitelisted target roots 2. Check if the transitive deps from the filtered roots are whitelisted, if not we throw a warning 3. Continue as normal, collecting python source files and running mypy
…opt-in type checking (#8099) ### Problem We want to move MyPy into the lint goal and allow for users to opt-in into type_checking for the new whitelisting/opt-in logic, we can make use of the lint goal capabilities instead of rebuilding the wheel See #7886 and #6742 for more context. ### Solution Registers MyPy as a 'lint' goal, and implements opt-in 'whitelist' system for type checking. Targets to be type checked are tagged according to the `--whitelisted-tag-name` option, defaults to `type_checked` as used from #7886. Add new mypy_tests for new logic, and update old tests and mypy instances to reflect lint goal change. New mypy logic added to accommodate new opt-in strategy. Mypy will acts according to the following: 1. Filter out non-whitelisted target roots 2. Check if the transitive deps from the filtered roots are whitelisted, if not we throw a warning 3. Continue as normal, collecting python source files and running mypy
'contrib/mypy/src/python/pants/contrib/mypy/tasks', | ||
], | ||
tags = {'integration_test'}, |
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.
@wisechengyi do you know why this change was introduced?
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.
Do you mean the tag? It was probably because it started out as integration tests, but we kept unit in the end, so please feel free to remove.
Problem
We want to move MyPy into the lint goal and allow for users to opt-in into type_checking
for the new whitelisting/opt-in logic, we can make use of the lint goal capabilities instead of rebuilding the wheel
See #7886 and #6742 for more context.
Solution
Registers MyPy as a 'lint' goal, and implements opt-in 'whitelist' system for type checking.
Targets to be type checked are tagged according to the
--whitelisted-tag-name
option, defaults totype_checked
as used from #7886. Add new mypy_tests for new logic, and update old tests and mypy instances to reflect lint goal change.New mypy logic added to accomodate new opt-in strategy. Mypy will acts according to the following: