-
-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move MyPy from isolated goal into 'lint' goal and add MyPy whitelist/…
…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
- Loading branch information
1 parent
f095e7d
commit 299bb04
Showing
10 changed files
with
156 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
contrib/mypy/tests/python/pants_test/contrib/mypy/tasks/test_mypy.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from unittest.mock import MagicMock | ||
|
||
from pants.backend.python.targets.python_library import PythonLibrary | ||
from pants_test.task_test_base import TaskTestBase | ||
|
||
from pants.contrib.mypy.tasks.mypy_task import MypyTask | ||
|
||
|
||
class MyPyTests(TaskTestBase): | ||
|
||
@classmethod | ||
def task_type(cls): | ||
return MypyTask | ||
|
||
def test_throws_no_warning_on_all_whitelisted_target_roots(self) -> None: | ||
t1 = self.make_target('t1', PythonLibrary, tags=['type_checked']) | ||
t2 = self.make_target('t2', PythonLibrary, tags=['type_checked']) | ||
task = self.create_task(self.context(target_roots=[t1, t2])) | ||
self.set_options(whitelist_tag_name='type_checked') | ||
task.execute() | ||
|
||
def test_throws_no_warning_on_some_whitelisted_target_roots_but_all_whitelisted_in_context(self) -> None: | ||
t1 = self.make_target('t1', PythonLibrary) | ||
t2 = self.make_target('t2', PythonLibrary, tags=['type_checked']) | ||
t3 = self.make_target('t3', PythonLibrary, tags=['type_checked'], dependencies=[t2]) | ||
task = self.create_task(self.context(target_roots=[t1, t3])) | ||
self.set_options(whitelist_tag_name='type_checked') | ||
task.execute() | ||
|
||
def test_throws_warning_on_some_whitelisted_target_roots_but_all_whitelisted_in_context(self) -> None: | ||
t1 = self.make_target('t1', PythonLibrary) | ||
t2 = self.make_target('t2', PythonLibrary, tags=['something_else']) | ||
t3 = self.make_target('t3', PythonLibrary, tags=['type_checked'], dependencies=[t2]) | ||
self.set_options(whitelist_tag_name='type_checked') | ||
task = self.create_task(self.context(target_roots=[t1, t3])) | ||
task._whitelist_warning = MagicMock() | ||
task.execute() | ||
task._whitelist_warning.assert_called() | ||
|
||
def test_throws_warning_on_all_whitelisted_target_roots_but_some_whitelisted_transitive_targets(self) -> None: | ||
t1 = self.make_target('t1', PythonLibrary, tags=['type_checked']) | ||
t2 = self.make_target('t2', PythonLibrary, tags=['something_else']) | ||
t3 = self.make_target('t3', PythonLibrary, tags=['type_checked'], dependencies=[t2]) | ||
t4 = self.make_target('t4', PythonLibrary, tags=['type_checked'], dependencies=[t3]) | ||
self.set_options(whitelist_tag_name='type_checked') | ||
task = self.create_task(self.context(target_roots=[t1, t4])) | ||
task._whitelist_warning = MagicMock() | ||
task.execute() | ||
task._whitelist_warning.assert_called() | ||
|
||
def test_throws_no_warning_if_no_whitelist_specified(self) -> None: | ||
t1 = self.make_target('t1', PythonLibrary) | ||
task = self.create_task(self.context(target_roots=[t1])) | ||
task._whitelist_warning = MagicMock() | ||
task.execute() | ||
task._whitelist_warning.assert_not_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters