Is there a good way to see orphaned files in pants...
# general
c
Is there a good way to see orphaned files in pants? basically files that only end up in lib and test targets but are never put into a binary
actually this would break a little bit if you have test libs that shouldn't be in any production code.
h
Interesting. I think you can pipe together a few commands to get this. Something like this to first get all your package targets, then to find their dependees + those package targets
Copy code
./pants filter --target-type=pex_binary,python_distribution,archive :: | xargs ./pants dependees --transitive --closed
Now, find the set difference of something like
./pants list ::
or
./pants filter --targget-type=python_library ::
, then subtract the previous result. Then on those remaining targets,
./pants filedeps
to see which files they correspond to
e
comm
is magic for stuff like this.
💯 1
âž• 1
h
Personally, I do the very verbose thing of using Python and
subprocess.run()
+ its
set
data type, but yeah
comm
allows you to stick to bash
c
Oh that's awesome. I'll give that a shot.
I think my project has a bunch of files we don't need anymore so this will help us clean them up
💯 1
h
./pants dependees
is one of my fav features of Pants for that exact reason, I love deleting code
c
Would pants consider adding a
test
argument to the targets that are
python_library
that would block them from being imported into nontest root targets? It could make this a little easier. I'm currently adding
tags = {'test-only'}
to those libs.
h
Probably before adding that would be adding more general support for visibility. Pants atm has no support for limiting imports, and you could for example import files from a
python_tests
target from a
python_library
target
c
I would love that feature. I find it very helpful for enforcing what the directory structure means.
âž• 2