forked from bazel-contrib/rules_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeprecation.bzl
59 lines (48 loc) · 1.93 KB
/
deprecation.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Helper functions to deprecation utilities.
"""
load("@rules_python_internal//:rules_python_config.bzl", "config")
_DEPRECATION_MESSAGE = """
The '{name}' symbol in '{old_load}'
is deprecated. It is an alias to the regular rule; use it directly instead:
load("{new_load}", "{name}")
{snippet}
"""
def _symbol(kwargs, *, symbol_name, new_load, old_load, snippet = ""):
"""An internal function to propagate the deprecation warning.
This is not an API that should be used outside `rules_python`.
Args:
kwargs: Arguments to modify.
symbol_name: {type}`str` the symbol name that is deprecated.
new_load: {type}`str` the new load location under `//`.
old_load: {type}`str` the symbol import location that we are deprecating.
snippet: {type}`str` the usage snippet of the new symbol.
Returns:
The kwargs to be used in the macro creation.
"""
if config.enable_deprecation_warnings:
deprecation = _DEPRECATION_MESSAGE.format(
name = symbol_name,
old_load = old_load,
new_load = new_load,
snippet = snippet,
)
if kwargs.get("deprecation"):
deprecation = kwargs.get("deprecation") + "\n\n" + deprecation
kwargs["deprecation"] = deprecation
return kwargs
with_deprecation = struct(
symbol = _symbol,
)