`pants tailor` isn’t generating some build files I...
# general
f
pants tailor
isn’t generating some build files I would have expected it to (there are
.py
files in the directory). Is there a readable explanation of the logic of how tailor decides where a
BUILD
file is needed that someone can point me at?
h
Does
./pants list path/to/file.py
return anything? It's possible the file is already "owned" thanks to recursive
sources
This is how Pants determines which Python targets it might want to create: https://github.com/pantsbuild/pants/blob/8d1c4c4fc68295b5bd394108c441ea8ced0bc1ee/src/python/pants/backend/python/goals/tailor.py#L95-L121 And then
core/goals/tailor.py
will filter out any targets that cover files already "owned"
f
A simple example of this would be a directory that contains only an
__init__.py
file.
Copy code
./pants list foo/__init__.py
errors, but
./pants tailor
will not create a BUILD file or target for the file
Yes I know it’s gross, but we have some examples in my repo of bare modules with only an
__init__.py
.
h
probably need to set
[python].tailor_ignore_solitary_init_files = false
f
ah, thanks, will do that
That created a couple more build files, but I’ve still got a directory with an
__init__.py
file (that does contain code) plus several other modules (but no python files) that is not picking up a
BUILD
file
h
is it in your
.gitignore
by chance? https://www.pantsbuild.org/docs/troubleshooting#pants-cannot-find-a-file-in-your-project Try running
./pants count-loc path/to/file.py
to debug
f
ok, that does find it, so it must be owned by a target somewhere …
h
not necessarily,
count-loc
works regardless of targets. But
./pants list path/to/file.py
will tell you if it's already owned or not
w
can use
./pants dependees $file
to see the target that owns it
h
./pants list $file
is an easier way to do that
👍 1
f
Ah, that was an illuminating exersise. The file was owned by a
**
a couple of directories up
We kind of need the
**
glob for one of our packaging targets, but I don’t want it to stop generation of other BUILD files (or more crucially stop pants tailor from telling us if some of them are missing)
h
Great! We generally discourage `**`: the tip at the bottom of https://www.pantsbuild.org/docs/targets#target-generation
👀 1
Hm why do you need
**
? If you haven't read this page of the docs in the past two weeks, I encourage re-reading it. We rewrote it to better explain what Pants is doing with "target generation"
f
I have not re-read recently so I will do that
we are using it to construct something kind of like the “thin pex” I saw in another thread today
we want to grab a bunch of files to package for a spark dependencies zip
so far at least I have not had good luck with using pex files on spark, so this was a “good enough” hack one of my co-workers came up with
What I’d like to be able to do is have a files target that depends on a bunch of python files. I haven’t figured out a cleaner way to do it yet
h
Ah, I think making the thin pex a reality in the near future will be a better solution, especially since you're not the only one that wants it
👍 1