config_ninja.contrib
Backend implementations for third-party integrations.
Each backend is implemented as a subclass of config_ninja.backend.Backend
in a module of this
package. The get_backend()
function is used to retrieve the backend class given its module name.
Available Backends
1"""Backend implementations for third-party integrations. 2 3Each backend is implemented as a subclass of `config_ninja.backend.Backend` in a module of this 4package. The `get_backend()` function is used to retrieve the backend class given its module name. 5 6## Available Backends 7 8- `config_ninja.contrib.appconfig` 9- `config_ninja.contrib.local` 10""" 11 12from __future__ import annotations 13 14import importlib 15 16from config_ninja.backend import Backend 17 18 19def get_backend(name: str) -> type[Backend]: 20 """Import the `config_ninja.backend.Backend` subclass for the given module name.""" 21 module = importlib.import_module(f'config_ninja.contrib.{name}') 22 for val in module.__dict__.values(): 23 try: 24 is_subclass = issubclass(val, Backend) 25 except TypeError: 26 continue 27 28 if is_subclass and val is not Backend: 29 return val # type: ignore[no-any-return] # is_subclass ensures the correct type 30 31 raise ValueError(f'No backend found for {name}') # pragma: no cover
20def get_backend(name: str) -> type[Backend]: 21 """Import the `config_ninja.backend.Backend` subclass for the given module name.""" 22 module = importlib.import_module(f'config_ninja.contrib.{name}') 23 for val in module.__dict__.values(): 24 try: 25 is_subclass = issubclass(val, Backend) 26 except TypeError: 27 continue 28 29 if is_subclass and val is not Backend: 30 return val # type: ignore[no-any-return] # is_subclass ensures the correct type 31 32 raise ValueError(f'No backend found for {name}') # pragma: no cover
Import the config_ninja.backend.Backend
subclass for the given module name.