diff options
Diffstat (limited to 'python/BUILD.bazel')
-rw-r--r-- | python/BUILD.bazel | 241 |
1 files changed, 241 insertions, 0 deletions
diff --git a/python/BUILD.bazel b/python/BUILD.bazel new file mode 100644 index 0000000..c5f2580 --- /dev/null +++ b/python/BUILD.bazel @@ -0,0 +1,241 @@ +# 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. +""" + +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/cc:distribution", + "//python/config_settings:distribution", + "//python/constraints:distribution", + "//python/private:distribution", + "//python/runfiles:distribution", + ], + visibility = ["//:__pkg__"], +) + +# ========= bzl_library targets end ========= + +bzl_library( + name = "current_py_toolchain_bzl", + srcs = ["current_py_toolchain.bzl"], +) + +bzl_library( + name = "defs_bzl", + srcs = [ + "defs.bzl", + ], + visibility = ["//visibility:public"], + deps = [ + ":current_py_toolchain_bzl", + ":py_binary_bzl", + ":py_import_bzl", + ":py_info_bzl", + ":py_library_bzl", + ":py_runtime_bzl", + ":py_runtime_info_bzl", + ":py_runtime_pair_bzl", + ":py_test_bzl", + "//python/private:bazel_tools_bzl", + ], +) + +bzl_library( + name = "proto_bzl", + srcs = [ + "proto.bzl", + ], + visibility = ["//visibility:public"], + deps = [ + "//python/private/proto:py_proto_library_bzl", + ], +) + +bzl_library( + name = "py_binary_bzl", + srcs = ["py_binary.bzl"], + deps = ["//python/private:util_bzl"], +) + +bzl_library( + name = "py_cc_link_params_info_bzl", + srcs = ["py_cc_link_params_info.bzl"], +) + +bzl_library( + name = "py_import_bzl", + srcs = ["py_import.bzl"], + deps = [":py_info_bzl"], +) + +bzl_library( + name = "py_info_bzl", + srcs = ["py_info.bzl"], + deps = ["//python/private:reexports_bzl"], +) + +bzl_library( + name = "py_library_bzl", + srcs = ["py_library.bzl"], + deps = ["//python/private:util_bzl"], +) + +bzl_library( + name = "py_runtime_bzl", + srcs = ["py_runtime.bzl"], + deps = ["//python/private:util_bzl"], +) + +bzl_library( + name = "py_runtime_pair_bzl", + srcs = ["py_runtime_pair.bzl"], + deps = ["//python/private:bazel_tools_bzl"], +) + +bzl_library( + name = "py_runtime_info_bzl", + srcs = ["py_runtime_info.bzl"], + deps = ["//python/private:reexports_bzl"], +) + +bzl_library( + name = "py_test_bzl", + srcs = ["py_test.bzl"], + deps = ["//python/private:util_bzl"], +) + +# 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", +) + +# 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 = "@bazel_tools//tools/python:autodetecting_toolchain", +) + +alias( + name = "autodetecting_toolchain_nonstrict", + actual = "@bazel_tools//tools/python:autodetecting_toolchain_nonstrict", +) + +# ========= Packaging rules ========= + +exports_files([ + "packaging.bzl", + "pip.bzl", +]) + +current_py_toolchain( + name = "current_py_toolchain", +) |