I'm implementing a plugin to show the path from X ...
# plugins
g
I'm implementing a plugin to show the path from X to Y. X depends on Y transitively, so I want to show the middle dependencies from X to Y (e.g. X -> X1 -> X2 -> Y). I've implemented a recursive search, but when I run it I get:
Copy code
Exception: Get(Targets, DependenciesRequest, DependenciesRequest(field=<class 'pants.engine.target.Dependencies'>(alias='dependencies', address=//path/to/file.py:../../../asdf, value=None, default=None), include_special_cased_deps=False)) was not detected in your @rule body at rule compile time. Was the `Get` constructor called in a separate function, or perhaps dynamically? If so, it must be inlined into the @rule body.
Does this mean that I cannot have a recursive function that calls Get?
โœ… 2
c
Hi! It sounds like youโ€™re trying to implement the
paths
goal: https://www.pantsbuild.org/docs/reference-paths
From the error message it sounds like you may be using
Get
from a method that is not decorated as a
@rule
which is not supported. There is a new
@rule_helper
that will let you do this, but is not yet in a stable release of Pants. https://github.com/pantsbuild/pants/pull/15025
g
Hi Andreas, I wasn't aware this already existed, it works as expected, thanks!
๐Ÿ‘ 1
Is it possible to visualize the output as a graph? (e.g. a
.dot
file)
f
When was
paths
added? That's cool
c
h
I think we didn't publcizie
paths
enough, actually! It's not in release blogs. Looks like 2.9
h
As for a .dot file, you can get the data you need in JSON form using
./pants peek
but you'll have to transform it to dot format
f
what's a recommended way to do that? What comes to mind for me is to grab
networkx
as a plugin requiremnt and use it to run graph algorithms
h
I think right now people are doing this outside of Pants. I have advocated for a
./pants graph
goal, but not everyone agrees it should exist.
f
well, it's very general, so I think it would be hard to come up with what a
graph
goal would do that would meet people's needs
โž• 1
h
I instead am +1 for our docs having more pre-baked recipes
f
I'm also reminded that https://github.com/vasturiano/force-graph might be useful for visualizing this (thanks @bitter-ability-32190), and
./pants paths
should work nicely with that, since it doesn't seem to return cycles (according to https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/project_info/paths.py)
๐Ÿ™Œ 1
h
I don't think
paths
on its own returns enough information for a graph, as you have to provide --from and --to?
peek
is probably what you want
โž• 1
b
Yeah I think I used
peek
for my PoC
f
it provides enough info for a subgraph, which is what I want really
maybe a potential use case for
./pants graph
would be to output peek-style info in typical graph formats
g
In the end I've used graphviz (https://github.com/xflr6/graphviz) to create the graph, by converting the output from
pants paths
to graphviz edges.