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

Move MyPy from isolated goal into 'lint' goal and add MyPy whitelist/opt-in type checking #8099

Merged
merged 26 commits into from
Aug 7, 2019

Conversation

mabdi3
Copy link
Contributor

@mabdi3 mabdi3 commented Jul 23, 2019

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 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

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
@mabdi3 mabdi3 changed the title [WIP] Move MyPy from isoltated goal into 'lint' goal [WIP] Move MyPy from isoltated goal into 'lint' goal and add MyPy whitelist/opt-in type checking Jul 23, 2019
@mabdi3 mabdi3 changed the title [WIP] Move MyPy from isoltated goal into 'lint' goal and add MyPy whitelist/opt-in type checking [WIP] Move MyPy from isolated goal into 'lint' goal and add MyPy whitelist/opt-in type checking Jul 23, 2019
Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thanks Mohammed!

@@ -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)
Copy link
Contributor

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.

Copy link
Contributor Author

@mabdi3 mabdi3 Jul 24, 2019

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.

Copy link
Member

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
Copy link
Contributor Author

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.

Copy link
Contributor

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"

@stuhood
Copy link
Member

stuhood commented Jul 26, 2019

@mabdi3 : Are you looking for review on this one? The title still says WIP, so confirming.

@mabdi3
Copy link
Contributor Author

mabdi3 commented Jul 26, 2019

@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!

@mabdi3 mabdi3 changed the title [WIP] Move MyPy from isolated goal into 'lint' goal and add MyPy whitelist/opt-in type checking Move MyPy from isolated goal into 'lint' goal and add MyPy whitelist/opt-in type checking Jul 26, 2019
Copy link
Contributor

@wisechengyi wisechengyi left a 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
Copy link
Contributor

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"

Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Thanks! Looks great.

@wisechengyi
Copy link
Contributor

will merge once the linty issue is fixed.

[31mERROR: All .py files other than __init__.py should start with the header:

@stuhood stuhood added this to the 1.19.x milestone Jul 29, 2019
@mabdi3 mabdi3 force-pushed the mabdi/move-mypy-to-lint-goal branch from f1e6697 to dff9175 Compare July 30, 2019 23:21
Copy link
Contributor

@wisechengyi wisechengyi left a 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

@@ -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\`"
Copy link
Contributor

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.

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a 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
Copy link
Contributor

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',
Copy link
Contributor

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",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why make this change?

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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).

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 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.

@wisechengyi wisechengyi merged commit 1c85b46 into pantsbuild:master Aug 7, 2019
stuhood pushed a commit to twitter/pants that referenced this pull request Aug 7, 2019
…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
wisechengyi pushed a commit that referenced this pull request Aug 8, 2019
…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'},
Copy link
Contributor

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?

Copy link
Contributor

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.

Eric-Arellano added a commit that referenced this pull request Oct 5, 2019
Refactors #8099.

This fixes always printing a warning no matter what about untyped targets. Now we only print this when there actually are untyped targets.
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.

4 participants