Skip to content

Commit

Permalink
fixed parsing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
soldni committed Feb 28, 2023
1 parent 0a0ca46 commit 67b7ec8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "springs"
version = "1.12"
version = "1.12.1"
description = """\
A set of utilities to create and manage typed configuration files \
effectively, built on top of OmegaConf.\
Expand Down
1 change: 1 addition & 0 deletions src/springs/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ def wrap_main_method(
table_parser(
title="Registered Nicknames",
columns=["Nickname", "Path"],
v_justify=["center", "left"],
values=NicknameRegistry().all(),
caption=(
"Nicknames are invoked via: "
Expand Down
4 changes: 2 additions & 2 deletions src/springs/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from get_annotations import get_annotations
from omegaconf import DictConfig, OmegaConf

from .core import cast
from .core import cast, to_python
from .utils import SpringsWarnings, clean_multiline


Expand Down Expand Up @@ -441,7 +441,7 @@ def __init__(self, a):
str(k): _recursive_init(
param=v, type_=_find_child_type(cls_=_type_, attr_name=str(k))
)
for k, v in {**config_node, **kwargs}.items()
for k, v in {**to_python(config_node), **kwargs}.items()
# we already extracted the target callable, so we don't need it
if k != cls.TARGET
}
Expand Down
19 changes: 12 additions & 7 deletions src/springs/nicknames.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import inspect
import json
from dataclasses import is_dataclass
from inspect import isclass
from pathlib import Path
Expand All @@ -19,7 +20,7 @@
from omegaconf import MISSING, DictConfig, ListConfig
from typing_extensions import ParamSpec

from .core import from_dict, from_file
from .core import from_dict, from_file, to_python
from .flexyclasses import FlexyClass
from .logging import configure_logging

Expand Down Expand Up @@ -166,14 +167,18 @@ def get(
raise ValueError(f"{name} is not registered as a nickname")
return cls.__registry__.get(name, None)

@staticmethod
def convert_nickname_value_to_string(config: RegistryValue) -> str:
if is_dataclass(config):
return getattr(config, "__name__", type(config).__name__)
elif isinstance(config, (DictConfig, ListConfig)):
return json.dumps(to_python(config), indent=2)
else:
return type(config).__name__

@classmethod
def all(cls) -> Sequence[Tuple[str, str]]:
return [
(
name,
getattr(config, "__name__", type(config).__name__)
if is_dataclass(config)
else type(config).__name__,
)
(name, cls.convert_nickname_value_to_string(config))
for name, config in cls.__registry__.items()
]

0 comments on commit 67b7ec8

Please sign in to comment.