Is there a simple way to find files that have 0 ta...
# general
g
Is there a simple way to find files that have 0 targets? For example, I have a monorepo that is predominately python which is included in all python_sources targets, etc. I want to find any file that is not a python file and has 0 targets. Some of my apps have .tar.gz and .yaml files that need to be included in the build. I want to have assurances that all files have a target so I don't have to keep questioning whether or not I'm missing something.
ChatGPT's answer: Hey Jason, To check if there are files in your repository not belonging to any target with Pantsbuild, you can use the
filedeps
goal along with some shell commands to compare against all files in your repo. Here's a quick way to do it: 1. Generate a list of all files that Pants knows about:
Copy code
pants filedeps :: > pants_files.txt
1. Generate a list of all files in your repository (adjust the
find
command as needed for your repo structure):
Copy code
find . -type f > all_files.txt
1. Compare the two lists to find files not known to Pants:
Copy code
comm -23 <(sort all_files.txt) <(sort pants_files.txt) > unknown_files.txt
Check
unknown_files.txt
for any files not belonging to any target. Adjust the
find
command to exclude directories or files as necessary for your project's structure.
😅 1
Is this the most effective way?
It totally worked, but I wish there was something to warn about this in pants natively.
f
You could use
expermential_test_shell_command
to write a validation check. Specify one of your output targets as a dependency of the test target, and then write some shell commands to ensure the files you want are in fact in the output.
Pants would invoke this validation check as part of the
test
goal.
👍 1
c
still pretty cool ChatGPT managed to give you a working answer..! 😮
g
haha, definitely.