Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between running with/without Bazel

Tags:

python

bazel

I try to understand purpose and usage of bazel.

For this project , running command is bazel run -c opt :train_ptn -- --init_model={}. What is the difference between this command and only python train_ptn.py?

Also, this github project only contains python scripts and why do we need bazel for running this project?

like image 283
Bedrick Kiq Avatar asked Nov 22 '25 12:11

Bedrick Kiq


1 Answers

Here's the doc for bazel run: https://docs.bazel.build/versions/master/user-manual.html#run

In general, bazel run //foo:bin ensures that the target //foo:bin and all of its dependencies are built and up-to-date, then runs the target in a well-defined working directory and with certain environment variables set.

Compare that with running the binary directly: the working directory and environment may contain anything (Bazel has no control over it), so the binary may or may not find its data files and dependencies where it expects them. Even if //foo:bin is a Python script and you're running it from the right working directory, some of its dependencies may be generated files that need rebuilding.

In special cases such as the project you linked, running the binary directly (or with Python) is fine, but you have to know that. Using bazel run relieves you of the burden of having to know that it's safe to run the script directly, and it defends you against future changes to the project, if for example someone adds a generated source file to the package.

like image 50
László Avatar answered Nov 25 '25 00:11

László



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!