I’m looking for a way to translate a unparsed targ...
# development
c
I’m looking for a way to translate a unparsed target address into a target. Looking at https://github.com/pantsbuild/pants/blob/main/src/python/pants/engine/addresses.py#L41 seems it should be straight forward, but it complains with:
Copy code
Exception: Could not find a rule to satisfy Get(Targets, UnparsedAddressInputs, UnparsedAddressInputs(values=('//src/python/foo/qux:bin',), relative_to='src/python/foo')).
What could I be missing?
Ah, realized this is from a test, so there could be a rule that’s not included in the runner… will look into that
👍 1
OK, I got a bit further, but still stuck.. This works:
Copy code
res = chroot_rule_runner.request(Targets, [UnparsedAddressInputs(["//src/python/foo:foo-dist"], owning_address=None)])
and gives me:
Copy code
----------------------------- Captured stdout call -----------------------------
Targets([<class 'pants.backend.python.target_types.PythonDistribution'>(address=src/python/foo:foo-dist, alias='python_distribution', dependencies=None, description=None, entry_points=FrozenDict({'console_scripts': FrozenDict({'foo_tool': 'foo.bar.baz:Tool.main', 'bin_tool': '//src/python/foo/qux:bin', 'hello': ':foo-bin'}), 'foo_plugins': FrozenDict({'qux': 'foo.qux'})}), provides=foo, setup_py_commands=None, tags=None)])
However, the error is still there…
Copy code
E           Engine traceback:
E             in select
E             in pants.backend.python.goals.setup_py.generate_chroot
E             in pants.engine.internals.graph.transitive_targets
E             in pants.engine.internals.graph.resolve_targets (src/python/foo:foo-dist)
E             in pants.engine.internals.graph.resolve_unexpanded_targets (src/python/foo:foo-dist)
E             in pants.engine.internals.graph.resolve_dependencies (src/python/foo:foo-dist)
E             in pants.backend.python.target_types_rules.inject_python_distribution_dependencies (src/python/foo:foo-dist)
E             in pants.backend.python.target_types_rules.resolve_python_distribution_entry_points
E           Traceback (no traceback):
E             <pants native internals>
E           Exception: Could not find a rule to satisfy Get(Targets, UnparsedAddressInputs, UnparsedAddressInputs(values=('//src/python/foo/qux:bin',), relative_to='src/python/foo')).
From the code under test:
Copy code
targets = await Get(Targets, UnparsedAddressInputs([ref], owning_address=address))
Do I simply just miss some required QueryRule()`s for the rule runner?
Yep, found it. Took a while to realize that I had to add QueryRules that matched the actual Get calls…
or so I thought…. hmmm
ok, I got this message:
Copy code
E       Exception: No installed QueryRules can compute Targets given input Params(UnparsedAddressInputs), but it can be produced using:
E         Params(Addresses)
E         Params(UnexpandedTargets)
when I have these QueryRule()s
Copy code
QueryRule(Addresses, (UnparsedAddressInputs,)),
            QueryRule(UnexpandedTargets, (Addresses,)),
            QueryRule(Targets, (UnexpandedTargets,)),
So, if I add a QueryRule() going from UnparsedAddressInputs to Targets, it works when I use the rule runner request, but I can’t get any QueryRule to work when I try to use await Get()…
will take a break, back later, or tomorrow 🙂
w
@curved-television-6568: so,
Could not find a rule to satisfy Get(..)
is a runtime error, which is very unexpected. the rule graph is supposed to be compiled such that that cannot happen.
c
hmm…???
Copy code
addrs = chroot_rule_runner.request(Addresses, [UnparsedAddressInputs(["//src/python/foo:foo-dist"], owning_address=None)])
        print(addrs)
>       unexpanded = chroot_rule_runner.request(UnexpandedTargets, Addresses(addrs))
Copy code
>       native_engine.execution_add_root_select(
            self.py_scheduler, execution_request, params, product
        )
E       Exception: No installed QueryRules can compute UnexpandedTargets given input Params(Address), but it can be produced using:
E         Params(Addresses)

src/python/pants/engine/internals/scheduler.py:291: Exception
Copy code
----------------------------- Captured stdout call -----------------------------
Addresses([Address(src/python/foo:foo-dist)])
So, it seems there’s something weird going on here..
w
we do that by having the
@rule
decorator detect usages of
Get
in your rule body
is there some reason that this
Get
might not have been detected in your
@rule
body? had it been extracted into a separate function perhaps?
c
@witty-crayon-22786 but during unit test runs, not all rules are loaded, right? so it could possibly be a test setup issue… I guess
Ah, that could be it
Yes, my Get() call is in a separate function
w
ah, yea… sorry about that. the
@rule
analysis is static, but very basic. it cannot walk into other functions to detect usages like that.
i’ll see if we can improve the runtime error message to mention this case.
👍 2
c
I’ll refactor it back in, simple enough 🙂
w
c
That did resolve it, thanks 👍
reading up on the docs to see if I could (should?) have resolved it that way.. nit-pick is the mention of the extinct engine channel..
ask for help in the #engine channel …
https://www.pantsbuild.org/docs/rules-api-concepts
And, well yes, I could’ve.. as it was on the very first line on the section for
await Get
..
In addition to requesting types in your rule’s parameters, you can request types in the body of your rule.
This could be highlighted for additional emphasis, though (although the new improved error message makes this less important) 🙂
I’m not used to find documentation in general to be so well covered, so kudos to you on that 💯