From 7eda1e416a879b5c495a5efd411ebf201a52895e Mon Sep 17 00:00:00 2001 From: Luca Soldaini Date: Sun, 2 Apr 2023 22:47:28 -0700 Subject: [PATCH 1/3] fixed logging --- src/springs/memoizer.py | 4 ++-- src/springs/nicknames.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/springs/memoizer.py b/src/springs/memoizer.py index 08a35a2..27e2264 100644 --- a/src/springs/memoizer.py +++ b/src/springs/memoizer.py @@ -1,5 +1,6 @@ import hashlib import inspect +from logging import getLogger import pickle from functools import reduce, wraps from pathlib import Path @@ -9,9 +10,8 @@ from typing_extensions import ParamSpec from .initialize import Target -from .logging import configure_logging -LOGGER = configure_logging(__file__) +LOGGER = getLogger(__name__) P = ParamSpec("P") R = TypeVar("R") diff --git a/src/springs/nicknames.py b/src/springs/nicknames.py index 98cfc84..f024687 100644 --- a/src/springs/nicknames.py +++ b/src/springs/nicknames.py @@ -19,10 +19,10 @@ from omegaconf import MISSING, DictConfig, ListConfig from typing_extensions import ParamSpec +from logging import getLogger from .core import from_dict, from_file, to_python from .flexyclasses import FlexyClass -from .logging import configure_logging RegistryValue = Union[Callable, Type[FlexyClass], DictConfig, ListConfig] # M = TypeVar("M", bound=RegistryValue) @@ -31,7 +31,7 @@ P = ParamSpec("P") -LOGGER = configure_logging(__name__) +LOGGER = getLogger(__name__) class NicknameRegistry: From abe13c3ac4c40c384d86570f66e0583bc15bc503 Mon Sep 17 00:00:00 2001 From: Luca Soldaini Date: Sun, 2 Apr 2023 22:48:28 -0700 Subject: [PATCH 2/3] style, bumped version --- pyproject.toml | 2 +- src/springs/memoizer.py | 2 +- src/springs/nicknames.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 638f3e8..6329fd2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "springs" -version = "1.12.2" +version = "1.12.3" description = """\ A set of utilities to create and manage typed configuration files \ effectively, built on top of OmegaConf.\ diff --git a/src/springs/memoizer.py b/src/springs/memoizer.py index 27e2264..a2f49c4 100644 --- a/src/springs/memoizer.py +++ b/src/springs/memoizer.py @@ -1,8 +1,8 @@ import hashlib import inspect -from logging import getLogger import pickle from functools import reduce, wraps +from logging import getLogger from pathlib import Path from typing import Callable, Optional, Tuple, TypeVar, Union diff --git a/src/springs/nicknames.py b/src/springs/nicknames.py index f024687..ff6130b 100644 --- a/src/springs/nicknames.py +++ b/src/springs/nicknames.py @@ -2,6 +2,7 @@ import json from dataclasses import is_dataclass from inspect import isclass +from logging import getLogger from pathlib import Path from typing import ( Callable, @@ -19,7 +20,6 @@ from omegaconf import MISSING, DictConfig, ListConfig from typing_extensions import ParamSpec -from logging import getLogger from .core import from_dict, from_file, to_python from .flexyclasses import FlexyClass From 56ecf248fd6dca73d6ffd97d27f2a3e91a5a83d1 Mon Sep 17 00:00:00 2001 From: Luca Soldaini Date: Sun, 2 Apr 2023 23:01:34 -0700 Subject: [PATCH 3/3] style --- src/springs/commandline.py | 1 - src/springs/field_utils.pyi | 4 ++-- src/springs/initialize.py | 1 - src/springs/memoizer.py | 3 --- src/springs/resolvers.py | 1 - src/springs/rich_utils.py | 1 - src/springs/traversal.py | 1 - src/springs/types_utils.py | 6 ++++-- tests/test_memoize.py | 1 - tests/test_merge.py | 1 - 10 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/springs/commandline.py b/src/springs/commandline.py index 1364861..1bdf6d6 100644 --- a/src/springs/commandline.py +++ b/src/springs/commandline.py @@ -285,7 +285,6 @@ def wrap_main_method( *args: MP.args, **kwargs: MP.kwargs, ) -> RT: - if not isinstance(config_node, DictConfig): raise TypeError("Config node must be a DictConfig") diff --git a/src/springs/field_utils.pyi b/src/springs/field_utils.pyi index 20bf03c..7d646f4 100644 --- a/src/springs/field_utils.pyi +++ b/src/springs/field_utils.pyi @@ -13,7 +13,7 @@ def field( *, help: str | None = ..., omegaconf_ignore: bool = ..., - **kwargs + **kwargs, ) -> _T: ... @overload def field( @@ -21,7 +21,7 @@ def field( *, help: str | None = ..., omegaconf_ignore: bool = ..., - **kwargs + **kwargs, ) -> _T: ... class HelpLookup: diff --git a/src/springs/initialize.py b/src/springs/initialize.py index c85122a..b9c7627 100644 --- a/src/springs/initialize.py +++ b/src/springs/initialize.py @@ -24,7 +24,6 @@ class InitLater(functools.partial): - # inherits slots from functools.partial __slots__ = ("type_",) diff --git a/src/springs/memoizer.py b/src/springs/memoizer.py index a2f49c4..9c29221 100644 --- a/src/springs/memoizer.py +++ b/src/springs/memoizer.py @@ -51,7 +51,6 @@ def memoize( full_cache_dir.mkdir(parents=True, exist_ok=True) def _memoize(func: Callable[P, R]) -> Callable[P, R]: - # get the fully specified function name function_name = Target.to_string(func) @@ -61,7 +60,6 @@ def _memoize(func: Callable[P, R]) -> Callable[P, R]: @wraps(func) def wrapper(*args: P.args, **kwargs: P.kwargs) -> R: - # we accumulate all arguments in a hash here; we also use the # fully specified function name to derive a filename at which # to cache. @@ -76,7 +74,6 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> R: # we iterate over the arguments and add them to the hash unless # the are either a class instance or a function. for i, (k, v) in enumerate(bounded_arguments.arguments.items()): - if i == 0 and (k == "self" or k == "cls"): # we skip cls or self if they are the first argument # provided. diff --git a/src/springs/resolvers.py b/src/springs/resolvers.py index fea9b35..67f1785 100644 --- a/src/springs/resolvers.py +++ b/src/springs/resolvers.py @@ -33,7 +33,6 @@ def register( name: str, use_cache: bool = False ) -> Callable[[Callable[..., T]], Callable[..., T]]: def _register(func: Callable[..., T]) -> Callable[..., T]: - # will raise an error if the resolver is already registered OmegaConf.register_new_resolver( name=name, resolver=func, use_cache=use_cache, replace=False diff --git a/src/springs/rich_utils.py b/src/springs/rich_utils.py index a4653ee..712b1da 100644 --- a/src/springs/rich_utils.py +++ b/src/springs/rich_utils.py @@ -152,7 +152,6 @@ def format_usage(self): for ag in self._action_groups: for act in ag._group_actions: - if isinstance(act.metavar, str): metavar = (act.metavar,) elif act.metavar is None: diff --git a/src/springs/traversal.py b/src/springs/traversal.py index d377bdc..2a7833a 100644 --- a/src/springs/traversal.py +++ b/src/springs/traversal.py @@ -54,7 +54,6 @@ def traverse( include_root: bool = False, recurse: bool = True, ) -> Iterator[ParamSpec]: - help = HelpLookup(node) if include_root: diff --git a/src/springs/types_utils.py b/src/springs/types_utils.py index 910713e..8ac6ab5 100644 --- a/src/springs/types_utils.py +++ b/src/springs/types_utils.py @@ -36,7 +36,8 @@ def get_type_hint(obj: Any, key: Any = None) -> Optional[Type[Any]]: def is_union_annotation(type_: Any) -> bool: """Check wether `type_` is equivalent to `typing.Union[T, ...]` - From https://github.com/omry/omegaconf/blob/e95c2c76d2545a844794682108ded57fbf98f042/omegaconf/_utils.py#L195""" # noqa: E501 + From https://github.com/omry/omegaconf/blob/e95c2c76d2545a844794682108ded57fbf98f042/omegaconf/_utils.py#L195 + """ # noqa: E501 if sys.version_info >= (3, 10): if isinstance(type_, types.UnionType): return True @@ -47,7 +48,8 @@ def resolve_optional(type_: Any) -> Tuple[bool, Any]: """Check whether `type_` is equivalent to `typing.Optional[T]` for some T. - From https://github.com/omry/omegaconf/blob/e95c2c76d2545a844794682108ded57fbf98f042/omegaconf/_utils.py#L202""" # noqa: E501 + From https://github.com/omry/omegaconf/blob/e95c2c76d2545a844794682108ded57fbf98f042/omegaconf/_utils.py#L202 + """ # noqa: E501 if is_union_annotation(type_): args = type_.__args__ if NoneType in args: diff --git a/tests/test_memoize.py b/tests/test_memoize.py index a0b503e..ae64266 100644 --- a/tests/test_memoize.py +++ b/tests/test_memoize.py @@ -6,7 +6,6 @@ class TestMemoize(unittest.TestCase): def test_memoize_function(self): - with TemporaryDirectory() as d: @memoize(cachedir=d) diff --git a/tests/test_merge.py b/tests/test_merge.py index 029d358..e8c7098 100644 --- a/tests/test_merge.py +++ b/tests/test_merge.py @@ -7,7 +7,6 @@ class TestMerge(unittest.TestCase): def test_merge_dicts(self): - d1 = from_python({"a": {"c": 4, "d": 5}, "b": 2, "c": 3}) d2 = from_python({"a": {"c": 6, "e": 7}, "b": {"f": 8}})