-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature_template_library.py
36 lines (26 loc) · 1.16 KB
/
feature_template_library.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
from __future__ import annotations
import json
from typing import TYPE_CHECKING, Sequence
if TYPE_CHECKING:
from os import PathLike
from arho_feature_template.core.feature_template import FeatureTemplate
class FeatureTemplateLibrary:
"""Class for storing FeatureTemplates and loading them from a JSON (or other conf. file)."""
def __init__(self, json_path: str | PathLike):
self.templates: list[FeatureTemplate] = []
library_dict = self.read_json(json_path)
self.build_templates(library_dict)
def read_json(self, json_path: str | PathLike) -> dict:
self.source_json = json_path
with open(json_path) as f:
return json.load(f)
def build_templates(self, library_dict: dict):
templates: list[FeatureTemplate] = []
_templates_raw = library_dict["templates"]
# for template_raw in templates_raw:
## ... build FeatureTemplate from dict here, in FeatureTemplate class or elsewhere?
# template = FeatureTemplate()
# templates.append(template)
self.templates = templates
def get_templates(self) -> Sequence[FeatureTemplate]:
return self.templates