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