|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
| 14 | + |
| 15 | +"""This package contains two sets of rules: |
| 16 | +
|
| 17 | + 1) the "core" Python rules, which were historically bundled with Bazel and |
| 18 | + are now either re-exported or copied into this repository; and |
| 19 | +
|
| 20 | + 2) the packaging rules, which were historically simply known as |
| 21 | + rules_python. |
| 22 | +
|
| 23 | +In an ideal renaming, we'd move the packaging rules to a different package so |
| 24 | +that @rules_python//python is only concerned with the core rules. |
| 25 | +""" |
| 26 | + |
14 | 27 | package(default_visibility = ["//visibility:public"]) |
15 | 28 |
|
16 | 29 | licenses(["notice"]) # Apache 2.0 |
17 | 30 |
|
| 31 | +# ========= Core rules ========= |
| 32 | + |
| 33 | +exports_files([ |
| 34 | + "defs.bzl", |
| 35 | + "python.bzl", # Deprecated, please use defs.bzl |
| 36 | +]) |
| 37 | + |
| 38 | +# This target can be used to inspect the current Python major version. To use, |
| 39 | +# put it in the `flag_values` attribute of a `config_setting` and test it |
| 40 | +# against the values "PY2" or "PY3". It will always match one or the other. |
| 41 | +# |
| 42 | +# If you do not need to test any other flags in combination with the Python |
| 43 | +# version, then as a convenience you may use the predefined `config_setting`s |
| 44 | +# `@rules_python//python:PY2` and `@rules_python//python:PY3`. |
| 45 | +# |
| 46 | +# Example usage: |
| 47 | +# |
| 48 | +# config_setting( |
| 49 | +# name = "py3_on_arm", |
| 50 | +# values = {"cpu": "arm"}, |
| 51 | +# flag_values = {"@rules_python//python:python_version": "PY3"}, |
| 52 | +# ) |
| 53 | +# |
| 54 | +# my_target( |
| 55 | +# ... |
| 56 | +# some_attr = select({ |
| 57 | +# ":py3_on_arm": ..., |
| 58 | +# ... |
| 59 | +# }), |
| 60 | +# ... |
| 61 | +# ) |
| 62 | +# |
| 63 | +# Caution: Do not `select()` on the built-in command-line flags `--force_python` |
| 64 | +# or `--python_version`, as they do not always reflect the true Python version |
| 65 | +# of the current target. `select()`-ing on them can lead to action conflicts and |
| 66 | +# will be disallowed. |
| 67 | +alias( |
| 68 | + name = "python_version", |
| 69 | + actual = "@bazel_tools//tools/python:python_version", |
| 70 | +) |
| 71 | + |
| 72 | +alias( |
| 73 | + name = "PY2", |
| 74 | + actual = "@bazel_tools//tools/python:PY2", |
| 75 | +) |
| 76 | + |
| 77 | +alias( |
| 78 | + name = "PY3", |
| 79 | + actual = "@bazel_tools//tools/python:PY3", |
| 80 | +) |
| 81 | + |
| 82 | +# The toolchain type for Python rules. Provides a Python 2 and/or Python 3 |
| 83 | +# runtime. |
| 84 | +alias( |
| 85 | + name = "toolchain_type", |
| 86 | + actual = "@bazel_tools//tools/python:toolchain_type", |
| 87 | +) |
| 88 | + |
| 89 | +# Definitions for a Python toolchain that, at execution time, attempts to detect |
| 90 | +# a platform runtime having the appropriate major Python version. Consider this |
| 91 | +# a toolchain of last resort. |
| 92 | +# |
| 93 | +# The non-strict version allows using a Python 2 interpreter for PY3 targets, |
| 94 | +# and vice versa. The only reason to use this is if you're working around |
| 95 | +# spurious failures due to PY2 vs PY3 validation. Even then, using this is only |
| 96 | +# safe if you know for a fact that your build is completely compatible with the |
| 97 | +# version of the `python` command installed on the target platform. |
| 98 | + |
| 99 | +alias( |
| 100 | + name = "autodetecting_toolchain", |
| 101 | + actual = "@bazel_tools//tools/python:autodetecting_toolchain", |
| 102 | +) |
| 103 | + |
| 104 | +alias( |
| 105 | + name = "autodetecting_toolchain_nonstrict", |
| 106 | + actual = "@bazel_tools//tools/python:autodetecting_toolchain_nonstrict", |
| 107 | +) |
| 108 | + |
| 109 | +# ========= Packaging rules ========= |
| 110 | + |
18 | 111 | exports_files([ |
19 | 112 | "pip.bzl", |
20 | | - "python.bzl", |
21 | 113 | "whl.bzl", |
22 | 114 | ]) |
0 commit comments