Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions aioddd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = (
Expand Down Expand Up @@ -91,7 +91,6 @@
# utils
'get_env',
'get_simple_logger',
'env_resolver',
'env',
# value_objects
'Id',
Expand Down
17 changes: 9 additions & 8 deletions aioddd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '')
Expand All @@ -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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <denisnavarroalcaide@outlook.es>"]
Expand Down Expand Up @@ -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"
Expand Down