confclasses
Advanced tools
+1
-1
| Metadata-Version: 2.4 | ||
| Name: confclasses | ||
| Version: 0.3.1 | ||
| Version: 0.3.2 | ||
| Summary: A simple wrapper around dataclasses, for general configuration | ||
@@ -5,0 +5,0 @@ Author-email: Simon Fletcher <simon.fletcher@lexisnexisrisk.com> |
| Metadata-Version: 2.4 | ||
| Name: confclasses | ||
| Version: 0.3.1 | ||
| Version: 0.3.2 | ||
| Summary: A simple wrapper around dataclasses, for general configuration | ||
@@ -5,0 +5,0 @@ Author-email: Simon Fletcher <simon.fletcher@lexisnexisrisk.com> |
| import dataclasses | ||
| import io | ||
| from ruamel.yaml import YAML, CommentedMap | ||
| import inspect | ||
| from typing import get_origin, get_args | ||
@@ -12,15 +11,7 @@ from warnings import deprecated | ||
| __version__ = "0.3.1" | ||
| __version__ = "0.3.2" | ||
| __all__ = [ | ||
| 'configclass', | ||
| 'load_config', | ||
| 'save_config', | ||
| 'is_confclass', | ||
| 'fields', | ||
| 'replace' | ||
| ] | ||
| _LOADED = "__CONFIGCLASSES_LOADED__" | ||
| _SCALAR = "__CONFIGCLASSES_SCALAR__" | ||
| _UNUSED = "__CONFIGCLASSES_UNUSED__" | ||
@@ -32,2 +23,8 @@ import logging | ||
| def unused(config): | ||
| """ | ||
| Returns a dictionary of all values in the config that were not used to populate the config. | ||
| """ | ||
| return getattr(config, _UNUSED, {}) | ||
| def replace(obj, /, **changes): | ||
@@ -283,3 +280,4 @@ """ | ||
| raise ConfclassesMissingValueError( | ||
| f"Missing required config field {'.'.join(crumbs + [field.name])}" | ||
| f"Missing required config field {'.'.join(crumbs + [field.name])}", | ||
| missing = crumbs + [field.name] | ||
| ) | ||
@@ -294,7 +292,4 @@ | ||
| # this is just for logging, doesn't serve any function | ||
| for name, value in values.items(): | ||
| if name not in kwargs: | ||
| logger.info(f"unused config {'.'.join(crumbs + [name])} = {value}") | ||
| setattr(config, _UNUSED, {k: values[k] for k in values.keys() - kwargs.keys()}) | ||
| elif isinstance(values, str): | ||
@@ -301,0 +296,0 @@ if hasattr(config, _SCALAR): |
@@ -0,1 +1,4 @@ | ||
| from typing import List | ||
| class ConfclassesAttributeError(Exception): | ||
@@ -13,2 +16,6 @@ pass | ||
| """ Raised when a required value is missing from defaults or loaded configuration """ | ||
| pass | ||
| missing: List[str] | ||
| def __init__(self, *args, missing: List[str] = None, **kwargs): | ||
| self.missing = missing | ||
| super().__init__(*args, **kwargs) |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
31782
0.53%533
-0.19%