Debian Codegraph @

third_party/python/taskcluster_taskgraph/taskgraph/util/set_name.py

raw
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 # Define a collection of set_name functions
6 # Note: this is stored here instead of where it is used in the `from_deps`
7 # transform to give consumers a chance to register their own `set_name`
8 # handlers before the `from_deps` schema is created.
9 SET_NAME_MAP = {}
10
11
12 def set_name(name, schema=None):
13 def wrapper(func):
14 assert name not in SET_NAME_MAP, (
15 f"duplicate set_name function name {name} ({func} and {SET_NAME_MAP[name]})"
16 )
17 SET_NAME_MAP[name] = func
18 func.schema = schema
19 return func
20
21 return wrapper
22
23
24 @set_name("strip-kind")
25 def set_name_strip_kind(config, tasks, primary_dep, primary_kind):
26 if primary_dep.label.startswith(primary_kind):
27 return primary_dep.label[len(primary_kind) + 1 :]
28 else:
29 return primary_dep.label
30
31
32 @set_name("retain-kind")
33 def set_name_retain_kind(config, tasks, primary_dep, primary_kind):
34 return primary_dep.label