-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
expose a v2 ruleset for BinaryToolBase #8859
Changes from all commits
608a7be
3fb6b63
84d7712
451b7af
ad3ae8d
b2f0e6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
from pants.backend.python.lint.bandit.rules import BanditTarget | ||
from pants.backend.python.lint.bandit.rules import rules as bandit_rules | ||
from pants.backend.python.rules import download_pex_bin, pex | ||
from pants.backend.python.subsystems import python_native_code, subprocess_environment | ||
from pants.backend.python.targets.python_library import PythonLibrary | ||
from pants.build_graph.address import Address | ||
from pants.build_graph.build_file_aliases import BuildFileAliases | ||
|
@@ -17,10 +19,16 @@ | |
from pants.rules.core.lint import LintResult | ||
from pants.source.wrapped_globs import EagerFilesetWithSpec | ||
from pants.testutil.option.util import create_options_bootstrapper | ||
from pants.testutil.subsystem.util import init_subsystems | ||
from pants.testutil.test_base import TestBase | ||
|
||
|
||
class BanditIntegrationTest(TestBase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
init_subsystems([download_pex_bin.DownloadedPexBin.Factory]) | ||
|
||
good_source = FileContent(path="test/good.py", content=b"hashlib.sha256()\n") | ||
bad_source = FileContent(path="test/bad.py", content=b"hashlib.md5()\n") | ||
# MD5 is a insecure hashing function | ||
|
@@ -31,7 +39,16 @@ def alias_groups(cls) -> BuildFileAliases: | |
|
||
@classmethod | ||
def rules(cls): | ||
return (*super().rules(), *bandit_rules(), RootRule(BanditTarget)) | ||
return ( | ||
*super().rules(), | ||
*bandit_rules(), | ||
download_pex_bin.download_pex_bin, | ||
*pex.rules(), | ||
*python_native_code.rules(), | ||
*subprocess_environment.rules(), | ||
RootRule(BanditTarget), | ||
RootRule(download_pex_bin.DownloadedPexBin.Factory), | ||
) | ||
Comment on lines
-34
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, this is a bit of a regression. The purpose of #9059 was to only need to have Can you please check these things:
If possible, it'd also be great to get the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't recall this issue?
This PR was from before then, so I suspect this change will work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, removing the same from the python awslambda test didn't work. I don't know if this was really "special-cased" as you describe -- I recall @gshuflin had this issue yesterday where we needed to inject There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We do not want to register subsystems as Note that these lint tests did not previously need to call Originally, we actually did have to do this, but thanks to #8943 we no longer need to because we pass --
We figured out the issue yesterday and no longer need to pass
That's one option, but even better would be being able to go back to the only boilerplate being the test having to register this: def rules():
return (*super().rules(), *bandit_rules(), RootRule(BanditTarget)) The first win would be to try this:
The next win would be
Per this, |
||
|
||
def run_bandit( | ||
self, | ||
|
@@ -60,7 +77,11 @@ def run_bandit( | |
) | ||
) | ||
return self.request_single_product( | ||
LintResult, Params(target, create_options_bootstrapper(args=args)), | ||
LintResult, Params( | ||
target, | ||
create_options_bootstrapper(args=args), | ||
download_pex_bin.DownloadedPexBin.Factory.global_instance(), | ||
), | ||
) | ||
|
||
def test_single_passing_source(self) -> None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
from pants.backend.python.lint.black.rules import BlackTarget | ||
from pants.backend.python.lint.black.rules import rules as black_rules | ||
from pants.backend.python.rules import download_pex_bin, pex | ||
from pants.backend.python.subsystems import python_native_code, subprocess_environment | ||
from pants.build_graph.address import Address | ||
from pants.engine.fs import Digest, FileContent, InputFilesContent, Snapshot | ||
from pants.engine.legacy.structs import TargetAdaptor | ||
|
@@ -16,11 +18,16 @@ | |
from pants.rules.core.lint import LintResult | ||
from pants.source.wrapped_globs import EagerFilesetWithSpec | ||
from pants.testutil.option.util import create_options_bootstrapper | ||
from pants.testutil.subsystem.util import init_subsystems | ||
from pants.testutil.test_base import TestBase | ||
|
||
|
||
class BlackIntegrationTest(TestBase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
init_subsystems([download_pex_bin.DownloadedPexBin.Factory]) | ||
|
||
good_source = FileContent(path="test/good.py", content=b'animal = "Koala"\n') | ||
bad_source = FileContent(path="test/bad.py", content=b'name= "Anakin"\n') | ||
fixed_bad_source = FileContent(path="test/bad.py", content=b'name = "Anakin"\n') | ||
|
@@ -30,7 +37,16 @@ class BlackIntegrationTest(TestBase): | |
|
||
@classmethod | ||
def rules(cls): | ||
return (*super().rules(), *black_rules(), RootRule(BlackTarget)) | ||
return ( | ||
*super().rules(), | ||
*black_rules(), | ||
download_pex_bin.download_pex_bin, | ||
*pex.rules(), | ||
*python_native_code.rules(), | ||
*subprocess_environment.rules(), | ||
RootRule(BlackTarget), | ||
RootRule(download_pex_bin.DownloadedPexBin.Factory), | ||
) | ||
Comment on lines
+40
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto on the bandit comments |
||
|
||
def run_black( | ||
self, | ||
|
@@ -56,8 +72,16 @@ def run_black( | |
lint_target = BlackTarget(target_adaptor) | ||
fmt_target = BlackTarget(target_adaptor, prior_formatter_result_digest=input_snapshot.directory_digest) | ||
options_bootstrapper = create_options_bootstrapper(args=args) | ||
lint_result = self.request_single_product(LintResult, Params(lint_target, options_bootstrapper)) | ||
fmt_result = self.request_single_product(FmtResult, Params(fmt_target, options_bootstrapper)) | ||
lint_result = self.request_single_product(LintResult, Params( | ||
lint_target, | ||
options_bootstrapper, | ||
download_pex_bin.DownloadedPexBin.Factory.global_instance(), | ||
)) | ||
fmt_result = self.request_single_product(FmtResult, Params( | ||
fmt_target, | ||
options_bootstrapper, | ||
download_pex_bin.DownloadedPexBin.Factory.global_instance(), | ||
)) | ||
return lint_result, fmt_result | ||
|
||
def get_digest(self, source_files: List[FileContent]) -> Digest: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
from pants.backend.python.lint.flake8.rules import Flake8Target | ||
from pants.backend.python.lint.flake8.rules import rules as flake8_rules | ||
from pants.backend.python.rules import download_pex_bin, pex | ||
from pants.backend.python.subsystems import python_native_code, subprocess_environment | ||
from pants.backend.python.targets.python_library import PythonLibrary | ||
from pants.build_graph.address import Address | ||
from pants.build_graph.build_file_aliases import BuildFileAliases | ||
|
@@ -18,10 +20,16 @@ | |
from pants.source.wrapped_globs import EagerFilesetWithSpec | ||
from pants.testutil.interpreter_selection_utils import skip_unless_python27_and_python3_present | ||
from pants.testutil.option.util import create_options_bootstrapper | ||
from pants.testutil.subsystem.util import init_subsystems | ||
from pants.testutil.test_base import TestBase | ||
|
||
|
||
class Flake8IntegrationTest(TestBase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
init_subsystems([download_pex_bin.DownloadedPexBin.Factory]) | ||
|
||
good_source = FileContent(path="test/good.py", content=b"print('Nothing suspicious here..')\n") | ||
bad_source = FileContent(path="test/bad.py", content=b"import typing\n") # unused import | ||
py3_only_source = FileContent(path="test/py3.py", content=b"version: str = 'Py3 > Py2'\n") | ||
|
@@ -32,7 +40,16 @@ def alias_groups(cls) -> BuildFileAliases: | |
|
||
@classmethod | ||
def rules(cls): | ||
return (*super().rules(), *flake8_rules(), RootRule(Flake8Target)) | ||
return ( | ||
*super().rules(), | ||
*flake8_rules(), | ||
download_pex_bin.download_pex_bin, | ||
*pex.rules(), | ||
*python_native_code.rules(), | ||
*subprocess_environment.rules(), | ||
RootRule(Flake8Target), | ||
RootRule(download_pex_bin.DownloadedPexBin.Factory), | ||
) | ||
Comment on lines
+43
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto on the bandit comments |
||
|
||
def run_flake8( | ||
self, | ||
|
@@ -61,7 +78,11 @@ def run_flake8( | |
) | ||
) | ||
return self.request_single_product( | ||
LintResult, Params(target, create_options_bootstrapper(args=args)), | ||
LintResult, Params( | ||
target, | ||
create_options_bootstrapper(args=args), | ||
download_pex_bin.DownloadedPexBin.Factory.global_instance(), | ||
), | ||
) | ||
|
||
def test_single_passing_source(self) -> None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
|
||
from pants.backend.python.lint.isort.rules import IsortTarget | ||
from pants.backend.python.lint.isort.rules import rules as isort_rules | ||
from pants.backend.python.rules import download_pex_bin, pex | ||
from pants.backend.python.subsystems import python_native_code, subprocess_environment | ||
from pants.build_graph.address import Address | ||
from pants.engine.fs import Digest, FileContent, InputFilesContent, Snapshot | ||
from pants.engine.legacy.structs import TargetAdaptor | ||
|
@@ -14,11 +16,16 @@ | |
from pants.rules.core.lint import LintResult | ||
from pants.source.wrapped_globs import EagerFilesetWithSpec | ||
from pants.testutil.option.util import create_options_bootstrapper | ||
from pants.testutil.subsystem.util import init_subsystems | ||
from pants.testutil.test_base import TestBase | ||
|
||
|
||
class IsortIntegrationTest(TestBase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
init_subsystems([download_pex_bin.DownloadedPexBin.Factory]) | ||
|
||
good_source = FileContent(path="test/good.py", content=b'from animals import cat, dog\n') | ||
bad_source = FileContent(path="test/bad.py", content=b'from colors import green, blue\n') | ||
fixed_bad_source = FileContent(path="test/bad.py", content=b'from colors import blue, green\n') | ||
|
@@ -36,7 +43,16 @@ class IsortIntegrationTest(TestBase): | |
|
||
@classmethod | ||
def rules(cls): | ||
return (*super().rules(), *isort_rules(), RootRule(IsortTarget)) | ||
return ( | ||
*super().rules(), | ||
*isort_rules(), | ||
download_pex_bin.download_pex_bin, | ||
*pex.rules(), | ||
*python_native_code.rules(), | ||
*subprocess_environment.rules(), | ||
RootRule(IsortTarget), | ||
RootRule(download_pex_bin.DownloadedPexBin.Factory), | ||
) | ||
Comment on lines
+46
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto on the bandit comments |
||
|
||
def run_isort( | ||
self, | ||
|
@@ -64,8 +80,16 @@ def run_isort( | |
target_adaptor, prior_formatter_result_digest=input_snapshot.directory_digest, | ||
) | ||
options_bootstrapper = create_options_bootstrapper(args=args) | ||
lint_result = self.request_single_product(LintResult, Params(lint_target, options_bootstrapper)) | ||
fmt_result = self.request_single_product(FmtResult, Params(fmt_target, options_bootstrapper)) | ||
lint_result = self.request_single_product(LintResult, Params( | ||
lint_target, | ||
options_bootstrapper, | ||
download_pex_bin.DownloadedPexBin.Factory.global_instance(), | ||
)) | ||
fmt_result = self.request_single_product(FmtResult, Params( | ||
fmt_target, | ||
options_bootstrapper, | ||
download_pex_bin.DownloadedPexBin.Factory.global_instance(), | ||
)) | ||
return lint_result, fmt_result | ||
|
||
def get_digest(self, source_files: List[FileContent]) -> Digest: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
_ConcretePythonFormatTarget, | ||
format_python_target, | ||
) | ||
from pants.backend.python.rules import download_pex_bin, pex | ||
from pants.backend.python.subsystems import python_native_code, subprocess_environment | ||
from pants.build_graph.address import Address | ||
from pants.engine.fs import Digest, FileContent, InputFilesContent, Snapshot | ||
from pants.engine.legacy.structs import TargetAdaptor | ||
|
@@ -19,21 +21,31 @@ | |
from pants.rules.core.fmt import AggregatedFmtResults | ||
from pants.source.wrapped_globs import EagerFilesetWithSpec | ||
from pants.testutil.option.util import create_options_bootstrapper | ||
from pants.testutil.subsystem.util import init_subsystems | ||
from pants.testutil.test_base import TestBase | ||
|
||
|
||
class PythonFormatTargetIntegrationTest(TestBase): | ||
|
||
def setUp(self): | ||
super().setUp() | ||
init_subsystems([download_pex_bin.DownloadedPexBin.Factory]) | ||
|
||
@classmethod | ||
def rules(cls): | ||
return ( | ||
*super().rules(), | ||
format_python_target, | ||
*black_rules(), | ||
*isort_rules(), | ||
download_pex_bin.download_pex_bin, | ||
*pex.rules(), | ||
*python_native_code.rules(), | ||
*subprocess_environment.rules(), | ||
Comment on lines
+41
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto on the bandit comments |
||
RootRule(_ConcretePythonFormatTarget), | ||
RootRule(BlackTarget), | ||
RootRule(IsortTarget), | ||
RootRule(download_pex_bin.DownloadedPexBin.Factory), | ||
) | ||
|
||
def run_black_and_isort( | ||
|
@@ -55,7 +67,8 @@ def run_black_and_isort( | |
args=[ | ||
"--backend-packages2=['pants.backend.python.lint.black', 'pants.backend.python.lint.isort']" | ||
], | ||
) | ||
), | ||
download_pex_bin.DownloadedPexBin.Factory.global_instance(), | ||
) | ||
) | ||
return results | ||
|
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 below commit in the
bandit
file about the possibility of trying to fix this.)