https://pantsbuild.org/ logo
b

billions-printer-97253

05/15/2023, 4:29 PM
Is it expected that every time I change the file of the entry_point of a pex_binary that it will rebuild every requirement each time? I was hoping for something like Docker where the build process is cached at each stage and altering code (which does not require different packages) is very quick if kept as last layer. But when I use
pants run :cli
it will rebuild all the package each time I just change the source code.
1
h

happy-kitchen-89482

05/15/2023, 4:34 PM
Hi, that's because
pants run
on a pex_binary actually builds the pex and then runs it. Instead you can
pants run
on a source file (typically the main of the binary) and it will run on the loose sources, without rebuilding an intermediate pex.
So will be fast
er
In the first case it's not necessarily rebuilding every requirement (that should be cached - if it isn't that is a separate issue), but it is repackaging the .pex file, and that takes time
In the second case you bypass that
b

billions-printer-97253

05/15/2023, 4:38 PM
Aha! Thank you!
But this won't know about the dependencies that the file will require. So probably export the virtualenv and run the script until requirements change?
e

enough-analyst-54434

05/15/2023, 4:43 PM
It will. Dependency inference is working presumably, and if not, in most cases it's appropriate to move any explicit dependencies you must list to a
python_source
target covering that file.
b

billions-printer-97253

05/15/2023, 4:45 PM
I see. Thank you @happy-kitchen-89482 and @enough-analyst-54434. Pants is an absolutely amazing tool!
🙏 2
h

happy-kitchen-89482

05/15/2023, 4:46 PM
Yep, the deps properly belong to the source, not the binary, the binary is just metadata saying "build a pex from this"
👍 2
b

billions-printer-97253

05/15/2023, 4:47 PM
This is great and will change how I've been putting together BUILD files.
w

witty-crayon-22786

05/15/2023, 4:49 PM
and to be clear about what not using a
pex_binary
avoids: all of the actual requirements going into the pex binary are cached as built wheels, so you aren’t actually rebuilding wheels each time: just copying them into an output binary.
b

billions-printer-97253

05/15/2023, 4:51 PM
That makes more sense taking into consideration the timings. The stdout does say building requirements so that is a little confusing.
5 Views