From 19fe4e3cec21067791dea8f1351c033c7132f579 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Wed, 15 Jun 2022 13:55:26 -0700 Subject: [PATCH] Add `description_of_origin` for Docker address parsing (#15814) Last part of https://github.com/pantsbuild/pants/issues/14468. [ci skip-rust] [ci skip-build-wheels] --- .../backend/docker/util_rules/dependencies.py | 8 +++++++- .../docker/util_rules/docker_build_context.py | 14 +++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/python/pants/backend/docker/util_rules/dependencies.py b/src/python/pants/backend/docker/util_rules/dependencies.py index ebb260e178b..7cee4d38b53 100644 --- a/src/python/pants/backend/docker/util_rules/dependencies.py +++ b/src/python/pants/backend/docker/util_rules/dependencies.py @@ -12,6 +12,7 @@ from pants.engine.rules import Get, collect_rules, rule from pants.engine.target import InjectDependenciesRequest, InjectedDependencies from pants.engine.unions import UnionRule +from pants.util.strutil import softwrap class InjectDockerDependencies(InjectDependenciesRequest): @@ -33,7 +34,12 @@ async def inject_docker_dependencies( UnparsedAddressInputs( (v for v in dockerfile_info.from_image_build_args.to_dict().values() if v), owning_address=dockerfile_info.address, - description_of_origin="TODO(#14468)", + description_of_origin=softwrap( + f""" + the FROM arguments from the file {dockerfile_info.source} + from the target {dockerfile_info.address} + """ + ), ), ) ) diff --git a/src/python/pants/backend/docker/util_rules/docker_build_context.py b/src/python/pants/backend/docker/util_rules/docker_build_context.py index ef40712f206..f87d0b0fe92 100644 --- a/src/python/pants/backend/docker/util_rules/docker_build_context.py +++ b/src/python/pants/backend/docker/util_rules/docker_build_context.py @@ -46,6 +46,7 @@ TransitiveTargetsRequest, ) from pants.engine.unions import UnionRule +from pants.util.strutil import softwrap logger = logging.getLogger(__name__) @@ -237,8 +238,10 @@ async def create_docker_build_context( Get(BuiltPackage, PackageFieldSet, field_set) for field_set in embedded_pkgs_per_target.field_sets # Exclude docker images, unless build_upstream_images is true. - if request.build_upstream_images - or not isinstance(getattr(field_set, "source", None), DockerImageSourceField) + if ( + request.build_upstream_images + or not isinstance(getattr(field_set, "source", None), DockerImageSourceField) + ) ) if request.build_upstream_images: @@ -283,7 +286,12 @@ async def create_docker_build_context( UnparsedAddressInputs( dockerfile_build_args.values(), owning_address=dockerfile_info.address, - description_of_origin="TODO(#14468)", + description_of_origin=softwrap( + f""" + the FROM arguments from the file {dockerfile_info.source} + from the target {dockerfile_info.address} + """ + ), ), ) # Map those addresses to the corresponding built image ref (tag).