xref: /aosp_15_r20/external/bazelbuild-rules_python/python/py_library.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_library."""
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_library_macro_bazel.bzl", _starlark_py_library = "py_library")
21*60517a1eSAndroid Build Coastguard Worker
22*60517a1eSAndroid Build Coastguard Worker# buildifier: disable=native-python
23*60517a1eSAndroid Build Coastguard Worker_py_library_impl = _starlark_py_library if config.enable_pystar else native.py_library
24*60517a1eSAndroid Build Coastguard Worker
25*60517a1eSAndroid Build Coastguard Workerdef py_library(**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    {bzl:obj}`py_library <//python/private/common:py_library_rule_bazel.bzl%py_library>`
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    * `srcs_version`: cannot be `PY2` or `PY2ONLY`
35*60517a1eSAndroid Build Coastguard Worker    * `tags`: May have special marker values added, if not already present.
36*60517a1eSAndroid Build Coastguard Worker
37*60517a1eSAndroid Build Coastguard Worker    Args:
38*60517a1eSAndroid Build Coastguard Worker      **attrs: Rule attributes forwarded onto
39*60517a1eSAndroid Build Coastguard Worker          {bzl:obj}`py_library <//python/private/common:py_library_rule_bazel.bzl%py_library>`
40*60517a1eSAndroid Build Coastguard Worker    """
41*60517a1eSAndroid Build Coastguard Worker    if attrs.get("srcs_version") in ("PY2", "PY2ONLY"):
42*60517a1eSAndroid Build Coastguard Worker        fail("Python 2 is no longer supported: https://github.com/bazelbuild/rules_python/issues/886")
43*60517a1eSAndroid Build Coastguard Worker
44*60517a1eSAndroid Build Coastguard Worker    _py_library_impl(**add_migration_tag(attrs))
45*60517a1eSAndroid Build Coastguard Worker
46*60517a1eSAndroid Build Coastguard Workerregister_extension_info(
47*60517a1eSAndroid Build Coastguard Worker    extension = py_library,
48*60517a1eSAndroid Build Coastguard Worker    label_regex_for_dep = "{extension_name}",
49*60517a1eSAndroid Build Coastguard Worker)
50