xref: /aosp_15_r20/external/bazelbuild-rules_python/python/config_settings/private/py_args.bzl (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1# Copyright 2023 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""A helper to extract default args for the transition rule."""
16
17def py_args(name, kwargs):
18    """A helper to extract common py_binary and py_test args
19
20    See https://bazel.build/reference/be/python#py_binary and
21    https://bazel.build/reference/be/python#py_test for the list
22    that should be returned
23
24    Args:
25        name: The name of the target.
26        kwargs: The kwargs to be extracted from; MODIFIED IN-PLACE.
27
28    Returns:
29        A dict with the extracted arguments
30    """
31    return dict(
32        args = kwargs.pop("args", None),
33        data = kwargs.pop("data", None),
34        env = kwargs.pop("env", None),
35        srcs = kwargs.pop("srcs", None),
36        deps = kwargs.pop("deps", None),
37        # See https://bazel.build/reference/be/python#py_binary.main
38        # for default logic.
39        # NOTE: This doesn't match the exact way a regular py_binary searches for
40        # it's main amongst the srcs, but is close enough for most cases.
41        main = kwargs.pop("main", name + ".py"),
42    )
43