Skip to main content

Rules

py_binary

View rule sourceopen_in_new
A py_binary is an executable Python program consisting of a collection of .py source files (possibly belonging to other py_library rules), a *.runfiles directory tree containing all the code and data needed by the program at run-time, and a stub script that starts up the program with the correct initial environment and data.

Examples

If you want to run a py_binary from within another binary or test (for example, running a python binary to set up some mock resource from within a java_test) then the correct approach is to make the other binary or test depend on the py_binary in its data section. The other binary can then locate the py_binary relative to the source directory.

Arguments

py_library

View rule sourceopen_in_new

Arguments

py_test

View rule sourceopen_in_new
A py_test() rule compiles a test. A test is a binary wrapper around some test code.

Examples

It’s also possible to specify a main module:

Arguments

py_runtime

View rule sourceopen_in_new
Represents a Python runtime used to execute Python code. A py_runtime target can represent either a platform runtime or an in-build runtime. A platform runtime accesses a system-installed interpreter at a known path, whereas an in-build runtime points to an executable target that acts as the interpreter. In both cases, an “interpreter” means any executable binary or wrapper script that is capable of running a Python script passed on the command line, following the same conventions as the standard CPython interpreter. A platform runtime is by its nature non-hermetic. It imposes a requirement on the target platform to have an interpreter located at a specific path. An in-build runtime may or may not be hermetic, depending on whether it points to a checked-in interpreter or a wrapper script that accesses the system interpreter.

Example:

Arguments