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

melodic-wolf-31860

04/14/2022, 9:53 AM
Hi team. We have a repo that is structured as below:
Copy code
- src
    - dir1
      - subdir1
        - script1.py
      - subdir2
        - script2.py
      - BUILD
    - dir2
      - subdir3
        - script3.py
      - subdir4
        - script4.py
      - BUILD
Is it advisable to have a
BUILD
file for each subdir as well? Given that we never intend to package/test the different subdirs separately? I feel that having a
BUILD
file at each subdir is unnecessary given we are happy with the defaults, and can be added later if we ever do intend to package/test/etc. those subdirs separately.
r

refined-addition-53644

04/14/2022, 9:59 AM
If you don't have any dependency etc and you also don't want to test/lint/package, then yeah you don't need to add anything. You can even explicitly ignore such directory. EDIT: re-reading your post after the comment below, I realize you are most probably asking about whether to add BUILD files in every directory vs just some top level. So you can ignore my comment.
👍 1
n

narrow-vegetable-37489

04/14/2022, 10:00 AM
It's recommended to do one per folder, but anything between that and only having one build file is possible. See the bottom of this page in the docs on why one per folder is recommended: https://www.pantsbuild.org/docs/targets
2
c

curved-television-6568

04/14/2022, 10:21 AM
Also noting that tailor can create all these BUILD files for you, so there is little manual work for simple cases such as you’ve described here.
m

melodic-wolf-31860

04/14/2022, 10:23 AM
Great thanks 🙂 Reading that tip at the bottom of the page, it sounds like the main advantage of having a build file for every subdir (rather than at every dir as I structured it above) is that it will encourage more fine-grained metadata, so we’ll take that into account.
👍 2
h

happy-kitchen-89482

04/14/2022, 12:57 PM
Note that the granularity of BUILD files only matters for your own metadata management purposes. If you prefer, you can have a top-level BUILD file or just a few of them, and use
overrides=
to override metadata on specific files. It's really up to you. Any choice you make should have no impact on performance, invalidation, caching and so on, since those happen at the file level anyway. TBH the recommendation of having one BUILD file per folder is a little outdated and reflects our personal preferences more than any deep-seated wisdom.
Note however that you do currently need to have a BUILD file inside every source root, for the sources in that source root. Currently targets cannot span multiple source roots.
h

hundreds-father-404

04/14/2022, 1:52 PM
TBH the recommendation of having one BUILD file per folder is a little outdated and reflects our personal preferences more than any deep-seated wisdom.
Disagree. A lot of thought went into it in the past five months when designing Go https://github.com/pantsbuild/pants/issues/13488
1
e

enough-analyst-54434

04/14/2022, 6:50 PM
A quick scan of the Go design thought says it was specific to Go, Does all or some of the reasoning actually apply to Python which is what the OP is about?