xref: /aosp_15_r20/external/bazelbuild-rules_python/python/py_runtime.bzl (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
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_runtime."""
16*60517a1eSAndroid Build Coastguard Worker
17*60517a1eSAndroid Build Coastguard Workerload("//python/private:util.bzl", "IS_BAZEL_6_OR_HIGHER", "add_migration_tag")
18*60517a1eSAndroid Build Coastguard Workerload("//python/private/common:py_runtime_macro.bzl", _starlark_py_runtime = "py_runtime")
19*60517a1eSAndroid Build Coastguard Worker
20*60517a1eSAndroid Build Coastguard Worker# buildifier: disable=native-python
21*60517a1eSAndroid Build Coastguard Worker_py_runtime_impl = _starlark_py_runtime if IS_BAZEL_6_OR_HIGHER else native.py_runtime
22*60517a1eSAndroid Build Coastguard Worker
23*60517a1eSAndroid Build Coastguard Workerdef py_runtime(**attrs):
24*60517a1eSAndroid Build Coastguard Worker    """Creates an executable Python program.
25*60517a1eSAndroid Build Coastguard Worker
26*60517a1eSAndroid Build Coastguard Worker    This is the public macro wrapping the underlying rule. Args are forwarded
27*60517a1eSAndroid Build Coastguard Worker    on as-is unless otherwise specified. See
28*60517a1eSAndroid Build Coastguard Worker    {bzl:obj}`py_runtime <//python/private/common:py_runtime_rule.bzl%py_runtime>`
29*60517a1eSAndroid Build Coastguard Worker    for detailed attribute documentation.
30*60517a1eSAndroid Build Coastguard Worker
31*60517a1eSAndroid Build Coastguard Worker    This macro affects the following args:
32*60517a1eSAndroid Build Coastguard Worker    * `python_version`: cannot be `PY2`
33*60517a1eSAndroid Build Coastguard Worker    * `srcs_version`: cannot be `PY2` or `PY2ONLY`
34*60517a1eSAndroid Build Coastguard Worker    * `tags`: May have special marker values added, if not already present.
35*60517a1eSAndroid Build Coastguard Worker
36*60517a1eSAndroid Build Coastguard Worker    Args:
37*60517a1eSAndroid Build Coastguard Worker      **attrs: Rule attributes forwarded onto
38*60517a1eSAndroid Build Coastguard Worker          {bzl:obj}`py_runtime <//python/private/common:py_runtime_rule.bzl%py_runtime>`
39*60517a1eSAndroid Build Coastguard Worker    """
40*60517a1eSAndroid Build Coastguard Worker    if attrs.get("python_version") == "PY2":
41*60517a1eSAndroid Build Coastguard Worker        fail("Python 2 is no longer supported: see https://github.com/bazelbuild/rules_python/issues/886")
42*60517a1eSAndroid Build Coastguard Worker
43*60517a1eSAndroid Build Coastguard Worker    _py_runtime_impl(**add_migration_tag(attrs))
44