8.4.5. pymodaq_utils.config module
- class pymodaq_utils.config.BaseConfig[source]
Bases:
objectBase class to manage configuration files
Should be subclassed with proper class attributes for each configuration file you need with pymodaq
- config_template_path
The Path of the template from which the config is constructed
- Type:
Path
- Attributes:
- config_name
config_pathGet the user config path
- config_template_path
system_config_pathGet the system_wide config path
Methods
__call__(*args)Call self as a function.
To subclass
get_children(*path)Get the list of config entries at a given path within the configulation toml file
load_config(config_file_name, template_path)Load a configuration file from both system-wide and user file
save()Save the current Config object into the user toml file
get
to_dict
- get_children(*path: Iterable[str])[source]
Get the list of config entries at a given path within the configulation toml file
new in 4.3.0
- load_config(config_file_name, template_path: Path)[source]
Load a configuration file from both system-wide and user file
check also if missing entries in the configuration file compared to the template
- abstract property config_name
- property config_path
Get the user config path
- abstract property config_template_path
- property system_config_path
Get the system_wide config path
- class pymodaq_utils.config.Config[source]
Bases:
BaseConfigMain class to deal with configuration values for PyMoDAQ
Methods
To subclass
- pymodaq_utils.config.check_config(config_base: dict, config_local: dict)[source]
Compare two configuration dictionaries. Adding missing keys
- pymodaq_utils.config.copy_template_config(config_file_name: str = 'config', source_path: Path | str = None, dest_path: Path | str = None)[source]
Get a toml file path and copy it
the destination is made of a given folder path (or the system-wide local path by default) and the config_file_name appended by the suffix ‘.toml’
The source file (or pymodaq config template path by default) is read and dumped in this destination file
- pymodaq_utils.config.create_toml_from_dict(mydict: dict, dest_path: Path)[source]
Create a Toml file at a given path from a dictionnary
- pymodaq_utils.config.deep_update(mapping: Dict[KeyType, Any], *updating_mappings: Dict[KeyType, Any]) Dict[KeyType, Any][source]
Make sure a dictionary is updated using another dict in any nested level Taken from Pydantic v1
- pymodaq_utils.config.get_set_config_dir(config_name='config', user=False)[source]
Creates a folder in the local config directory to store specific configuration files
- Parameters:
- Return type:
Path
See also
- pymodaq_utils.config.get_set_local_dir(user=False) Path[source]
Defines, creates and returns a local folder where configuration files will be saved
Depending on the os the configurations files will be stored in CONFIG_BASE_PATH, then each user will have another one created that could override the default and system-wide base folder
- Parameters:
user (bool) – if False get the system-wide folder, otherwise the user folder
- Returns:
Path
- Return type:
the local path
- pymodaq_utils.config.get_set_log_path()[source]
creates and return the config folder path for log files
- pymodaq_utils.config.getitem_recursive(dic, *args, ndepth=0, create_if_missing=False)[source]
Will scan recursively a dictionary in order to get the item defined by the iterable args
- Parameters:
dic (dict) – the dictionary to scan
args (an iterable of str) – keys of the dict
ndepth (int) – by default (0) get the last element defined by args. 1 would mean it get the parent dict, 2 the parent of the parent…
create_if_missing (bool) – if the entry is not present, create it assigning the ‘none’ default value (as a lower case string)
- Return type:
- pymodaq_utils.config.load_system_config_and_update_from_user(config_file_name: str)[source]
load from a system-wide config file, update it from the user config file
- Parameters:
config_file_name (str) – The config file to be loaded
- Returns:
dict
- Return type:
contains the toml system-wide file update with the user file