Debian Codegraph @

.evergreen/legacy_config_generator/evergreen_config_generator/variants.py

raw
1 # Copyright 2009-present MongoDB, Inc.
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 from typing import Iterable, Mapping
16
17 from evergreen_config_generator import ConfigObject
18
19 from . import ValueMapping
20
21
22 class Variant(ConfigObject):
23 def __init__(
24 self,
25 name: str,
26 display_name: str,
27 run_on: list[str] | str,
28 tasks: Iterable[str | ValueMapping],
29 expansions: Mapping[str, str] | None = None,
30 tags: Iterable[str] | None = None,
31 patchable: bool | None = None,
32 batchtime: int | None = None,
33 display_tasks: Iterable[ValueMapping] = None,
34 ):
35 super(Variant, self).__init__()
36 self._variant_name = name
37 self.display_name = display_name
38 self.run_on = run_on
39 self.tasks = tasks
40 self.expansions = expansions
41 self.tags = tags
42 self.patchable = patchable
43 self.batchtime = batchtime
44 self.display_tasks = display_tasks
45
46 @property
47 def name(self):
48 return self._variant_name
49
50 def to_dict(self):
51 v = super(Variant, self).to_dict()
52 for i in 'display_name', 'expansions', 'run_on', 'tasks', 'patchable', 'batchtime', 'tags', 'display_tasks':
53 attr = getattr(self, i)
54
55 # Allow `False`, but ignore empty lists and dicts.
56 if isinstance(attr, None | list | dict) and not attr:
57 continue
58
59 v[i] = attr
60 return v