0.3.6: fixed config handling with multiple sources
This commit is contained in:
parent
cb99c3911c
commit
cf4bcb7f5b
3 changed files with 15 additions and 5 deletions
|
|
@ -4,6 +4,10 @@
|
||||||
|
|
||||||
👀
|
👀
|
||||||
|
|
||||||
|
## 0.3.6
|
||||||
|
|
||||||
|
- Fixed `ConfigValue` behavior with multiple sources. It used to iterate through all the sources, possibly overwriting; now, iteration stops at first non-missing value.
|
||||||
|
|
||||||
## 0.3.5
|
## 0.3.5
|
||||||
|
|
||||||
- Fixed cb32 handling. Now leading zeros in SIQ's are stripped, and `.from_cb32()` was implemented.
|
- Fixed cb32 handling. Now leading zeros in SIQ's are stripped, and `.from_cb32()` was implemented.
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ from .itertools import makelist, kwargs_prefix, ltuple, rtuple, additem
|
||||||
from .i18n import I18n, JsonI18n, TomlI18n
|
from .i18n import I18n, JsonI18n, TomlI18n
|
||||||
from .snowflake import Snowflake, SnowflakeGen
|
from .snowflake import Snowflake, SnowflakeGen
|
||||||
|
|
||||||
__version__ = "0.3.5"
|
__version__ = "0.3.6"
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'Siq', 'SiqCache', 'SiqType', 'SiqGen', 'StringCase',
|
'Siq', 'SiqCache', 'SiqType', 'SiqGen', 'StringCase',
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@ from .functools import deprecated_alias
|
||||||
MISSING = object()
|
MISSING = object()
|
||||||
_T = TypeVar('T')
|
_T = TypeVar('T')
|
||||||
|
|
||||||
|
def _not_missing(v) -> bool:
|
||||||
|
return v and v is not MISSING
|
||||||
|
|
||||||
|
|
||||||
class MissingConfigError(LookupError):
|
class MissingConfigError(LookupError):
|
||||||
"""
|
"""
|
||||||
|
|
@ -180,9 +183,12 @@ class ConfigValue:
|
||||||
for srckey, src in obj._srcs.items():
|
for srckey, src in obj._srcs.items():
|
||||||
if srckey in self._srcs:
|
if srckey in self._srcs:
|
||||||
v = src.get(self._srcs[srckey], v)
|
v = src.get(self._srcs[srckey], v)
|
||||||
if self._required and (not v or v is MISSING):
|
if _not_missing(v):
|
||||||
|
break
|
||||||
|
if not _not_missing(v):
|
||||||
|
if self._required:
|
||||||
raise MissingConfigError(f'required config {self._srcs['default']} not set!')
|
raise MissingConfigError(f'required config {self._srcs['default']} not set!')
|
||||||
if v is MISSING:
|
else:
|
||||||
v = self._default
|
v = self._default
|
||||||
if callable(self._cast):
|
if callable(self._cast):
|
||||||
v = self._cast(v) if v is not None else self._cast()
|
v = self._cast(v) if v is not None else self._cast()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue