Lines Matching +full:python +full:- +full:version
1 # Python Rules for Bazel
3 …ba7a1205955a45b53e854.svg?branch=main)](https://buildkite.com/bazel/python-rules-python-postsubmit)
7 This repository is the home of the core Python rules -- `py_library`,
8 `py_binary`, `py_test`, `py_proto_library`, and related symbols that provide the basis for Python
14 [Bazel Build Encyclopedia](https://docs.bazel.build/versions/master/be/python.html).
19 …, the future-proof way to depend on Python rules is via this repository. See[`Migrating from the B…
22 [backward compatibility policy](https://docs.bazel.build/versions/master/backward-compatibility.htm…
30 - Status: Beta
31 - Full Feature Parity: No
48 # Update the version "0.0.0" to the release found here:
50 bazel_dep(name = "rules_python", version = "0.0.0")
56 load("@rules_python//python:py_binary.bzl", "py_binary")
62 configuration to control what Python version is used; read the following
68 `rules_python`. Note, however, the version used tracks the most recent Python
71 If you want to use a specific Python version for your programs, then how
73 module is special because it can set the *default* Python version, which
74 is used by the version-unaware rules (e.g. `//python:py_binary.bzl` et al). For
75 submodules, it's recommended to use the version-aware rules to pin your programs
76 to a specific Python version so they don't accidentally run with a different
77 version configured by the root module.
79 ##### Configuring and using the default Python version
81 To specify what the default Python version is, set `is_default = True` when
82 calling `python.toolchain()`. This can only be done by the root module; it is
83 silently ignored if a submodule does it. Similarly, using the version-unaware
84 rules (which always use the default Python version) should only be done by the
85 root module. If submodules use them, then they may run with a different Python
86 version than they expect.
89 python = use_extension("@rules_python//python/extensions:python.bzl", "python")
91 python.toolchain(
97 Then use the base rules from e.g. `//python:py_binary.bzl`.
99 ##### Pinning to a Python version
101 Pinning to a version allows targets to force that a specific Python version is
102 used, even if the root module configures a different version as a default. This
105 1. For submodules to ensure they run with the appropriate Python version
106 2. To allow incremental, per-target, upgrading to newer Python versions,
107 typically in a mono-repo situation.
109 To configure a submodule with the version-aware rules, request the particular
110 version you need, then use the `@python_versions` repo to use the rules that
114 python = use_extension("@rules_python//python/extensions:python.bzl", "python")
116 python.toolchain(
119 use_repo(python, "python_versions")
123 the rules that force that particular version. Multiple versions can be specified
130 The `python.toolchain()` call makes its contents available under a repo named
132 `python.toolchain(python_version="3.11")` creates the repo `@python_3_11`.
134 `use_repo(python, "python_3_11")`
142 To depend on a particular unreleased version, you can do the following:
148 # Update the SHA and VERSION to the lastest version available here:
153 VERSION="0.23.1"
158 strip_prefix = "rules_python-{}".format(VERSION),
159 …b.com/bazelbuild/rules_python/releases/download/{}/rules_python-{}.tar.gz".format(VERSION,VERSION),
162 load("@rules_python//python:repositories.bzl", "py_repositories")
169 To register a hermetic Python toolchain rather than rely on a system-installed interpreter for runt…
172 load("@rules_python//python:repositories.bzl", "python_register_toolchains")
176 # Available versions are listed in @rules_python//python:versions.bzl.
177 # We recommend using the same version your team is already standardized on.
183 load("@rules_python//python:pip.bzl", "pip_parse")
192 After registration, your Python targets will use the toolchain's interpreter during execution, but …
193 is still used to 'bootstrap' Python targets (see https://github.com/bazelbuild/rules_python/issues/…
194 …ing this toolchain. Please refer to [python-build-standalone documentation's _Quirks_ section](htt…
198 Python toolchains can be utilized in other bazel rules, such as `genrule()`, by adding the `toolcha…
206 load("@rules_python//python:defs.bzl", "py_binary")
218 1. [Installing third_party packages](#installing-third_party-packages)
219 2. [Using third_party packages as dependencies](#using-third_party-packages-as-dependencies
228 pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
243 load("@rules_python//python:pip.bzl", "pip_parse")
259 Note that since `pip_parse` is a repository rule and therefore executes pip at WORKSPACE-evaluation…
260 information about the Python toolchain and cannot enforce that the interpreter
270 re-executed to pick up a non-hermetic change to your environment (e.g.,
271 updating your system `python` interpreter), you can force it to re-execute by running
272 `bazel sync --only [pip_parse name]`.
274 …ve the same implementation. The name `pip_install` may be removed in a future version of the rules.
276 …nts.txt` with a fully resolved set of dependencies using a tool such as `pip-tools` or the `compil…
306 [this issue][requirements-drawbacks] for an enumeration. If you don't
316 Bazel label names (e.g. `-`, `.`) replaced with `_`. If you need to
330 [requirements-drawbacks]: https://github.com/bazelbuild/rules_python/issues/414
349 # Python Gazelle plugin
351 [Gazelle](https://github.com/bazelbuild/bazel-gazelle)
360 The core rules are currently available in Bazel as built-in symbols, but this
362 `WORKSPACE` file and load the Python rules from
363 `@rules_python//python:defs.bzl`.
370 # Also consider using the -r flag to modify an entire workspace.
371 buildifier --lint=fix --warnings=native-py <files>
375 started](#Getting-started) above.
377 Note that Starlark-defined bundled symbols underneath
378 `@bazel_tools//tools/python` are also deprecated. These are not yet rewritten