Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
add found injectables to the :class:`InjectionContainer` without clearing
previously found ones.
.. deprecated:: 3.4.0
This method will be removed from the public API in the future. Use
:func:`load_injection_container` instead.
"""
warnings.warn(
"Using 'load' directly from the 'InjectionContainer' is deprecated."
" Use 'load_injection_container' instead. This class will be removed from"
" the injectable's public API in the future.",
DeprecationWarning,
2,
)
cls.LOADING_DEFAULT_NAMESPACE = default_namespace or DEFAULT_NAMESPACE
cls.NAMESPACES[default_namespace] = Namespace()
if search_path is None:
search_path = os.path.dirname(get_caller_filepath())
elif not os.path.isabs(search_path):
caller_path = os.path.dirname(get_caller_filepath())
search_path = os.path.normpath(os.path.join(caller_path, search_path))
cls._link_dependencies(search_path)
cls.LOADING_DEFAULT_NAMESPACE = None
def _get_namespace_entry(cls, namespace: str) -> Namespace:
if namespace not in cls.NAMESPACES:
cls.NAMESPACES[namespace] = Namespace()
return cls.NAMESPACES[namespace]
Invoking :func:`load_injection_container` is the only necessary action before
injecting dependencies. Attempting to call an autowired function before invoking
:func:`load_injection_container` will log a warning indicating that the injection
container is empty.
This class is not meant to be instantiated and will raise an error if instantiation
is attempted.
.. deprecated:: 3.4.0
This class will be removed from the public API in the future.
"""
LOADING_DEFAULT_NAMESPACE: Optional[str] = None
LOADING_FILEPATH: Optional[str] = None
LOADED_FILEPATHS: Set[str] = set()
NAMESPACES: Dict[str, Namespace] = {}
def __new__(cls):
raise NotImplementedError("InjectionContainer must not be instantiated")
@classmethod
def load(
cls, search_path: str = None, *, default_namespace: str = None,
):
"""
Loads injectables under the search path to the :class:`InjectionContainer`
under the designated namespaces.
:param search_path: (optional) path under which to search for injectables. Can
be either a relative or absolute path. Defaults to the caller's file
directory.
:param default_namespace: (optional) designated namespace for registering