From 3687fd88fb038dbce5155ee50e433f3c6009af47 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Thu, 5 May 2022 09:37:33 -0500 Subject: [PATCH] Error on unowned internal Python dependencies (#15331) The dogfooding is good, especially as we consider changing the default for Pants to be warn or error (https://github.com/pantsbuild/pants/issues/15326). --- pants.toml | 1 + .../backend/docker/subsystems/dockerfile_wrapper_script.py | 2 +- src/python/pants/backend/terraform/hcl2_parser.py | 5 +++-- src/python/pants/goal/stats_aggregator.py | 2 +- testprojects/src/python/native/name.py | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pants.toml b/pants.toml index d48971ef466..8c6b39d9346 100644 --- a/pants.toml +++ b/pants.toml @@ -131,6 +131,7 @@ lockfile_generator = "pex" [python-infer] assets = true +unowned_dependency_behavior = "error" [docformatter] args = ["--wrap-summaries=100", "--wrap-descriptions=100"] diff --git a/src/python/pants/backend/docker/subsystems/dockerfile_wrapper_script.py b/src/python/pants/backend/docker/subsystems/dockerfile_wrapper_script.py index 228779ee073..309bf5b1876 100644 --- a/src/python/pants/backend/docker/subsystems/dockerfile_wrapper_script.py +++ b/src/python/pants/backend/docker/subsystems/dockerfile_wrapper_script.py @@ -70,7 +70,7 @@ def valid_address(value: str) -> bool: def main(cmd: str, args: list[str]) -> None: # import here to allow the rest of the file to be tested without a dependency on dockerfile - from dockerfile import Command, parse_file, parse_string + from dockerfile import Command, parse_file, parse_string # pants: no-infer-dep @dataclass(frozen=True) class ParsedDockerfile: diff --git a/src/python/pants/backend/terraform/hcl2_parser.py b/src/python/pants/backend/terraform/hcl2_parser.py index 98d986c4523..b4ead0a042c 100644 --- a/src/python/pants/backend/terraform/hcl2_parser.py +++ b/src/python/pants/backend/terraform/hcl2_parser.py @@ -28,8 +28,9 @@ def resolve_pure_path(base: PurePath, relative_path: PurePath) -> PurePath: def extract_module_source_paths(path: PurePath, raw_content: bytes) -> Set[str]: - # Import here so we can still test this file with pytest (since `hcl2` is not present in normal Pants venv.) - import hcl2 # type: ignore[import] + # Import here so we can still test this file with pytest (since `hcl2` is not present in + # normal Pants venv.) + import hcl2 # type: ignore[import] # pants: no-infer-dep content = raw_content.decode("utf-8") parsed_content = hcl2.loads(content) diff --git a/src/python/pants/goal/stats_aggregator.py b/src/python/pants/goal/stats_aggregator.py index efd9aa9eb90..2574bfd8346 100644 --- a/src/python/pants/goal/stats_aggregator.py +++ b/src/python/pants/goal/stats_aggregator.py @@ -120,7 +120,7 @@ def __call__( if not (self.log and self.has_histogram_module): return - from hdrh.histogram import HdrHistogram + from hdrh.histogram import HdrHistogram # pants: no-infer-dep histograms = context.get_observation_histograms()["histograms"] if not histograms: diff --git a/testprojects/src/python/native/name.py b/testprojects/src/python/native/name.py index e8c72664a42..d7ce4c166c1 100644 --- a/testprojects/src/python/native/name.py +++ b/testprojects/src/python/native/name.py @@ -1,7 +1,7 @@ # Copyright 2021 Pants project contributors (see CONTRIBUTORS.md). # Licensed under the Apache License, Version 2.0 (see LICENSE). -from native import impl # type: ignore[attr-defined] +from native import impl # type: ignore[attr-defined] # pants: no-infer-dep def get_name():