Skip to content

Commit

Permalink
Add description_of_origin for several places finding Addresses (#15797
Browse files Browse the repository at this point in the history
)

Progress towards #14468.

We only have Dockerfile address parsing left, which I'll do in a follow up.

[ci skip-rust]
  • Loading branch information
Eric-Arellano committed Jun 10, 2022
1 parent 1e06f67 commit 960f12f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
19 changes: 14 additions & 5 deletions src/python/pants/backend/python/target_types_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,26 @@ async def resolve_python_distribution_entry_points(
return ResolvedPythonDistributionEntryPoints()
address = request.entry_points_field.address
all_entry_points = cast(_EntryPointsDictType, request.entry_points_field.value)
description_of_origin = (
f"the `{request.entry_points_field.alias}` field from the target {address}"
)

elif request.provides_field:
address = request.provides_field.address
provides_field_value = cast(
_EntryPointsDictType, request.provides_field.value.kwargs.get("entry_points") or {}
)

if provides_field_value:
all_entry_points = provides_field_value
else:
if not provides_field_value:
return ResolvedPythonDistributionEntryPoints()

all_entry_points = provides_field_value
description_of_origin = softwrap(
f"""
the `entry_points` argument from the `{request.provides_field.alias}` field from
the target {address}
"""
)

else:
return ResolvedPythonDistributionEntryPoints()

Expand All @@ -326,7 +335,7 @@ async def resolve_python_distribution_entry_points(
UnparsedAddressInputs(
target_refs,
owning_address=address,
description_of_origin="TODO(#14468)",
description_of_origin=description_of_origin,
),
)
address_by_ref = dict(zip(target_refs, target_addresses))
Expand Down
11 changes: 1 addition & 10 deletions src/python/pants/bsp/spec/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from enum import IntEnum
from typing import Any, ClassVar

from pants.build_graph.address import Address, AddressInput
from pants.build_graph.address import Address

# -----------------------------------------------------------------------------------------------
# Basic JSON Structures
Expand Down Expand Up @@ -39,15 +39,6 @@ def to_json_dict(self):
def from_address(cls, addr: Address) -> BuildTargetIdentifier:
return cls(uri=f"pants:{str(addr)}")

@property
def address_input(self) -> AddressInput:
if not self.uri.startswith("pants:"):
raise ValueError(
f"Unknown URI scheme for BSP BuildTargetIdentifier. Expected scheme `pants`, but URI was: {self.uri}"
)
raw_addr = self.uri[len("pants:") :]
return AddressInput.parse(raw_addr, description_of_origin="TODO(#14468)")


@dataclass(frozen=True)
class BuildTargetCapabilities:
Expand Down
31 changes: 28 additions & 3 deletions src/python/pants/engine/internals/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,24 @@
@rule
async def resolve_unexpanded_targets(addresses: Addresses) -> UnexpandedTargets:
wrapped_targets = await MultiGet(
Get(WrappedTarget, WrappedTargetRequest(a, description_of_origin="TODO(#14468)"))
Get(
WrappedTarget,
WrappedTargetRequest(
a,
# Idiomatic rules should not be manually constructing `Addresses`. Instead, they
# should use `UnparsedAddressInputs` or `Specs` rules.
#
# It is technically more correct for us to require callers of
# `Addresses -> UnexpandedTargets` to specify a `description_of_origin`. But in
# practice, this dramatically increases boilerplate, and it should never be
# necessary.
#
# Note that this contrasts with an individual `Address`, which often is unverified
# because it can come from the rule `AddressInput -> Address`, which only verifies
# that it has legal syntax and does not check the address exists.
description_of_origin="<infallible>",
),
)
for a in addresses
)
return UnexpandedTargets(wrapped_target.target for wrapped_target in wrapped_targets)
Expand Down Expand Up @@ -362,7 +379,10 @@ async def resolve_targets(
_TargetParametrizations,
_TargetParametrizationsRequest(
tgt.address.maybe_convert_to_target_generator(),
description_of_origin="TODO(#14468)",
# Idiomatic rules should not be manually creating `UnexpandedTargets`, so
# we can be confident that the targets actually exist and the addresses
# are already legitimate.
description_of_origin="<infallible>",
),
)
)
Expand Down Expand Up @@ -922,7 +942,11 @@ def compatible_with_sources_field(valid_type: type[SourcesField]) -> bool:
return HydratedSources(snapshot, sources_field.filespec, sources_type=sources_type)
wrapped_protocol_target = await Get(
WrappedTarget,
WrappedTargetRequest(sources_field.address, description_of_origin="<infallible>"),
WrappedTargetRequest(
sources_field.address,
# It's only possible to hydrate sources on a target that we already know exists.
description_of_origin="<infallible>",
),
)
generated_sources = await Get(
GeneratedSources,
Expand Down Expand Up @@ -1049,6 +1073,7 @@ async def resolve_dependencies(
wrapped_tgt, explicitly_provided = await MultiGet(
Get(
WrappedTarget,
# It's only possible to find dependencies for a target that we already know exists.
WrappedTargetRequest(request.field.address, description_of_origin="<infallible>"),
),
Get(ExplicitlyProvidedDependencies, DependenciesRequest, request),
Expand Down
4 changes: 3 additions & 1 deletion src/python/pants/jvm/resolve/coursier_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,9 @@ async def coursier_fetch_one_coord(
targets = await Get(
Targets,
UnparsedAddressInputs(
[request.pants_address], owning_address=None, description_of_origin="TODO(#14468)"
[request.pants_address],
owning_address=None,
description_of_origin="<infallible - coursier fetch>",
),
)
req = ArtifactRequirement(request.coord, jar=targets[0][JvmArtifactJarSourceField])
Expand Down

0 comments on commit 960f12f

Please sign in to comment.