2

I'm new to pants and uses pantsbuild python tutorials to learn about pants

The tutorial says:

The rule of thumb is that each directory of .py files has a BUILD file with a python_library target

I cannot understand why do I need BUILD file for each directory? Suppose that I have library with many directories and sub directories in it, why can't I have one BUILD file on the libraries main directory which sources all of the relevant files of the library?

Comparing pants to setup.py of pip - I can create only one setup.py on the main folder and source all of the files. Why is the concept of pants is different?

Also I have seen example of pants python project - each folder in it has BUILD file, and any BUILD file (that isn't the main BUILD file) declaring its own library containing the files of the same level its BUILD file. This lead to weird libraries names - it looks little bit "hacky"

Is there any other wrapping tool for PEX other that pants?

  • This is just the rule of thumb. There's nothing preventing you from having a single BUILD file and using "**/*.py" to bring all python files into the same target. The reason 1 BUILD file for each directory is encouraged is to allow for small and granular targets - which goes along nicely with the concept of packages in languages, python included. – whaley Mar 02 '20 at 02:21

1 Answers1

2

That pattern is also known as the 1:1:1 rule (for "1 directory with 1 BUILD file and 1 target.") and it does have advantages.

  • submodules allow greater use of the build cache and a tighter iteration cycle.
  • modules serve as isolation boundaries in multi-team codebases
  • allows terse BUILD files, skipping args like name, sources in favor of python_library()
  • and more

Pants is an enterprise scale build system that specializes in large monorepos, so the ability to operate over slices of a codebase is a necessity. Submodules act as units of work.

With that said, for a single developer codebase, you are the ultimate arbiter of what works for you.

And yes, Pex can also be built with Buck, another "Blaze-like" from Facebook.

mateor
  • 1,293
  • 1
  • 16
  • 19