Pex
Bazel rules for the Python executable packaging tool pex.
Setup
bazel_dep(name = "rules_pex", version = "{version}")
pex = use_extension("//pex:extensions.bzl", "pex")
pex.toolchain(
name = "pex_toolchains",
)
use_repo(
pex,
"pex_toolchains",
)
register_toolchains(
"@pex_toolchains//:all",
dev_dependency = True,
)
Rules
Module Extensions
py_pex_binary
load("@rules_pex//pex:defs.bzl", "py_pex_binary")
py_pex_binary(name, binary)
A rule for creating pex executables from Python targets.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| binary | The py_binary target to convert to a Pex. | Label | required |
py_pex_toolchain
load("@rules_pex//pex:defs.bzl", "py_pex_toolchain")
py_pex_toolchain(name, pex, platform, scie_jump, scie_ptex, scie_python_interpreter,
scie_python_version, scie_science)
A toolchain for the pex packaging tool rules.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| pex | The pex binary to use with the rules. | Label | required | |
| platform | The platform to target for scie executables. | String | required | |
| scie_jump | The scie jump binary to use for scie targets. | Label | required | |
| scie_ptex | The scie ptex binary to use for scie targets. | Label | required | |
| scie_python_interpreter | The standalone python interpreter archive (.tar.gz) to bundle into scie binaries. | Label | required | |
| scie_python_version | The Python version string to pass to pex for scie builds (e.g., '3.11'). | String | required | |
| scie_science | The scie science binary to use for scie targets. | Label | required |
py_scie_binary
load("@rules_pex//pex:defs.bzl", "py_scie_binary")
py_scie_binary(name, binary)
A rule for creating pex scie executables from Python targets.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| binary | The py_binary target to convert to a Pex. | Label | required |
pex
pex = use_extension("@rules_pex//pex:defs.bzl", "pex")
pex.add_fallback_windows_binaries(toolchain_name)
pex.toolchain(name, pex_version, python_version, scie_jump_version, scie_ptex_version,
scie_science_version)
Bzlmod extensions for Pex.
TAG CLASSES
add_fallback_windows_binaries
Registers Windows fallback binaries for a specific toolchain.
This tag is used to add fallback binaries for Windows platforms when the actual pex tools don't support Windows. This prevents toolchain resolution failures in multi-platform repositories.
Note: Full Windows support is tracked in https://github.com/UebelAndre/rules_pex/issues/1
Example:
pex = use_extension("//pex:extensions.bzl", "pex")
pex.toolchain(
name = "pex_toolchains",
python_version = "3.11",
)
pex.add_fallback_windows_binaries(
toolchain_name = "pex_toolchains",
)
use_repo(pex, "pex_toolchains")
register_toolchains("@pex_toolchains//:all")
Attributes
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| toolchain_name | The name of the toolchain to add Windows fallback binaries for. | String | required |
toolchain
An extension for defining a pex toolchain.
An example of defining and using a pex toolchain:
pex = use_extension("//pex:extensions.bzl", "pex")
pex.toolchain(
name = "pex_toolchains",
pex_version = "2.67.3",
python_version = "3.11",
scie_science_version = "0.15.0",
scie_jump_version = "0.15.0",
scie_ptex_version = "0.15.0",
)
use_repo(pex, "pex_toolchains")
register_toolchains(
"@pex_toolchains//:all"
)
Attributes
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | The name of the repository hub to create. | Name | required | |
| pex_version | The version of pex to download. | String | optional | "2.67.3" |
| python_version | The Python version (e.g., '3.11'). | String | optional | "3.11" |
| scie_jump_version | The version of scie jump to download. | String | optional | "1.8.0" |
| scie_ptex_version | The version of scie ptex to download. | String | optional | "1.7.0" |
| scie_science_version | The version of scie science to download. | String | optional | "0.15.0" |