-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
57 lines (43 loc) · 1.48 KB
/
common.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
"""
Contains common functionality, required by multiple subcommands
"""
from typing import Tuple
import jinja2
from loguru import logger
from .architecture import ArchitectureConfig
from .schema import Schema, SchemaRegistry
def init(
architecture: str,
) -> Tuple[jinja2.Environment, SchemaRegistry, ArchitectureConfig]:
"""
Initialization routine for the transpiler and graph subcommands
"""
logger.info("Initializing...")
# setup templating engine
env = jinja2.Environment(
loader=jinja2.BaseLoader(),
)
# read & validate schemas
logger.info("Reading and validation schemas...")
schema_registry: SchemaRegistry = Schema.load_all()
return env, schema_registry, load_architecture(architecture, schema_registry)
def load_architecture(
architecture: str, schema_registry: SchemaRegistry
) -> ArchitectureConfig:
"""
Loads and validates the architecture
"""
logger.info("Loading user-provided architecture definition file...")
# load architecture definition
architecture: ArchitectureConfig = ArchitectureConfig.with_schema_registry(
architecture, schema_registry
)
logger.info("Validating architecture")
# check for naming collisions
collisions: list[str] = architecture.check_naming_collisions()
if len(collisions) >= 1:
logger.error(
f"Found architecture component name collisions (names have to be unique): {collisions}"
)
exit(1)
return architecture