diff --git a/src/python/pants/backend/python/dependency_inference/module_mapper.py b/src/python/pants/backend/python/dependency_inference/module_mapper.py index af90d7d46518..6d6fafadd827 100644 --- a/src/python/pants/backend/python/dependency_inference/module_mapper.py +++ b/src/python/pants/backend/python/dependency_inference/module_mapper.py @@ -163,3 +163,11 @@ async def map_module_to_address( if first_party_address: return PythonModuleOwner(first_party_address) return PythonModuleOwner(address=None) + + +def rules(): + return [ + map_first_party_modules_to_addresses, + map_third_party_modules_to_addresses, + map_module_to_address, + ] diff --git a/src/python/pants/backend/python/dependency_inference/rules.py b/src/python/pants/backend/python/dependency_inference/rules.py index 803ab3b7361b..74c164fa3eb8 100644 --- a/src/python/pants/backend/python/dependency_inference/rules.py +++ b/src/python/pants/backend/python/dependency_inference/rules.py @@ -3,14 +3,9 @@ from pathlib import PurePath +from pants.backend.python.dependency_inference import module_mapper from pants.backend.python.dependency_inference.import_parser import find_python_imports -from pants.backend.python.dependency_inference.module_mapper import ( - PythonModule, - PythonModuleOwner, - map_first_party_modules_to_addresses, - map_module_to_address, - map_third_party_modules_to_addresses, -) +from pants.backend.python.dependency_inference.module_mapper import PythonModule, PythonModuleOwner from pants.backend.python.dependency_inference.python_stdlib.combined import combined_stdlib from pants.backend.python.rules import inject_ancestor_files from pants.backend.python.rules.inject_ancestor_files import AncestorFiles, AncestorFilesRequest @@ -20,7 +15,7 @@ StripSourcesFieldRequest, ) from pants.engine.fs import Digest, DigestContents -from pants.engine.internals.graph import Owners, OwnersNotFoundBehavior, OwnersRequest +from pants.engine.internals.graph import Owners, OwnersRequest from pants.engine.rules import SubsystemRule, rule from pants.engine.selectors import Get, MultiGet from pants.engine.target import ( @@ -30,6 +25,7 @@ InferredDependencies, ) from pants.engine.unions import UnionRule +from pants.option.global_options import OwnersNotFoundBehavior from pants.subsystem.subsystem import Subsystem @@ -163,6 +159,7 @@ async def infer_python_conftest_dependencies( def rules(): return [ *inject_ancestor_files.rules(), + *module_mapper.rules(), infer_python_dependencies, infer_python_init_dependencies, infer_python_conftest_dependencies, @@ -170,7 +167,4 @@ def rules(): UnionRule(InferDependenciesRequest, InferInitDependencies), UnionRule(InferDependenciesRequest, InferConftestDependencies), SubsystemRule(PythonInference), - map_first_party_modules_to_addresses, - map_third_party_modules_to_addresses, - map_module_to_address, ] diff --git a/src/python/pants/backend/python/rules/coverage_integration_test.py b/src/python/pants/backend/python/rules/coverage_integration_test.py index 3dc39aaea5a6..cea4a56ded94 100644 --- a/src/python/pants/backend/python/rules/coverage_integration_test.py +++ b/src/python/pants/backend/python/rules/coverage_integration_test.py @@ -120,7 +120,7 @@ def test_arithmetic(): (no_src_folder / "test_no_src.py").write_text("def test_true():\n\tassert True is True\n") (no_src_folder / "BUILD").write_text( dedent( - f"""\ + """\ python_tests() python_library(name='lib') diff --git a/src/python/pants/backend/python/rules/python_sources.py b/src/python/pants/backend/python/rules/python_sources.py index ed011a89eac0..076c058751d3 100644 --- a/src/python/pants/backend/python/rules/python_sources.py +++ b/src/python/pants/backend/python/rules/python_sources.py @@ -4,7 +4,6 @@ from dataclasses import dataclass from typing import Iterable, List, Tuple, Type -from pants.backend.python.rules.inject_ancestor_files import rules as inject_ancestor_rules from pants.backend.python.target_types import PythonSources from pants.core.target_types import FilesSources, ResourcesSources from pants.core.util_rules import determine_source_files diff --git a/src/python/pants/backend/python/typecheck/mypy/rules_integration_test.py b/src/python/pants/backend/python/typecheck/mypy/rules_integration_test.py index 790704505e40..9a72ca5727ea 100644 --- a/src/python/pants/backend/python/typecheck/mypy/rules_integration_test.py +++ b/src/python/pants/backend/python/typecheck/mypy/rules_integration_test.py @@ -113,6 +113,7 @@ def run_mypy( "--backend-packages=pants.backend.python", "--backend-packages=pants.backend.python.typecheck.mypy", "--source-root-patterns=['src/python', 'tests/python']", + "--python-infer-imports", ] if config: self.create_file(relpath="mypy.ini", contents=config) @@ -186,7 +187,6 @@ def test_skip(self) -> None: assert not result def test_transitive_dependencies(self) -> None: - self.create_file(f"{self.package}/util/__init__.py") self.create_file( f"{self.package}/util/lib.py", diff --git a/src/python/pants/engine/internals/graph.py b/src/python/pants/engine/internals/graph.py index e4020a33df5c..aba187bba27e 100644 --- a/src/python/pants/engine/internals/graph.py +++ b/src/python/pants/engine/internals/graph.py @@ -345,7 +345,7 @@ def _log_or_raise_unmatched_owners( ) -> None: msgs = [] if ignore_option: - option_msg = "\nIf you would like to ignore un-owned files, please pass `ignore_option`." + option_msg = f"\nIf you would like to ignore un-owned files, please pass `{ignore_option}`." else: option_msg = "" for file_path in file_paths: @@ -763,7 +763,7 @@ async def resolve_dependencies( ) inference_request_types = union_membership.get(InferDependenciesRequest) - inferred = [InferredDependencies()] + inferred: Tuple[InferredDependencies, ...] = (InferredDependencies(),) if inference_request_types: # Dependency inference is solely determined by the `Sources` field for a Target, so we # re-resolve the original target to inspect its `Sources` field, if any.