Skip to content

Files

Latest commit

886aeea · May 28, 2025

History

History
132 lines (88 loc) · 12.3 KB

venv.md

File metadata and controls

132 lines (88 loc) · 12.3 KB

Implementation for the py_binary and py_test rules.

py_venv

py_venv(name, data, deps, env, imports, interpreter_options, package_collisions, python_version,
        resolutions, srcs)

Build a Python virtual environment and execute its interpreter.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
data Runtime dependencies of the program.

The transitive closure of the data dependencies will be available in the .runfiles folder for this binary/test. The program may optionally use the Runfiles lookup library to locate the data files, see https://pypi.org/project/bazel-runfiles/.
List of labels optional []
deps Targets that produce Python code, commonly py_library rules. List of labels optional []
env Environment variables to set when running the binary. Dictionary: String -> String optional {}
imports List of import directories to be added to the PYTHONPATH. List of strings optional []
interpreter_options Additional options to pass to the Python interpreter. List of strings optional []
package_collisions The action that should be taken when a symlink collision is encountered when creating the venv. A collision can occur when multiple packages providing the same file are installed into the venv. The possible values are:

* "error": When conflicting symlinks are found, an error is reported and venv creation halts. * "warning": When conflicting symlinks are found, an warning is reported, however venv creation continues. * "ignore": When conflicting symlinks are found, no message is reported and venv creation continues.
String optional "error"
python_version Whether to build this target and its transitive deps for a specific python version. String optional ""
resolutions Satisfy a virtual_dep with a mapping from external package name to the label of an installed package that provides it. See virtual dependencies. Dictionary: Label -> String optional {}
srcs Python source files. List of labels optional []

py_venv_binary

py_venv_binary(name, data, deps, env, imports, interpreter_options, main, package_collisions,
               python_version, resolutions, srcs, venv)

Run a Python program under Bazel using a virtualenv.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
data Runtime dependencies of the program.

The transitive closure of the data dependencies will be available in the .runfiles folder for this binary/test. The program may optionally use the Runfiles lookup library to locate the data files, see https://pypi.org/project/bazel-runfiles/.
List of labels optional []
deps Targets that produce Python code, commonly py_library rules. List of labels optional []
env Environment variables to set when running the binary. Dictionary: String -> String optional {}
imports List of import directories to be added to the PYTHONPATH. List of strings optional []
interpreter_options Additional options to pass to the Python interpreter. List of strings optional []
main Script to execute with the Python interpreter. Label required
package_collisions The action that should be taken when a symlink collision is encountered when creating the venv. A collision can occur when multiple packages providing the same file are installed into the venv. The possible values are:

* "error": When conflicting symlinks are found, an error is reported and venv creation halts. * "warning": When conflicting symlinks are found, an warning is reported, however venv creation continues. * "ignore": When conflicting symlinks are found, no message is reported and venv creation continues.
String optional "error"
python_version Whether to build this target and its transitive deps for a specific python version. String optional ""
resolutions Satisfy a virtual_dep with a mapping from external package name to the label of an installed package that provides it. See virtual dependencies. Dictionary: Label -> String optional {}
srcs Python source files. List of labels optional []
venv A virtualenv; if provided all 3rdparty deps are assumed to come via the venv. Label optional None

py_venv_test

py_venv_test(name, data, deps, env, env_inherit, imports, interpreter_options, main,
             package_collisions, python_version, resolutions, srcs, venv)

Run a Python program under Bazel using a virtualenv.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
data Runtime dependencies of the program.

The transitive closure of the data dependencies will be available in the .runfiles folder for this binary/test. The program may optionally use the Runfiles lookup library to locate the data files, see https://pypi.org/project/bazel-runfiles/.
List of labels optional []
deps Targets that produce Python code, commonly py_library rules. List of labels optional []
env Environment variables to set when running the binary. Dictionary: String -> String optional {}
env_inherit Specifies additional environment variables to inherit from the external environment when the test is executed by bazel test. List of strings optional []
imports List of import directories to be added to the PYTHONPATH. List of strings optional []
interpreter_options Additional options to pass to the Python interpreter. List of strings optional []
main Script to execute with the Python interpreter. Label required
package_collisions The action that should be taken when a symlink collision is encountered when creating the venv. A collision can occur when multiple packages providing the same file are installed into the venv. The possible values are:

* "error": When conflicting symlinks are found, an error is reported and venv creation halts. * "warning": When conflicting symlinks are found, an warning is reported, however venv creation continues. * "ignore": When conflicting symlinks are found, no message is reported and venv creation continues.
String optional "error"
python_version Whether to build this target and its transitive deps for a specific python version. String optional ""
resolutions Satisfy a virtual_dep with a mapping from external package name to the label of an installed package that provides it. See virtual dependencies. Dictionary: Label -> String optional {}
srcs Python source files. List of labels optional []
venv A virtualenv; if provided all 3rdparty deps are assumed to come via the venv. Label optional None

VirtualenvInfo

VirtualenvInfo(home)
Provider used to distinguish venvs from py rules.

FIELDS

Name Description
home Path of the virtualenv

py_venv_link

py_venv_link(venv_name, kwargs)

Build a Python virtual environment and produce a script to link it into the build directory.

PARAMETERS

Name Description Default Value
venv_name

-

None
kwargs

-

none