Let's say I have a list of possible resource paths...
# plugins
b
Let's say I have a list of possible resource paths (relative to some file). How would one request the address for the valid ones (tossing the invalid ones?) E.g. If I have
data/foo.json
I know is relative to some dir
./bar
(e.g.
./bar/data.foo.json
), if it's a valid resource I want it's address, otherwise no-op)
Is this what I'm looking for?
Copy code
Get(Address, AddressInput.parse(possible_resource, relative_to=the_path))
OK that works for the valid case 🤔
Wondering if I should make another flavor of this that returns an Optional and doesn't raise
ResolveError
👍 1
f
Other options: 1. Compute the path you want and then use
Get(Digest, PathGlobs(…))
to attempt to make a
Digest
out of files from the repo. 2. Require that the resource file be the subject of a `resource`target and then use `DependenciesRequest`to get the deps and then just find the resource target in the returned
Dependencies
and load it via its
Sources
field (i.e., with
HydratesSourcesRequest
or equivalent).
c
Wondering if I should make another flavor of this that returns an Optional and doesn’t raise 
ResolveError
I think this would be useful to have. For the Docker backend, when using heuristics to determine possible dependencies, it would be good to have a rule to apply that gives you back any valid addresses, and discards the invalid ones without err.
b
@curved-television-6568 I guess I'd still need to verify the addresses are resources...
@fast-nail-55400 I'm actually writing a rule to satisfy a dependency request, so that probably is a no-go
f
Then you should just be able to convert to
Targets
and scan for whatever targets has the
resource
-specific sources field.
And if you need to load the resource, just use HydrateSourcesRequest with
for_sources_type
and
enable_codegen
set appropriately.
If you grep
for_sources_type
you should see some examples in the code that deal with
resource
targets.
(
enable_codegen=True
will allow you to work with anything that can codegen to a resource. This is how
relocated_files
works.)
And then no need to even scan targets then.
b
I might need some hand-holding on this one 😅 . But AFAICT I need to take my string, and reference it against the global set of all resource targets? If so, I think I'm on the right track...
OMG it works 😂
🙌 1