Is there a function somewhere to resolve a string ...
# general
r
Is there a function somewhere to resolve a string to an
Address
relative to another address? E.g. if I have address
path/to/my/address:target_a
and string
:target_b
how can I generate the address
path/to/my/address:target_b
?
Also important - is there a way to do this without using an
await Get
?
c
r
I was actually looking at that, gonna try this
Copy code
def _resolver(self, spec: str) -> Address:
        address_input = AddressInput.parse(
            spec=spec,
            description_of_origin="",
            relative_to=self._root_address
        )
        return Address(
            address_input.path_component,
            target_name=address_input.target_component,
            generated_name=address_input.generated_component,
            parameters=address_input.parameters
        )
c
is
self._root_address
a path?
otherwise you may want
self._root_address.spec_path
🙏 1
r
good catch, yeah it's an address
c
the
AddressInput
has
file_to_address
and
dir_to_address
.. sure they don’t do what you want instead of creating the
Address
manually?
r
Does
file_to_address
work with helm deployments? Because I know these addresses are going to either refer to a helm deployment, docker image, or another custom target type that doesn't have a sources component.
Or is the file in question the
BUILD
file?
c
it’s about what the address points at, a file concept or a directory.. if in doubt, I think it’s safe to go with file.
r
I'll give that a try then!
c
try it and compare the result with what you expect to get
coke
looking at the rust implementation, the dir versions seems actually pretty close to what you did already.. 😉 https://github.com/pantsbuild/pants/blob/eecd07908868af3e3e0d97a91852de2785b7b16c/src/rust/engine/src/externs/address.rs#L354