1*60517a1eSAndroid Build Coastguard Worker# Copyright 2023 The Bazel Authors. All rights reserved. 2*60517a1eSAndroid Build Coastguard Worker# 3*60517a1eSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 4*60517a1eSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 5*60517a1eSAndroid Build Coastguard Worker# You may obtain a copy of the License at 6*60517a1eSAndroid Build Coastguard Worker# 7*60517a1eSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 8*60517a1eSAndroid Build Coastguard Worker# 9*60517a1eSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*60517a1eSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 11*60517a1eSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*60517a1eSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 13*60517a1eSAndroid Build Coastguard Worker# limitations under the License. 14*60517a1eSAndroid Build Coastguard Worker 15*60517a1eSAndroid Build Coastguard Worker"""Public entry point for py_binary.""" 16*60517a1eSAndroid Build Coastguard Worker 17*60517a1eSAndroid Build Coastguard Workerload("@rules_python_internal//:rules_python_config.bzl", "config") 18*60517a1eSAndroid Build Coastguard Workerload("//python/private:register_extension_info.bzl", "register_extension_info") 19*60517a1eSAndroid Build Coastguard Workerload("//python/private:util.bzl", "add_migration_tag") 20*60517a1eSAndroid Build Coastguard Workerload("//python/private/common:py_binary_macro_bazel.bzl", _starlark_py_binary = "py_binary") 21*60517a1eSAndroid Build Coastguard Worker 22*60517a1eSAndroid Build Coastguard Worker# buildifier: disable=native-python 23*60517a1eSAndroid Build Coastguard Worker_py_binary_impl = _starlark_py_binary if config.enable_pystar else native.py_binary 24*60517a1eSAndroid Build Coastguard Worker 25*60517a1eSAndroid Build Coastguard Workerdef py_binary(**attrs): 26*60517a1eSAndroid Build Coastguard Worker """Creates an executable Python program. 27*60517a1eSAndroid Build Coastguard Worker 28*60517a1eSAndroid Build Coastguard Worker This is the public macro wrapping the underlying rule. Args are forwarded 29*60517a1eSAndroid Build Coastguard Worker on as-is unless otherwise specified. See 30*60517a1eSAndroid Build Coastguard Worker the underlying {bzl:obj}`py_binary rule<//python/private/common:py_binary_rule_bazel.bzl%py_binary>` 31*60517a1eSAndroid Build Coastguard Worker for detailed attribute documentation. 32*60517a1eSAndroid Build Coastguard Worker 33*60517a1eSAndroid Build Coastguard Worker This macro affects the following args: 34*60517a1eSAndroid Build Coastguard Worker * `python_version`: cannot be `PY2` 35*60517a1eSAndroid Build Coastguard Worker * `srcs_version`: cannot be `PY2` or `PY2ONLY` 36*60517a1eSAndroid Build Coastguard Worker * `tags`: May have special marker values added, if not already present. 37*60517a1eSAndroid Build Coastguard Worker 38*60517a1eSAndroid Build Coastguard Worker Args: 39*60517a1eSAndroid Build Coastguard Worker **attrs: Rule attributes forwarded onto the underlying 40*60517a1eSAndroid Build Coastguard Worker {bzl:obj}`py_binary rule<//python/private/common:py_binary_rule_bazel.bzl%py_binary>` 41*60517a1eSAndroid Build Coastguard Worker """ 42*60517a1eSAndroid Build Coastguard Worker if attrs.get("python_version") == "PY2": 43*60517a1eSAndroid Build Coastguard Worker fail("Python 2 is no longer supported: https://github.com/bazelbuild/rules_python/issues/886") 44*60517a1eSAndroid Build Coastguard Worker if attrs.get("srcs_version") in ("PY2", "PY2ONLY"): 45*60517a1eSAndroid Build Coastguard Worker fail("Python 2 is no longer supported: https://github.com/bazelbuild/rules_python/issues/886") 46*60517a1eSAndroid Build Coastguard Worker 47*60517a1eSAndroid Build Coastguard Worker _py_binary_impl(**add_migration_tag(attrs)) 48*60517a1eSAndroid Build Coastguard Worker 49*60517a1eSAndroid Build Coastguard Workerregister_extension_info( 50*60517a1eSAndroid Build Coastguard Worker extension = py_binary, 51*60517a1eSAndroid Build Coastguard Worker label_regex_for_dep = "{extension_name}", 52*60517a1eSAndroid Build Coastguard Worker) 53