mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-07-04 12:23:14 +03:00
Add implementation
This commit is contained in:
parent
34902db86e
commit
3873d1bc2b
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -116,6 +116,7 @@ cdef class Configuration(Object):
|
||||||
cdef dict __children
|
cdef dict __children
|
||||||
cdef list __yaml_files
|
cdef list __yaml_files
|
||||||
cdef list __ini_files
|
cdef list __ini_files
|
||||||
|
cdef list __pydantic_settings
|
||||||
cdef object __weakref__
|
cdef object __weakref__
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -224,6 +224,7 @@ class Configuration(Object[Any]):
|
||||||
strict: bool = False,
|
strict: bool = False,
|
||||||
yaml_files: Optional[_Iterable[Union[Path, str]]] = None,
|
yaml_files: Optional[_Iterable[Union[Path, str]]] = None,
|
||||||
ini_files: Optional[_Iterable[Union[Path, str]]] = None,
|
ini_files: Optional[_Iterable[Union[Path, str]]] = None,
|
||||||
|
pydantic_settings: Optional[_Iterable[PydanticSettings]] = None,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
def __enter__(self) -> Configuration : ...
|
def __enter__(self) -> Configuration : ...
|
||||||
def __exit__(self, *exc_info: Any) -> None: ...
|
def __exit__(self, *exc_info: Any) -> None: ...
|
||||||
|
@ -248,6 +249,9 @@ class Configuration(Object[Any]):
|
||||||
def get_ini_files(self) -> _List[Union[Path, str]]: ...
|
def get_ini_files(self) -> _List[Union[Path, str]]: ...
|
||||||
def set_ini_files(self, files: _Iterable[Union[Path, str]]) -> Configuration: ...
|
def set_ini_files(self, files: _Iterable[Union[Path, str]]) -> Configuration: ...
|
||||||
|
|
||||||
|
def get_pydantic_settings(self) -> _List[PydanticSettings]: ...
|
||||||
|
def set_pydantic_settings(self, settings: _Iterable[PydanticSettings]) -> Configuration: ...
|
||||||
|
|
||||||
def load(self, required: bool = False, envs_required: bool = False) -> None: ...
|
def load(self, required: bool = False, envs_required: bool = False) -> None: ...
|
||||||
|
|
||||||
def get(self, selector: str) -> Any: ...
|
def get(self, selector: str) -> Any: ...
|
||||||
|
|
|
@ -1755,12 +1755,13 @@ cdef class Configuration(Object):
|
||||||
|
|
||||||
DEFAULT_NAME = 'config'
|
DEFAULT_NAME = 'config'
|
||||||
|
|
||||||
def __init__(self, name=DEFAULT_NAME, default=None, strict=False, yaml_files=None, ini_files=None):
|
def __init__(self, name=DEFAULT_NAME, default=None, strict=False, yaml_files=None, ini_files=None, pydantic_settings=None):
|
||||||
self.__name = name
|
self.__name = name
|
||||||
self.__strict = strict
|
self.__strict = strict
|
||||||
self.__children = {}
|
self.__children = {}
|
||||||
self.__yaml_files = []
|
self.__yaml_files = []
|
||||||
self.__ini_files = []
|
self.__ini_files = []
|
||||||
|
self.__pydantic_settings = []
|
||||||
|
|
||||||
super().__init__(provides={})
|
super().__init__(provides={})
|
||||||
self.set_default(default)
|
self.set_default(default)
|
||||||
|
@ -1773,6 +1774,10 @@ cdef class Configuration(Object):
|
||||||
ini_files = []
|
ini_files = []
|
||||||
self.set_ini_files(ini_files)
|
self.set_ini_files(ini_files)
|
||||||
|
|
||||||
|
if pydantic_settings is None:
|
||||||
|
pydantic_settings = []
|
||||||
|
self.set_pydantic_settings(pydantic_settings)
|
||||||
|
|
||||||
def __deepcopy__(self, memo):
|
def __deepcopy__(self, memo):
|
||||||
copied = memo.get(id(self))
|
copied = memo.get(id(self))
|
||||||
if copied is not None:
|
if copied is not None:
|
||||||
|
@ -1860,7 +1865,7 @@ cdef class Configuration(Object):
|
||||||
|
|
||||||
def get_yaml_files(self):
|
def get_yaml_files(self):
|
||||||
"""Return list of YAML files."""
|
"""Return list of YAML files."""
|
||||||
return self.__yaml_files
|
return list(self.__yaml_files)
|
||||||
|
|
||||||
def set_yaml_files(self, files):
|
def set_yaml_files(self, files):
|
||||||
"""Set list of YAML files."""
|
"""Set list of YAML files."""
|
||||||
|
@ -1869,13 +1874,22 @@ cdef class Configuration(Object):
|
||||||
|
|
||||||
def get_ini_files(self):
|
def get_ini_files(self):
|
||||||
"""Return list of INI files."""
|
"""Return list of INI files."""
|
||||||
return self.__ini_files
|
return list(self.__ini_files)
|
||||||
|
|
||||||
def set_ini_files(self, files):
|
def set_ini_files(self, files):
|
||||||
"""Set list of INI files."""
|
"""Set list of INI files."""
|
||||||
self.__ini_files = list(files)
|
self.__ini_files = list(files)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def get_pydantic_settings(self):
|
||||||
|
"""Return list of Pydantic settings."""
|
||||||
|
return list(self.__pydantic_settings)
|
||||||
|
|
||||||
|
def set_pydantic_settings(self, settings):
|
||||||
|
"""Set list of Pydantic settings."""
|
||||||
|
self.__pydantic_settings = list(settings)
|
||||||
|
return self
|
||||||
|
|
||||||
def load(self, required=UNDEFINED, envs_required=UNDEFINED):
|
def load(self, required=UNDEFINED, envs_required=UNDEFINED):
|
||||||
"""Load configuration.
|
"""Load configuration.
|
||||||
|
|
||||||
|
@ -1899,6 +1913,9 @@ cdef class Configuration(Object):
|
||||||
for file in self.get_ini_files():
|
for file in self.get_ini_files():
|
||||||
self.from_ini(file, required=required, envs_required=envs_required)
|
self.from_ini(file, required=required, envs_required=envs_required)
|
||||||
|
|
||||||
|
for settings in self.get_pydantic_settings():
|
||||||
|
self.from_pydantic(settings, required=required)
|
||||||
|
|
||||||
def get(self, selector, required=False):
|
def get(self, selector, required=False):
|
||||||
"""Return configuration option.
|
"""Return configuration option.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user