| # Copyright 2017 The Bazel Authors. All rights reserved. | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| """This package contains two sets of rules: | |
| 1) the "core" Python rules, which were historically bundled with Bazel and | |
| are now either re-exported or copied into this repository; and | |
| 2) the packaging rules, which were historically simply known as | |
| rules_python. | |
| In an ideal renaming, we'd move the packaging rules to a different package so | |
| that @rules_python//python is only concerned with the core rules. | |
| """ | |
| # TODO: make current_py_toolchain.bzl private | |
| # gazelle:resolve starlark @rules_python//python:current_py_toolchain.bzl //python:current_py_toolchain_bzl | |
| # gazelle:resolve starlark //python:current_py_toolchain.bzl //python:current_py_toolchain_bzl | |
| load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | |
| load(":current_py_toolchain.bzl", "current_py_toolchain") | |
| package(default_visibility = ["//visibility:public"]) | |
| licenses(["notice"]) | |
| filegroup( | |
| name = "distribution", | |
| srcs = glob(["**"]) + [ | |
| "//python/api:distribution", | |
| "//python/bin:distribution", | |
| "//python/cc:distribution", | |
| "//python/config_settings:distribution", | |
| "//python/constraints:distribution", | |
| "//python/entry_points:distribution", | |
| "//python/extensions:distribution", | |
| "//python/local_toolchains:distribution", | |
| "//python/pip_install:distribution", | |
| "//python/private:distribution", | |
| "//python/runfiles:distribution", | |
| "//python/runtime_env_toolchains:distribution", | |
| "//python/uv:distribution", | |
| "//python/zipapp:distribution", | |
| ], | |
| visibility = ["//:__pkg__"], | |
| ) | |
| # ========= bzl_library targets end ========= | |
| # NOTE: Remember to add bzl_library targets to //tests:bzl_libraries | |
| # ========= bzl_library targets end ========= | |
| # Filegroup of bzl files that can be used by downstream rules for documentation generation | |
| filegroup( | |
| name = "bzl", | |
| srcs = [ | |
| "defs.bzl", | |
| "packaging.bzl", | |
| "pip.bzl", | |
| "repositories.bzl", | |
| "versions.bzl", | |
| "//python/pip_install:bzl", | |
| "//python/private:bzl", | |
| ], | |
| visibility = ["//visibility:public"], | |
| ) | |
| # ========= Core rules ========= | |
| exports_files([ | |
| "defs.bzl", | |
| "python.bzl", # Deprecated, please use defs.bzl | |
| ]) | |
| # This target can be used to inspect the current Python major version. To use, | |
| # put it in the `flag_values` attribute of a `config_setting` and test it | |
| # against the values "PY2" or "PY3". It will always match one or the other. | |
| # | |
| # If you do not need to test any other flags in combination with the Python | |
| # version, then as a convenience you may use the predefined `config_setting`s | |
| # `@rules_python//python:PY2` and `@rules_python//python:PY3`. | |
| # | |
| # Example usage: | |
| # | |
| # config_setting( | |
| # name = "py3_on_arm", | |
| # values = {"cpu": "arm"}, | |
| # flag_values = {"@rules_python//python:python_version": "PY3"}, | |
| # ) | |
| # | |
| # my_target( | |
| # ... | |
| # some_attr = select({ | |
| # ":py3_on_arm": ..., | |
| # ... | |
| # }), | |
| # ... | |
| # ) | |
| # | |
| # Caution: Do not `select()` on the built-in command-line flags `--force_python` | |
| # or `--python_version`, as they do not always reflect the true Python version | |
| # of the current target. `select()`-ing on them can lead to action conflicts and | |
| # will be disallowed. | |
| alias( | |
| name = "python_version", | |
| actual = "@bazel_tools//tools/python:python_version", | |
| ) | |
| alias( | |
| name = "PY2", | |
| actual = "@bazel_tools//tools/python:PY2", | |
| ) | |
| alias( | |
| name = "PY3", | |
| actual = "@bazel_tools//tools/python:PY3", | |
| ) | |
| # The toolchain type for Python rules. Provides a Python 2 and/or Python 3 | |
| # runtime. | |
| alias( | |
| name = "toolchain_type", | |
| actual = "@bazel_tools//tools/python:toolchain_type", | |
| ) | |
| toolchain_type( | |
| name = "exec_tools_toolchain_type", | |
| visibility = ["//visibility:public"], | |
| ) | |
| # Special target to indicate `None` for label attributes a default value. | |
| alias( | |
| name = "none", | |
| actual = "//python/private:sentinel", | |
| ) | |
| # Definitions for a Python toolchain that, at execution time, attempts to detect | |
| # a platform runtime having the appropriate major Python version. Consider this | |
| # a toolchain of last resort. | |
| # | |
| # The non-strict version allows using a Python 2 interpreter for PY3 targets, | |
| # and vice versa. The only reason to use this is if you're working around | |
| # spurious failures due to PY2 vs PY3 validation. Even then, using this is only | |
| # safe if you know for a fact that your build is completely compatible with the | |
| # version of the `python` command installed on the target platform. | |
| alias( | |
| name = "autodetecting_toolchain", | |
| actual = "//python/runtime_env_toolchains:runtime_env_toolchain", | |
| deprecation = "Use //python/runtime_env_toolchains:all instead", | |
| ) | |
| alias( | |
| name = "autodetecting_toolchain_nonstrict", | |
| actual = "//python/runtime_env_toolchains:runtime_env_toolchain", | |
| deprecation = "Use //python/runtime_env_toolchains:all instead", | |
| ) | |
| # ========= Packaging rules ========= | |
| exports_files([ | |
| "packaging.bzl", | |
| "pip.bzl", | |
| ]) | |
| current_py_toolchain( | |
| name = "current_py_toolchain", | |
| ) | |
| # Keep this target because it is a public API and Gazelle might otherwise | |
| # remove it if it is not loaded by other bzl_library targets. | |
| # keep | |
| bzl_library( | |
| name = "current_py_toolchain_bzl", | |
| srcs = ["current_py_toolchain.bzl"], | |
| visibility = ["//visibility:public"], | |
| ) | |
| bzl_library( | |
| name = "defs", | |
| srcs = ["defs.bzl"], | |
| deps = [ | |
| ":py_binary", | |
| ":py_import", | |
| ":py_info", | |
| ":py_library", | |
| ":py_runtime", | |
| ":py_runtime_info", | |
| ":py_runtime_pair", | |
| ":py_test", | |
| "//python:current_py_toolchain_bzl", | |
| ], | |
| ) | |
| alias( | |
| name = "defs_bzl", | |
| actual = ":defs", | |
| deprecation = "Use //python:defs instead", | |
| ) | |
| alias( | |
| name = "features_bzl", | |
| actual = ":features", | |
| deprecation = "Use //python:features instead", | |
| ) | |
| bzl_library( | |
| name = "packaging", | |
| srcs = ["packaging.bzl"], | |
| deps = [ | |
| ":py_binary", | |
| "//python/private:bzlmod_enabled", | |
| "//python/private:py_package", | |
| "//python/private:py_wheel", | |
| "//python/private:util", | |
| "@bazel_skylib//rules:native_binary", | |
| ], | |
| ) | |
| alias( | |
| name = "packaging_bzl", | |
| actual = ":packaging", | |
| deprecation = "Use //python:packaging instead", | |
| ) | |
| bzl_library( | |
| name = "pip", | |
| srcs = ["pip.bzl"], | |
| deps = [ | |
| "//python/private:normalize_name", | |
| "//python/private/pypi:multi_pip_parse", | |
| "//python/private/pypi:package_annotation", | |
| "//python/private/pypi:pip_compile", | |
| "//python/private/pypi:pip_repository", | |
| "//python/private/pypi:whl_library_alias", | |
| "//python/private/whl_filegroup", | |
| ], | |
| ) | |
| alias( | |
| name = "pip_bzl", | |
| actual = ":pip", | |
| deprecation = "Use //python:pip instead", | |
| ) | |
| bzl_library( | |
| name = "proto", | |
| srcs = ["proto.bzl"], | |
| deps = ["@com_google_protobuf//bazel:py_proto_library_bzl"], | |
| ) | |
| alias( | |
| name = "proto_bzl", | |
| actual = ":proto", | |
| deprecation = "Use //python:proto instead", | |
| ) | |
| bzl_library( | |
| name = "py_binary", | |
| srcs = ["py_binary.bzl"], | |
| deps = ["//python/private:py_binary_macro"], | |
| ) | |
| alias( | |
| name = "py_binary_bzl", | |
| actual = ":py_binary", | |
| deprecation = "Use //python:py_binary instead", | |
| ) | |
| bzl_library( | |
| name = "py_cc_link_params_info", | |
| srcs = ["py_cc_link_params_info.bzl"], | |
| deps = ["//python/private:py_cc_link_params_info"], | |
| ) | |
| alias( | |
| name = "py_cc_link_params_info_bzl", | |
| actual = ":py_cc_link_params_info", | |
| deprecation = "Use //python:py_cc_link_params_info instead", | |
| ) | |
| bzl_library( | |
| name = "py_exec_tools_info", | |
| srcs = ["py_exec_tools_info.bzl"], | |
| deps = ["//python/private:py_exec_tools_info"], | |
| ) | |
| alias( | |
| name = "py_exec_tools_info_bzl", | |
| actual = ":py_exec_tools_info", | |
| deprecation = "Use //python:py_exec_tools_info instead", | |
| ) | |
| bzl_library( | |
| name = "py_exec_tools_toolchain", | |
| srcs = ["py_exec_tools_toolchain.bzl"], | |
| deps = ["//python/private:py_exec_tools_toolchain"], | |
| ) | |
| alias( | |
| name = "py_exec_tools_toolchain_bzl", | |
| actual = ":py_exec_tools_toolchain", | |
| deprecation = "Use //python:py_exec_tools_toolchain instead", | |
| ) | |
| bzl_library( | |
| name = "py_executable_info", | |
| srcs = ["py_executable_info.bzl"], | |
| deps = ["//python/private:py_executable_info"], | |
| ) | |
| alias( | |
| name = "py_executable_info_bzl", | |
| actual = ":py_executable_info", | |
| deprecation = "Use //python:py_executable_info instead", | |
| ) | |
| bzl_library( | |
| name = "py_import", | |
| srcs = ["py_import.bzl"], | |
| deps = [":py_info"], | |
| ) | |
| alias( | |
| name = "py_import_bzl", | |
| actual = ":py_import", | |
| deprecation = "Use //python:py_import instead", | |
| ) | |
| bzl_library( | |
| name = "py_info", | |
| srcs = ["py_info.bzl"], | |
| deps = ["//python/private:py_info"], | |
| ) | |
| alias( | |
| name = "py_info_bzl", | |
| actual = ":py_info", | |
| deprecation = "Use //python:py_info instead", | |
| ) | |
| bzl_library( | |
| name = "py_library", | |
| srcs = ["py_library.bzl"], | |
| deps = ["//python/private:py_library_macro"], | |
| ) | |
| alias( | |
| name = "py_library_bzl", | |
| actual = ":py_library", | |
| deprecation = "Use //python:py_library instead", | |
| ) | |
| bzl_library( | |
| name = "py_runtime", | |
| srcs = ["py_runtime.bzl"], | |
| deps = ["//python/private:py_runtime_macro"], | |
| ) | |
| alias( | |
| name = "py_runtime_bzl", | |
| actual = ":py_runtime", | |
| deprecation = "Use //python:py_runtime instead", | |
| ) | |
| bzl_library( | |
| name = "py_runtime_info", | |
| srcs = ["py_runtime_info.bzl"], | |
| deps = ["//python/private:py_runtime_info"], | |
| ) | |
| alias( | |
| name = "py_runtime_info_bzl", | |
| actual = ":py_runtime_info", | |
| deprecation = "Use //python:py_runtime_info instead", | |
| ) | |
| bzl_library( | |
| name = "py_runtime_pair", | |
| srcs = ["py_runtime_pair.bzl"], | |
| deps = ["//python/private:py_runtime_pair_macro"], | |
| ) | |
| alias( | |
| name = "py_runtime_pair_bzl", | |
| actual = ":py_runtime_pair", | |
| deprecation = "Use //python:py_runtime_pair instead", | |
| ) | |
| # keep | |
| bzl_library( | |
| name = "py_test", | |
| srcs = ["py_test.bzl"], | |
| deps = ["//python/private:py_test_macro"], | |
| ) | |
| alias( | |
| name = "py_test_bzl", | |
| actual = ":py_test", | |
| deprecation = "Use //python:py_test instead", | |
| ) | |
| alias( | |
| name = "python_bzl", | |
| actual = ":python", | |
| deprecation = "Use //python:python instead", | |
| ) | |
| bzl_library( | |
| name = "repositories", | |
| srcs = ["repositories.bzl"], | |
| deps = [ | |
| "//python/private:is_standalone_interpreter", | |
| "//python/private:py_repositories", | |
| "//python/private:python_register_multi_toolchains", | |
| "//python/private:python_register_toolchains", | |
| "//python/private:python_repository", | |
| ], | |
| ) | |
| alias( | |
| name = "repositories_bzl", | |
| actual = ":repositories", | |
| deprecation = "Use //python:repositories instead", | |
| ) | |
| bzl_library( | |
| name = "versions", | |
| srcs = ["versions.bzl"], | |
| deps = [ | |
| "//python/private:pbs_manifest", | |
| "//python/private:platform_info", | |
| "//python/private:runtimes_manifest_workspace", | |
| ], | |
| ) | |
| alias( | |
| name = "versions_bzl", | |
| actual = ":versions", | |
| deprecation = "Use //python:versions instead", | |
| ) | |
| bzl_library( | |
| name = "features", | |
| srcs = ["features.bzl"], | |
| ) | |
| bzl_library( | |
| name = "python", | |
| srcs = ["python.bzl"], | |
| ) |