ripe-gigabyte-88964
10/24/2023, 3:17 PMAddress
objects are equivalent if one is relative and one is absolute? I tried comparing their address.spec
, which documentation claims will prepend //
to any build root level targets, but I am not seeing that behavior in actuality, the relative specs are still missing the //
.curved-television-6568
10/24/2023, 3:33 PM❯ pants list :
//:all-__init__.py-files
//:buildgrid_remote
//:checks-empty-init-files
//:docker_env
//:files
//:scripts
//:test_utils
//BUILD_ROOT:files
//cargo:scripts
//conftest.py:test_utils
//pants:scripts
//pants.toml:files
on current main
in the pants repo.ripe-gigabyte-88964
10/24/2023, 3:33 PMcurved-television-6568
10/24/2023, 3:34 PMpath_safe_spec
?ripe-gigabyte-88964
10/24/2023, 3:35 PMcurved-television-6568
10/24/2023, 3:35 PMcurved-television-6568
10/24/2023, 3:36 PMripe-gigabyte-88964
10/24/2023, 3:36 PMAddressInput.dir_to_address
as opposed to <http://AddressInput.it|AddressInput.file_to_address
it> just uses all relative paths instead of prepending the //
in the spec pathcurved-television-6568
10/24/2023, 3:36 PMripe-gigabyte-88964
10/24/2023, 3:40 PMaddress_set = {tgt.address.spec for tgt in docker_targets}
logger.debug(f"All docker image addresses: {address_set}")
target_pattern = re.compile(r"[\w/\-]*:([\w/\-]+)")
def recursive_search(contents: Any, key: Tuple[str, ...] = ()) -> Iterable[Tuple[Address, Tuple[str, ...]]]:
if isinstance(contents, str):
if target_pattern.fullmatch(contents):
logger.debug(f"Found potential target {contents}")
resolved_address = resolve_str_to_address(
contents,
description_of_origin="Deployment dependency inference",
relative_to=request.root_address,
)
logger.debug(f"Resolved potential target to address {resolved_address}")
if resolved_address.spec in address_set:
logger.debug(f"Address {resolved_address} found in address set")
yield resolved_address, key
elif isinstance(contents, collections.abc.Mapping):
for k, value in contents.items():
yield from recursive_search(value, (*key, k))
elif isinstance(contents, collections.abc.Sequence):
for i, entry in enumerate(contents):
yield from recursive_search(entry, (*key, str(i)))
ripe-gigabyte-88964
10/24/2023, 3:40 PMresolve_str_to_address
to the following this worked:
def resolve_str_to_address(spec: str, *, description_of_origin: str, relative_to: Address) -> Address:
return AddressInput.parse(
spec=spec, description_of_origin=description_of_origin, relative_to=relative_to.spec_path
).dir_to_address()
curved-television-6568
10/24/2023, 3:40 PMcurved-television-6568
10/24/2023, 3:41 PMfoo/bar:baz
is the same as //foo/bar:baz
the only relative one is :name
i.e. with no path at all.ripe-gigabyte-88964
10/24/2023, 3:42 PMfoo/bar:baz
in it //foo/bar:baz in my_address_set
evaluates to false though.curved-television-6568
10/24/2023, 3:44 PM//
will be removed from the spec, I think.. it’s only preserved for root level addresses.curved-television-6568
10/24/2023, 3:44 PMcurved-television-6568
10/24/2023, 3:47 PM//
in your code, unless it’s a root level address 🙂ripe-gigabyte-88964
10/24/2023, 3:47 PMAllDockerImageTargets
, the ones at the root level, their specs don't seem to get //
curved-television-6568
10/24/2023, 3:48 PMspec_path
?ripe-gigabyte-88964
10/24/2023, 3:49 PMcurved-television-6568
10/24/2023, 3:49 PMcurved-television-6568
10/24/2023, 3:50 PMripe-gigabyte-88964
10/24/2023, 3:51 PMdir_to_address
seems to work perfectly for my use case, since what I want is the actual directory of the build file.curved-television-6568
10/24/2023, 3:53 PMaddress.spec_path
is perhaps useful, depending on what you do?