1# Copyright 2024 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"""Package annotation API for WORKSPACE setups.""" 16 17def package_annotation( 18 additive_build_content = None, 19 copy_files = {}, 20 copy_executables = {}, 21 data = [], 22 data_exclude_glob = [], 23 srcs_exclude_glob = []): 24 """Annotations to apply to the BUILD file content from package generated from a `pip_repository` rule. 25 26 [cf]: https://github.com/bazelbuild/bazel-skylib/blob/main/docs/copy_file_doc.md 27 28 Args: 29 additive_build_content (str, optional): Raw text to add to the generated `BUILD` file of a package. 30 copy_files (dict, optional): A mapping of `src` and `out` files for [@bazel_skylib//rules:copy_file.bzl][cf] 31 copy_executables (dict, optional): A mapping of `src` and `out` files for 32 [@bazel_skylib//rules:copy_file.bzl][cf]. Targets generated here will also be flagged as 33 executable. 34 data (list, optional): A list of labels to add as `data` dependencies to the generated `py_library` target. 35 data_exclude_glob (list, optional): A list of exclude glob patterns to add as `data` to the generated 36 `py_library` target. 37 srcs_exclude_glob (list, optional): A list of labels to add as `srcs` to the generated `py_library` target. 38 39 Returns: 40 str: A json encoded string of the provided content. 41 """ 42 return json.encode(struct( 43 additive_build_content = additive_build_content, 44 copy_files = copy_files, 45 copy_executables = copy_executables, 46 data = data, 47 data_exclude_glob = data_exclude_glob, 48 srcs_exclude_glob = srcs_exclude_glob, 49 )) 50