diff --git a/src/xeda/design.py b/src/xeda/design.py index 4a14f25d..359af347 100644 --- a/src/xeda/design.py +++ b/src/xeda/design.py @@ -23,7 +23,14 @@ validation_errors, validator, ) -from .utils import WorkingDirectory, hierarchical_merge, removeprefix, settings_to_dict, toml_load +from .utils import ( + WorkingDirectory, + expand_hierarchy, + hierarchical_merge, + removeprefix, + settings_to_dict, + toml_load, +) log = logging.getLogger(__name__) @@ -596,10 +603,8 @@ class Design(XedaBaseModel): @validator("flow", pre=True, always=True) def _flow_settings(cls, value): - print(f"in flow validator value={value} {type(value)}") if value: value = settings_to_dict(value) - print(f"in flow validator value set to {value} {type(value)}") return value @validator("dependencies", pre=True, always=True) @@ -746,6 +751,7 @@ def from_file( elif design_file.suffix == ".json": with open(design_file, "r") as f: design_dict = json.load(f) + design_dict = expand_hierarchy(design_dict) else: raise ValueError(f"File extension `{design_file.suffix}` is not supported.") design_dict = hierarchical_merge(design_dict, overrides) diff --git a/src/xeda/utils.py b/src/xeda/utils.py index 99074b52..260e6136 100644 --- a/src/xeda/utils.py +++ b/src/xeda/utils.py @@ -15,7 +15,6 @@ from typing import Any, Dict, Iterable, List, Optional, OrderedDict, Tuple, Type, TypeVar, Union import unittest from xml.etree import ElementTree -from git import Sequence from pyparsing import Mapping from varname import argname @@ -277,7 +276,6 @@ def get_hierarchy(dct: Dict[str, Any], path): def set_hierarchy(dct: Dict[str, Any], path, value): - print(f"set_hierarchy k={path} v={value}") if isinstance(path, str): path = re.split(SEP, path) k = path[0] @@ -292,7 +290,6 @@ def set_hierarchy(dct: Dict[str, Any], path, value): if k not in dct: dct[k] = {} set_hierarchy(dct[k], path[1:], value) - print(f"set_hierarchy dct={dct}") def append_flag(flag_list: List[str], flag: str) -> List[str]: @@ -474,6 +471,13 @@ def conv(v): return v +def expand_hierarchy(d: Dict[str, Any]) -> Dict[str, Any]: + expanded: DictStrHier = {} + for k, v in d.items(): + set_hierarchy(expanded, k, conv(v)) + return expanded + + def settings_to_dict( settings: Union[List[str], Tuple[str, ...], Mapping[str, StrOrDictStrHier]], hierarchical_keys: bool = True, @@ -496,8 +500,5 @@ def settings_to_dict( if isinstance(settings, dict): if not hierarchical_keys: return settings - expanded: DictStrHier = {} - for k, v in settings.items(): - set_hierarchy(expanded, k, conv(v)) - return expanded + return expand_hierarchy(settings) raise TypeError(f"Unsupported type: {type(settings)}")