edq.config.common
This module houses common information, mainly for the purpose of breaking dependency cycles.
Users should strongly prefer edq.config.settings over this module.
1#pylint: disable=invalid-name 2 3""" 4This module houses common information, mainly for the purpose of breaking dependency cycles. 5Users should strongly prefer `edq.config.settings` over this module. 6""" 7 8import abc 9import typing 10 11import platformdirs 12 13import edq.config.constants 14import edq.util.serial 15 16_DEFAULT_CONFIG_FILENAME: str = 'edq-config.json' 17_config_filename: str = _DEFAULT_CONFIG_FILENAME 18 19_DEFAULT_DEFAULT_ENCRYPTION_KEY: str = 'edq' 20_default_encryption_key: str = _DEFAULT_DEFAULT_ENCRYPTION_KEY 21 22_DEFAULT_ENV_PREFIX: str = 'EDQ__' 23_env_prefix: str = _DEFAULT_ENV_PREFIX 24 25_DEFAULT_GLOBAL_DIR: str = platformdirs.user_config_dir() 26_global_dir: str = _DEFAULT_GLOBAL_DIR 27 28class InternalApplicationConfig(edq.util.serial.DictConverter): 29 """ 30 An internal-only class for breaking dependency cycles. 31 See edq.config.app.BaseApplicationConfig for information about application configs. 32 """ 33 34 serialization_skip_fields = { 35 '_extra', 36 } 37 38 def __init__(self, 39 encryption_key: typing.Union[str, None] = None, 40 debug: typing.Union[bool, None] = None, 41 log_level: typing.Union[str, None] = None, 42 quiet: typing.Union[bool, None] = None, 43 **kwargs: typing.Any) -> None: 44 if (encryption_key is None): 45 encryption_key = _default_encryption_key 46 47 self.encryption_key: str = encryption_key 48 """ The encryption key to use for config secrets. """ 49 50 self.debug: typing.Union[bool, None] = debug 51 """ If extra debugging (e.g., logging) information should be provided. """ 52 53 self.log_level: typing.Union[str, None] = log_level 54 """ The log level this program was started with. """ 55 56 self.quiet: typing.Union[bool, None] = quiet 57 """ If the logs should give reduced output. """ 58 59 self._extra: typing.Dict[str, typing.Any] = kwargs 60 """ Config options that were not explicitly handled in the constructor. """ 61 62 def to_dict(self, 63 context: typing.Union[edq.util.serial.SerializationContext, None] = None, 64 ) -> typing.Dict[str, edq.util.serial.PODType]: 65 if (context is None): 66 context = edq.util.serial.SerializationContext() 67 else: 68 context = context.copy() 69 70 if (context.key is None): 71 context.key = self.encryption_key 72 73 return super().to_dict(context) 74 75class InternalConfigSourceSpec(abc.ABC, edq.util.serial.DictConverter): 76 """ 77 An internal-only class for breaking dependency cycles. 78 See edq.config.source.ConfigSourceSpec for information about config source specifications. 79 """ 80 81 label: str = '' 82 """ 83 A label set by each subclass to identify the type of source spec. 84 Generally, a user-friendly version of the class name. 85 """ 86 87 def __init__(self) -> None: 88 if (len(self.label) == 0): 89 raise ValueError(f"ConfigSourceSpec child class ({type(self)}) did not set label.") 90 91 self.type: str = self.label 92 """ A label identifying the type of source this is (mainly used for identification during serialization). """ 93 94 @abc.abstractmethod 95 def get_help_lines(self) -> typing.List[str]: 96 """ 97 Get lines of text describing how this source is loaded. 98 This text is intended to be used in a help prompt. 99 """ 100 101# Will be set by edq.config.app on import. 102_DEFAULT_APPLICATION_CONFIG_CLASS: typing.Type[InternalApplicationConfig] = InternalApplicationConfig 103_application_config_class: typing.Type[InternalApplicationConfig] = _DEFAULT_APPLICATION_CONFIG_CLASS 104 105# Will be set by edq.config.source on import. 106_DEFAULT_LOAD_ORDER: typing.List[InternalConfigSourceSpec] = [] 107_load_order: typing.List[InternalConfigSourceSpec] = _DEFAULT_LOAD_ORDER.copy()
29class InternalApplicationConfig(edq.util.serial.DictConverter): 30 """ 31 An internal-only class for breaking dependency cycles. 32 See edq.config.app.BaseApplicationConfig for information about application configs. 33 """ 34 35 serialization_skip_fields = { 36 '_extra', 37 } 38 39 def __init__(self, 40 encryption_key: typing.Union[str, None] = None, 41 debug: typing.Union[bool, None] = None, 42 log_level: typing.Union[str, None] = None, 43 quiet: typing.Union[bool, None] = None, 44 **kwargs: typing.Any) -> None: 45 if (encryption_key is None): 46 encryption_key = _default_encryption_key 47 48 self.encryption_key: str = encryption_key 49 """ The encryption key to use for config secrets. """ 50 51 self.debug: typing.Union[bool, None] = debug 52 """ If extra debugging (e.g., logging) information should be provided. """ 53 54 self.log_level: typing.Union[str, None] = log_level 55 """ The log level this program was started with. """ 56 57 self.quiet: typing.Union[bool, None] = quiet 58 """ If the logs should give reduced output. """ 59 60 self._extra: typing.Dict[str, typing.Any] = kwargs 61 """ Config options that were not explicitly handled in the constructor. """ 62 63 def to_dict(self, 64 context: typing.Union[edq.util.serial.SerializationContext, None] = None, 65 ) -> typing.Dict[str, edq.util.serial.PODType]: 66 if (context is None): 67 context = edq.util.serial.SerializationContext() 68 else: 69 context = context.copy() 70 71 if (context.key is None): 72 context.key = self.encryption_key 73 74 return super().to_dict(context)
An internal-only class for breaking dependency cycles. See edq.config.app.BaseApplicationConfig for information about application configs.
39 def __init__(self, 40 encryption_key: typing.Union[str, None] = None, 41 debug: typing.Union[bool, None] = None, 42 log_level: typing.Union[str, None] = None, 43 quiet: typing.Union[bool, None] = None, 44 **kwargs: typing.Any) -> None: 45 if (encryption_key is None): 46 encryption_key = _default_encryption_key 47 48 self.encryption_key: str = encryption_key 49 """ The encryption key to use for config secrets. """ 50 51 self.debug: typing.Union[bool, None] = debug 52 """ If extra debugging (e.g., logging) information should be provided. """ 53 54 self.log_level: typing.Union[str, None] = log_level 55 """ The log level this program was started with. """ 56 57 self.quiet: typing.Union[bool, None] = quiet 58 """ If the logs should give reduced output. """ 59 60 self._extra: typing.Dict[str, typing.Any] = kwargs 61 """ Config options that were not explicitly handled in the constructor. """
63 def to_dict(self, 64 context: typing.Union[edq.util.serial.SerializationContext, None] = None, 65 ) -> typing.Dict[str, edq.util.serial.PODType]: 66 if (context is None): 67 context = edq.util.serial.SerializationContext() 68 else: 69 context = context.copy() 70 71 if (context.key is None): 72 context.key = self.encryption_key 73 74 return super().to_dict(context)
Return a dict that can be used to represent this object. If the dict is passed to from_dict(), an identical object should be reconstructed.
A general (but inefficient) implementation is provided by default.
Inherited Members
76class InternalConfigSourceSpec(abc.ABC, edq.util.serial.DictConverter): 77 """ 78 An internal-only class for breaking dependency cycles. 79 See edq.config.source.ConfigSourceSpec for information about config source specifications. 80 """ 81 82 label: str = '' 83 """ 84 A label set by each subclass to identify the type of source spec. 85 Generally, a user-friendly version of the class name. 86 """ 87 88 def __init__(self) -> None: 89 if (len(self.label) == 0): 90 raise ValueError(f"ConfigSourceSpec child class ({type(self)}) did not set label.") 91 92 self.type: str = self.label 93 """ A label identifying the type of source this is (mainly used for identification during serialization). """ 94 95 @abc.abstractmethod 96 def get_help_lines(self) -> typing.List[str]: 97 """ 98 Get lines of text describing how this source is loaded. 99 This text is intended to be used in a help prompt. 100 """
An internal-only class for breaking dependency cycles. See edq.config.source.ConfigSourceSpec for information about config source specifications.
A label set by each subclass to identify the type of source spec. Generally, a user-friendly version of the class name.
A label identifying the type of source this is (mainly used for identification during serialization).
95 @abc.abstractmethod 96 def get_help_lines(self) -> typing.List[str]: 97 """ 98 Get lines of text describing how this source is loaded. 99 This text is intended to be used in a help prompt. 100 """
Get lines of text describing how this source is loaded. This text is intended to be used in a help prompt.