Build self-contained python executables.
Bazel

Build self-contained python executables.


par_binary

par_binary(name, **kwargs)

An executable Python program.

par_binary() is a drop-in replacement for py_binary() that also builds a self-contained, single-file executable for the application, with a .par file extension.

The name attribute shouldn't include the .par file extension, it's added automatically. So, for a rule like par_binary(name="myname"), build the file myname.par by doing bazel build //mypackage:myname.par

See py_binary for arguments and usage.

Attributes

name

Name; Required

A unique name for this rule.

**kwargs

Unknown; Optional


par_test

par_test(name, **kwargs)

An executable Python test.

Just like par_binary, but for py_test instead of py_binary. Useful if you specifically need to test a module's behaviour when used in a .par binary.

Attributes

name

Name; Required

A unique name for this rule.

**kwargs

Unknown; Optional


parfile

parfile(name, src, compiler, compiler_args, default_python_version, imports, main, zip_safe)

A self-contained, single-file Python program, with a .par file extension.

You probably want to use par_binary() instead of this.

TODO(b/27502830): A directory foo.par.runfiles is also created. This is a bug, don't use or depend on it.

Attributes

name

Name; Required

A unique name for this rule.

src

Label; Required

A py_binary() target

compiler

Label; Optional; Default is //compiler:compiler.par

Internal use only.

compiler_args

List of strings; Optional; Default is []

default_python_version

String; Required

A string specifying the default Python major version to use when building this par file.

See py_binary.default_python_version

imports

List of strings; Optional; Default is []

List of import directories to be added to the PYTHONPATH.

See py_binary.imports

main

Label; Required

The name of the source file that is the main entry point of the application.

See py_binary.main

zip_safe

Boolean; Optional; Default is True

Whether to import Python code and read datafiles directly from the zip archive. Otherwise, if False, all files are extracted to a temporary directory on disk each time the par file executes.


parfile_test

parfile_test(name, src, compiler, compiler_args, default_python_version, imports, main, zip_safe)

Identical to par_binary, but the rule is marked as being a test.

You probably want to use par_test() instead of this.

Attributes

name

Name; Required

A unique name for this rule.

src

Label; Required

A py_binary() target

compiler

Label; Optional; Default is //compiler:compiler.par

Internal use only.

compiler_args

List of strings; Optional; Default is []

default_python_version

String; Required

A string specifying the default Python major version to use when building this par file.

See py_binary.default_python_version

imports

List of strings; Optional; Default is []

List of import directories to be added to the PYTHONPATH.

See py_binary.imports

main

Label; Required

The name of the source file that is the main entry point of the application.

See py_binary.main

zip_safe

Boolean; Optional; Default is True

Whether to import Python code and read datafiles directly from the zip archive. Otherwise, if False, all files are extracted to a temporary directory on disk each time the par file executes.