https://pantsbuild.org/ logo
#general
Title
# general
f

freezing-vegetable-92896

12/02/2021, 7:33 PM
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

hundreds-father-404

12/02/2021, 7:36 PM
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

freezing-vegetable-92896

12/02/2021, 7:39 PM
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

hundreds-father-404

12/02/2021, 7:40 PM
probably need to set
[python].tailor_ignore_solitary_init_files = false
f

freezing-vegetable-92896

12/02/2021, 7:41 PM
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

hundreds-father-404

12/02/2021, 7:45 PM
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

freezing-vegetable-92896

12/02/2021, 7:49 PM
ok, that does find it, so it must be owned by a target somewhere …
h

hundreds-father-404

12/02/2021, 7:49 PM
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

witty-crayon-22786

12/02/2021, 7:51 PM
can use
./pants dependees $file
to see the target that owns it
h

hundreds-father-404

12/02/2021, 7:52 PM
./pants list $file
is an easier way to do that
👍 1
f

freezing-vegetable-92896

12/02/2021, 7:52 PM
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

hundreds-father-404

12/02/2021, 7:53 PM
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

freezing-vegetable-92896

12/02/2021, 7:54 PM
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

happy-kitchen-89482

12/02/2021, 8:01 PM
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
5 Views