diff --git a/pants.ini b/pants.ini index 0550b8e9cb5..2fe576eda92 100644 --- a/pants.ini +++ b/pants.ini @@ -45,7 +45,6 @@ pythonpath: [ ] backend_packages: +[ - "pants.backend.python.lint.isort", "pants.backend.docgen", "pants.contrib.avro", "pants.contrib.awslambda.python", @@ -71,6 +70,7 @@ backend_packages: +[ backend_packages2: [ "pants.backend.project_info", "pants.backend.python", + "pants.backend.python.lint.isort", "pants.backend.native", "internal_backend.rules_for_testing", ] diff --git a/src/python/pants/backend/python/lint/black/rules.py b/src/python/pants/backend/python/lint/black/rules.py index 6fbd8776f1e..f61e057f533 100644 --- a/src/python/pants/backend/python/lint/black/rules.py +++ b/src/python/pants/backend/python/lint/black/rules.py @@ -33,7 +33,7 @@ @dataclass(frozen=True) class BlackTarget: target: TargetAdaptor - prior_formatter_result_digest: Digest + prior_formatter_result_digest: Optional[Digest] = None # unused by `lint` @dataclass(frozen=True) @@ -99,7 +99,7 @@ async def create_black_request( subprocess_encoding_environment: SubprocessEncodingEnvironment, ) -> ExecuteProcessRequest: target = wrapped_target.target - sources_digest = wrapped_target.prior_formatter_result_digest + sources_digest = wrapped_target.prior_formatter_result_digest or target.sources.snapshot.directory_digest merged_input_files = await Get[Digest]( DirectoriesToMerge( directories=( diff --git a/src/python/pants/backend/python/lint/black/rules_integration_test.py b/src/python/pants/backend/python/lint/black/rules_integration_test.py index ae769d1f5d1..62ba203e41c 100644 --- a/src/python/pants/backend/python/lint/black/rules_integration_test.py +++ b/src/python/pants/backend/python/lint/black/rules_integration_test.py @@ -70,33 +70,32 @@ def run_black( if config is not None: self.create_file(relpath="pyproject.toml", contents=config) input_snapshot = self.request_single_product(Snapshot, InputFilesContent(source_files)) - target = BlackTarget( - TargetAdaptor( - sources=EagerFilesetWithSpec('test', {'globs': []}, snapshot=input_snapshot), - address=Address.parse("test:target"), - ), - prior_formatter_result_digest=input_snapshot.directory_digest, + target_adaptor = TargetAdaptor( + sources=EagerFilesetWithSpec('test', {'globs': []}, snapshot=input_snapshot), + address=Address.parse("test:target"), ) + lint_target = BlackTarget(target_adaptor) + fmt_target = BlackTarget(target_adaptor, prior_formatter_result_digest=input_snapshot.directory_digest) black_subsystem = global_subsystem_instance( Black, options={Black.options_scope: { "config": "pyproject.toml" if config else None, "args": passthrough_args or [], }} ) + python_subsystems = [ + PythonNativeCode.global_instance(), + PythonSetup.global_instance(), + SubprocessEnvironment.global_instance(), + ] black_setup = self.request_single_product( - BlackSetup, - Params( - black_subsystem, - PythonNativeCode.global_instance(), - PythonSetup.global_instance(), - SubprocessEnvironment.global_instance(), - ) + BlackSetup, Params(black_subsystem, *python_subsystems) ) - fmt_and_lint_params = Params( - target, black_setup, PythonSetup.global_instance(), SubprocessEnvironment.global_instance() + lint_result = self.request_single_product( + LintResult, Params(lint_target, black_setup, *python_subsystems) + ) + fmt_result = self.request_single_product( + FmtResult, Params(fmt_target, black_setup, *python_subsystems) ) - lint_result = self.request_single_product(LintResult, fmt_and_lint_params) - fmt_result = self.request_single_product(FmtResult, fmt_and_lint_params) return lint_result, fmt_result def get_digest(self, source_files: List[FileContent]) -> Digest: diff --git a/src/python/pants/backend/python/lint/isort/rules.py b/src/python/pants/backend/python/lint/isort/rules.py index 3b52e6af5cc..3695d57f8a8 100644 --- a/src/python/pants/backend/python/lint/isort/rules.py +++ b/src/python/pants/backend/python/lint/isort/rules.py @@ -31,7 +31,7 @@ @dataclass(frozen=True) class IsortTarget: target: TargetAdaptor - prior_formatter_result_digest: Digest + prior_formatter_result_digest: Optional[Digest] = None # unused by `lint` @dataclass(frozen=True) @@ -91,7 +91,7 @@ async def create_isort_request( subprocess_encoding_environment: SubprocessEncodingEnvironment, ) -> ExecuteProcessRequest: target = wrapped_target.target - sources_digest = wrapped_target.prior_formatter_result_digest + sources_digest = wrapped_target.prior_formatter_result_digest or target.sources.snapshot.directory_digest merged_input_files = await Get[Digest]( DirectoriesToMerge( directories=( diff --git a/src/python/pants/backend/python/lint/isort/rules_integration_test.py b/src/python/pants/backend/python/lint/isort/rules_integration_test.py index aeb46775935..84458ada2b1 100644 --- a/src/python/pants/backend/python/lint/isort/rules_integration_test.py +++ b/src/python/pants/backend/python/lint/isort/rules_integration_test.py @@ -78,33 +78,32 @@ def run_isort( if config is not None: self.create_file(relpath=".isort.cfg", contents=config) input_snapshot = self.request_single_product(Snapshot, InputFilesContent(source_files)) - target = IsortTarget( - TargetAdaptor( - sources=EagerFilesetWithSpec('test', {'globs': []}, snapshot=input_snapshot), - address=Address.parse("test:target"), - ), - prior_formatter_result_digest=input_snapshot.directory_digest, + target_adaptor = TargetAdaptor( + sources=EagerFilesetWithSpec('test', {'globs': []}, snapshot=input_snapshot), + address=Address.parse("test:target"), ) + lint_target = IsortTarget(target_adaptor) + fmt_target = IsortTarget(target_adaptor, prior_formatter_result_digest=input_snapshot.directory_digest) isort_subsystem = global_subsystem_instance( Isort, options={Isort.options_scope: { "config": [".isort.cfg"] if config else None, "args": passthrough_args or [], }} ) + python_subsystems = [ + PythonNativeCode.global_instance(), + PythonSetup.global_instance(), + SubprocessEnvironment.global_instance(), + ] isort_setup = self.request_single_product( - IsortSetup, - Params( - isort_subsystem, - PythonNativeCode.global_instance(), - PythonSetup.global_instance(), - SubprocessEnvironment.global_instance(), - ) + IsortSetup, Params(isort_subsystem, *python_subsystems) ) - fmt_and_lint_params = Params( - target, isort_setup, PythonSetup.global_instance(), SubprocessEnvironment.global_instance() + lint_result = self.request_single_product( + LintResult, Params(lint_target, isort_setup, *python_subsystems) + ) + fmt_result = self.request_single_product( + FmtResult, Params(fmt_target, isort_setup, *python_subsystems) ) - lint_result = self.request_single_product(LintResult, fmt_and_lint_params) - fmt_result = self.request_single_product(FmtResult, fmt_and_lint_params) return lint_result, fmt_result def get_digest(self, source_files: List[FileContent]) -> Digest: