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

adventurous-island-11048

07/22/2022, 9:04 PM
Hi there. This is maybe a real basic, foundational question, but I'm messing around with pants, and when I ran
./pants tailor
I noticed it recursed down into my python package to add a
BUILD
file to every level of the Python package. Is this required to have all of those
BUILD
files, or can you have one for each python package?
w

witty-crayon-22786

07/22/2022, 9:06 PM
hey Donald!
while it isn’t necessary, we definitely recommend a
BUILD
file per relevant directory, as it’s effectively inevitable that you’ll need metadata for some of your files
and we’ve found that when you do have metadata for files (test timeouts, extra dependencies, etc), defining that metadata near/next-to those files reduces boilerplate significantly, and is easiest to reason about
a

adventurous-island-11048

07/22/2022, 9:09 PM
Hrm, okay. I'll give that a try. I'm just experimenting right now with turning https://github.com/pypi/warehouse into a relatively small monorepo that has the main app + a few libs we've extracted from it over the years that are currently in their own repos + maybe a few isolated services. Most of my monorepo experience has been with go and bazel, but figured I'd try out pants since Bazel's python support is awful.
Thanks!
w

witty-crayon-22786

07/22/2022, 9:10 PM
sure thing!
w

wide-midnight-78598

07/22/2022, 9:11 PM
FYI: Similar discussion with a lot of comments and replies https://pantsbuild.slack.com/archives/C046T6T9U/p1652381728327739 Almost feel we need a FAQ for these kinda things
w

witty-crayon-22786

07/22/2022, 9:12 PM
mm, the first link in that thread referencing the “Tip: one BUILD file per directory” callout is still pretty good: https://www.pantsbuild.org/docs/targets#target-generation
👍 1
but edits to include counterpoints would be … considered 😉
a

adventurous-island-11048

07/22/2022, 9:20 PM
cool, I'll read through those. I don't really have a specific complaint about it, it just felt wrong? but that may just be myself being weird, but I conceptually don't think of it as I need to build some random project, but need to build some specific artifact, and those files are all inputs to that artifact, so I may just need to adjust my thinking
h

high-yak-85899

07/22/2022, 9:21 PM
I'm a big fan of many BUILD files. The times I tend to avoid it are when I have something like a
testdata
directory for unit tests. If you place the
BUILD
file for those resources in that directory, you then have to use absolute references in the directory you care about (often only one level up) which is burdensome. Instead, I like referencing my testdata files where my test targets live so I can use simpler target syntax when setting dependencies.
h

happy-kitchen-89482

07/22/2022, 9:36 PM
To clarify though - if you don't want that many BUILD files you can manually create a smaller number of them, and use recursive globs (e.g.,
**/*.py
) in their
sources=
to capture all the subdirs.
We've found that this may not be ideal, but you can definitely do it if you have reason to prefer it
tailor
won't help you there though, but you could roll your own similar thing, or just do it manually since there would be a lot fewer to begin with.
4 Views