diff --git a/aioddd/__init__.py b/aioddd/__init__.py index 3c7370b..9ccaeb4 100644 --- a/aioddd/__init__.py +++ b/aioddd/__init__.py @@ -43,7 +43,7 @@ find_event_mapper_by_name, find_event_mapper_by_type, ) -from .utils import env, env_resolver, get_env, get_simple_logger +from .utils import env, get_env, get_simple_logger from .value_objects import Id, StrDateTime, Timestamp __all__ = ( @@ -91,7 +91,6 @@ # utils 'get_env', 'get_simple_logger', - 'env_resolver', 'env', # value_objects 'Id', diff --git a/aioddd/utils.py b/aioddd/utils.py index dfd1bda..18437cb 100644 --- a/aioddd/utils.py +++ b/aioddd/utils.py @@ -28,17 +28,15 @@ def get_simple_logger( _ENV: Optional[Dict[str, Any]] = None -def env_resolver() -> Optional[Dict[str, Any]]: - """Override this method to use below env method to automatically cache and get type validations magically.""" - return {} - - def env(key: Optional[str] = None, typ: Optional[Type[_T]] = None) -> _T: + """Get full environment variables resolved if no argument given or env var matching key and optional type given.""" global _ENV - if not _ENV: - _ENV = env_resolver() or {} - if not key: + if _ENV is None: + _ENV = env.resolver() # type: ignore + if key is None: return _ENV # type: ignore + if not isinstance(_ENV, dict): + raise ValueError('"_ENV" variable must be a dict. Check env.resolver method.') if key not in _ENV: raise KeyError( '<{0}{1}> does not exist as environment variable'.format(key, ': {0}'.format(typ.__name__) if typ else '') @@ -49,3 +47,6 @@ def env(key: Optional[str] = None, typ: Optional[Type[_T]] = None) -> _T: '<{0}{1}> does not exist as environment variable'.format(key, ': {0}'.format(typ.__name__) if typ else '') ) return val + + +env.resolver = lambda: None # type: ignore diff --git a/pyproject.toml b/pyproject.toml index 648c79f..034aff1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [metadata] name = "aioddd" -version = "1.3.0" +version = "1.3.1" description = "Async Python DDD utilities library." license = "MIT" authors = ["ticdenis "] @@ -32,7 +32,7 @@ uuid = "1.30" [tool.pylint.master] jobs = "0" [tool.pylint.messages_control] -disable = "C0103,C0114,C0115,C0116,C0205,C0209,C0301,E0401,E0611,E1136,R0903,R1704,R1725,W0108,W0212,W0235,W0236,W0603,W0611,W0622,W0707,W1202" +disable = "C0103,C0114,C0115,C0116,C0205,C0209,C0301,E0401,E0611,E1135,E1136,R0903,R1704,R1725,W0108,W0212,W0235,W0236,W0603,W0611,W0622,W0707,W1202" [tool.pytest.ini_options] cache_dir = "var/cache/.pytest_cache"