confattr.config module¶
- class confattr.config.Config(key: str, default: T, *, help: Optional[Union[str, dict[T, str]]] = None, unit: Optional[str] = None, parent: Optional[DictConfig[Any, T]] = None, allowed_values: Optional[Sequence[T]] = None)¶
Bases:
Generic
[T
]Each instance of this class represents a setting which can be changed in a config file.
This class implements the descriptor protocol to return
value
if an instance of this class is accessed as an instance attribute. If you want to get this object you need to access it as a class instance.- Parameters:
key – The name of this setting in the config file
default – The default value of this setting
help – A description of this setting
unit – The unit of an int or float value
T
can be one of:a subclass of
enum.Enum
a class where
__str__()
returns a string representation which can be passed to the constructor to create an equal object. If that class has a str attributetype_name
this is used instead of the class name inside of config file. If that class has a str attributehelp
this is used instead of the doc string when explaining the type at the beginning of the config file.
- Raises:
ValueError – if key is not unique
- LIST_SEP = ','¶
- default_config_id = 'general'¶
- instances: dict[str, confattr.config.Config[Any]] = {}¶
- parse_value_part(t: type[T1], value: str) T1 ¶
- Raises:
ValueError – if value is invalid
- class confattr.config.ConfigTrackingChanges(key: str, default: T, *, help: Optional[Union[str, dict[T, str]]] = None, unit: Optional[str] = None, parent: Optional[DictConfig[Any, T]] = None, allowed_values: Optional[Sequence[T]] = None)¶
Bases:
Config
[T
]- Parameters:
key – The name of this setting in the config file
default – The default value of this setting
help – A description of this setting
unit – The unit of an int or float value
T
can be one of:a subclass of
enum.Enum
a class where
__str__()
returns a string representation which can be passed to the constructor to create an equal object. If that class has a str attributetype_name
this is used instead of the class name inside of config file. If that class has a str attributehelp
this is used instead of the doc string when explaining the type at the beginning of the config file.
- Raises:
ValueError – if key is not unique
- has_changed() bool ¶
- Returns:
True if
value
has been changed since the last call tosave_value()
- restore_value() None ¶
Restore
value
to the value before the last call ofsave_value()
.
- property value: T¶
- class confattr.config.DictConfig(key_prefix: str, default_values: dict[T_KEY, T], *, ignore_keys: Container[T_KEY] = {}, unit: Optional[str] = None, help: Optional[str] = None, allowed_values: Optional[Sequence[T]] = None)¶
Bases:
Generic
[T_KEY
,T
]- Parameters:
key_prefix –
default –
ignore_keys –
unit –
help –
- Raises:
ValueError – if a key is not unique
- class confattr.config.InstanceSpecificDictMultiConfig(dmc: MultiDictConfig[T_KEY, T], config_id: ConfigId)¶
Bases:
Generic
[T_KEY
,T
]
- class confattr.config.MultiConfig(key: str, default: T, *, unit: Optional[str] = None, help: Optional[Union[str, dict[T, str]]] = None, parent: Optional[MultiDictConfig[Any, T]] = None, allowed_values: Optional[Sequence[T]] = None)¶
Bases:
Config
[T
]- Parameters:
key – The name of this setting in the config file
default – The default value of this setting
help – A description of this setting
unit – The unit of an int or float value
T
can be one of:a subclass of
enum.Enum
a class where
__str__()
returns a string representation which can be passed to the constructor to create an equal object. If that class has a str attributetype_name
this is used instead of the class name inside of config file. If that class has a str attributehelp
this is used instead of the doc string when explaining the type at the beginning of the config file.
- Raises:
ValueError – if key is not unique
- class confattr.config.MultiDictConfig(key_prefix: str, default_values: dict[T_KEY, T], *, ignore_keys: Container[T_KEY] = {}, unit: Optional[str] = None, help: Optional[str] = None, allowed_values: Optional[Sequence[T]] = None)¶
Bases:
DictConfig
[T_KEY
,T
]- Parameters:
key_prefix –
default –
ignore_keys –
unit –
help –
- Raises:
ValueError – if a key is not unique