Hi there. This is maybe a real basic, foundational...
# general
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
file to every level of the Python package. Is this required to have all of those
files, or can you have one for each python package?
hey Donald!
while it isn’t necessary, we definitely recommend a
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
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.
sure thing!
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
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 😉
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
I'm a big fan of many BUILD files. The times I tend to avoid it are when I have something like a
directory for unit tests. If you place the
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.
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.,
) in their
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
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.