nskit.common
nskit.common.configuration¶
Base configuration class.
Includes
- properties in model dumps
- file based config loading (json/toml/yaml)
- model dumping to toml & yaml
BaseConfiguration
¶
Bases: PropertyDumpMixin, BaseSettings
A Pydantic BaseSettings type object with Properties included in model dump, and yaml and toml integrations.
Source code in src/nskit/common/configuration/__init__.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
model_dump_toml(*, indent=None, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True)
¶
Dump model to TOML.
Source code in src/nskit/common/configuration/__init__.py
model_dump_yaml(*, indent=None, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True)
¶
Dump model to YAML.
Source code in src/nskit/common/configuration/__init__.py
settings_customise_sources(settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings)
classmethod
¶
Create settings loading, including the FileConfigSettingsSource.
Source code in src/nskit/common/configuration/__init__.py
SettingsConfigDict
¶
Bases: SettingsConfigDict
Customised Settings Config Dict.
Source code in src/nskit/common/configuration/__init__.py
nskit.common.contextmanagers¶
Reusable context managers.
ChDir
¶
Bases: ContextDecorator
Context manager for running in a specified (or temporary) directory.
The optional argument is a path to a specified target directory, if this isn't provided, a temporary directory is created
Source code in src/nskit/common/contextmanagers/chdir.py
__enter__()
¶
Change to the target directory.
Source code in src/nskit/common/contextmanagers/chdir.py
__exit__(exc_type, exc_val, exc_tb)
¶
Reset to the original directory.
Source code in src/nskit/common/contextmanagers/chdir.py
__init__(target_dir=None)
¶
Initialise the context manager.
Other Parameters:
| Name | Type | Description |
|---|---|---|
target_dir |
Optional[Path]
|
the target directory |
Source code in src/nskit/common/contextmanagers/chdir.py
Env
¶
Bases: ContextDecorator
Context manager for managing environment variables.
The optional arguments can provide either an exhaustive set of environment values, values to override or values to remove.
Source code in src/nskit/common/contextmanagers/env.py
__enter__()
¶
Change to the target environment variables.
Source code in src/nskit/common/contextmanagers/env.py
__exit__(*args, **kwargs)
¶
__init__(environ=None, override=None, remove=None)
¶
Initialise the context manager.
The parameters are applied in the following order (so can be combined): 1st - environ, 2nd - override, 3rd - remove
Other Parameters:
| Name | Type | Description |
|---|---|---|
environ |
Optional[Dict[str, str]]
|
an exhaustive set of environment values to set (replaces overall os.environ contents) |
override |
Optional[Dict[str, str]]
|
a set of environment values to either override or set (replaces values in existing os.environ) |
remove |
Optional[List[str]]
|
a set of environment values to remove (removes values if found in os.environ ) |
Source code in src/nskit/common/contextmanagers/env.py
TestExtension
¶
Bases: ContextDecorator
Context manager for running a test of an entrypoint.
Source code in src/nskit/common/contextmanagers/test_extensions.py
__enter__()
¶
Add the extension so it can be loaded.
__exit__(*args, **kwargs)
¶
Remove the extension and return to the original.
Source code in src/nskit/common/contextmanagers/test_extensions.py
__init__(name, group, entrypoint, *, solo=False)
¶
Initialise the context manager.
Other Parameters:
| Name | Type | Description |
|---|---|---|
name |
str
|
the extension name |
group |
str
|
the extension group |
entrypoint |
type
|
the object/type to load in the entrypoint |
solo |
bool
|
set so only that entrypoint will be found (can cause side-effects) |
Source code in src/nskit/common/contextmanagers/test_extensions.py
nskit.common.extensions¶
Common extension helpers.
ExtensionsEnum
¶
Bases: Enum
Enum created from available extensions on an entrypoint.
Source code in src/nskit/common/extensions.py
get_extension_names(entrypoint)
¶
Get all installed extension names for a given entrypoint.
Source code in src/nskit/common/extensions.py
get_extensions(entrypoint)
¶
Load all extensions for a given entrypoint.
Source code in src/nskit/common/extensions.py
load_extension(entrypoint, extension)
¶
Load a given extension for a given entrypoint.
Source code in src/nskit/common/extensions.py
nskit.common.io¶
nskit.common.io.json¶
nskit.common.io.toml¶
nskit.common.io.yaml¶
nskit.common.logging¶
Common logging helpers.
LoggingConfig
¶
Bases: BaseConfiguration
This is a basic config for logging.
Source code in src/nskit/common/logging/config.py
formatter
property
¶
Return the logging formatter for the format string.
LibraryLoggerFactory
¶
A factory for creating multiple library loggers.
Source code in src/nskit/common/logging/library.py
library
property
¶
Return the library name.
version
property
¶
Return the version name.
__init__(library, version, base_config=None)
¶
Initialise the logger factory.
Source code in src/nskit/common/logging/library.py
get(name, config=None, **kwargs)
¶
getLogger(name, config=None, **kwargs)
¶
Alias for the get_logger method to provide parity with the standard logging API.
get_logger(name, config=None, **kwargs)
¶
getLogger(name, config=None, **kwargs)
¶
get_library_logger(library, version, name, config=None, **kwargs)
¶
Get a (sub)logger for a library component, which includes the library and version.