-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchitecture.py
58 lines (46 loc) · 1.6 KB
/
architecture.py
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
"""
Contains the architecture class
"""
from __future__ import annotations
from collections import Counter
from typing import Optional, Tuple, Union
from . import utils
from .config import YamlConfig
from .tags import RefTag, architecture_loader
from .validator import ArchitectureValidator
class ArchitectureConfig(YamlConfig):
"""
The architecture class parsed from YAML
"""
SCHEMA_NAME: str = "Architecture"
def __init__(self, metadata: Optional[dict], spec: dict) -> None:
super().__init__(metadata, spec)
def platforms(self) -> list[dict]:
"""
Returns the list of platforms
"""
return self.spec["platforms"]
def components(self) -> list[dict]:
"""
Returns the list of components
"""
return self.spec["components"]
def check_naming_collisions(self) -> list[str]:
"""
Checks for naming collisions: ensure every component name is unique
"""
names: list[str] = map(lambda x: x["name"], self.components())
counter = Counter(names)
return [i for i, j in counter.items() if j > 1]
@staticmethod
def with_schema_registry(
path: str, schema_registry: dict[str, dict]
) -> ArchitectureConfig:
"""
Parses the architecture file from a path
"""
schema: dict = schema_registry[ArchitectureConfig.SCHEMA_NAME]
data: dict = utils.load_yaml_and_validate_handle_errors(
path, schema.spec, architecture_loader(), ArchitectureValidator()
)
return ArchitectureConfig(data.get("metadata"), data["spec"])