8.4.5. pymodaq_utils.config module

exception pymodaq_utils.config.ConfigError[source]

Bases: Exception

class pymodaq_utils.config.BaseConfig(*args, **kwargs)[source]

Bases: object

Base class to manage configuration files

Should be subclassed with proper class attributes for each configuration file you need with pymodaq

config_name

The name with which the configuration will be saved

Type:

str

config_template_path

The Path of the template from which the config is constructed

Type:

Path

Attributes:
config_path

Get the user config path

system_config_path

Get the system_wide config path

Methods

__call__(*args)

dict_to_add_to_user()

To subclass

get_children(*path)

Get the list of config entries at a given path within the configuration toml file

load()

Load a configuration file from both system-wide and user file check also if missing entries in the configuration file compared to the template

save()

Save the current Config object into the user toml file and reload it

to_xml_string()

Convert this object to a xml string representing it as a Parameter Tree

get

to_dict

dict_to_add_to_user()[source]

To subclass

get(key, default=None)[source]
get_children(*path)[source]

Get the list of config entries at a given path within the configuration toml file

new in 4.3.0

load()[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

save()[source]

Save the current Config object into the user toml file and reload it

to_dict()[source]
to_xml_string()[source]

Convert this object to a xml string representing it as a Parameter Tree

pymodaq_gui is necessary for this purpose

Return type:

bytes

config_name: str = NotImplemented
property config_path

Get the user config path

config_template_path: Path = NotImplemented
property system_config_path

Get the system_wide config path

class pymodaq_utils.config.CacheConfig(*args, **kwargs)[source]

Bases: BaseConfig

class pymodaq_utils.config.Config(*args, **kwargs)[source]

Bases: BaseConfig

Main class to deal with configuration values for PyMoDAQ

Methods

__call__(*args)

dict_to_add_to_user()

To subclass

dict_to_add_to_user()[source]

To subclass

config_name: str = 'utils'
config_template_path: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pymodaq/checkouts/dev/packages/pymodaq_utils/src/pymodaq_utils/resources/config_template.toml')
class pymodaq_utils.config.ConfigSingleton[source]

Bases: Singleton

Methods

__call__(*args, **kwargs)

class pymodaq_utils.config.GlobalConfig(*args, **kwargs)[source]

Bases: object

Attributes:
config_path

Get the user config path

system_config_path

Get the system_wide config path

Methods

__call__(*args)

register()

To be used as a decorator

add_config

get

save

to_dict

classmethod register()[source]

To be used as a decorator

Register in the config registry a new config class using its name

Return type:

Callable

add_config(name, config)[source]
get(key, default=None)[source]
save()[source]
to_dict()[source]
config_name: str = 'global'
property config_path

Get the user config path

property system_config_path

Get the system_wide config path

pymodaq_utils.config.check_config(config_base, config_local)[source]

Compare two configuration dictionaries. Adding missing keys

Parameters:
  • config_base (dict) – The base dictionaries with possible new keys

  • config_local (dict) – a dict from a local config file potentially missing keys

Returns:

bool

Return type:

True if keys where missing else False

pymodaq_utils.config.copy_template_config(config_file_name='config', source_path=None, dest_path=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

Parameters:
  • config_file_name (str) – the name of the destination config file

  • source_path (Union[Path, str]) – the path of the toml source to be copied

  • dest_path (Union[Path, str]) – the destination path of the copied config

Returns:

Path

Return type:

the path of the copied file

pymodaq_utils.config.create_toml_from_dict(mydict, dest_path)[source]

Create a Toml file at a given path from a dictionnary

pymodaq_utils.config.deep_update(mapping, *updating_mappings)[source]

Make sure a dictionary is updated using another dict in any nested level Taken from Pydantic v1

Return type:

Dict[TypeVar(KeyType), Any]

pymodaq_utils.config.get_config_file(config_file_name, user=False)[source]
Return type:

Path

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:
  • config_name ((str) name of the configuration folder)

  • user (bool) – if False get the system-wide folder, otherwise the user folder

Return type:

Path

pymodaq_utils.config.get_set_local_dir(user=False)[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:

Path

pymodaq_utils.config.get_set_log_path()[source]

creates and return the config folder path for log files

pymodaq_utils.config.get_set_path(a_base_path, dir_name)[source]
Return type:

Path

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:

object or dict

pymodaq_utils.config.load_system_config_and_update_from_user(config_file_name)[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

pymodaq_utils.config.recursive_iterable_flattening(aniterable)[source]
pymodaq_utils.config.replace_file_extension(filename, ext)[source]

Replace the extension of a file by the specified one, without the dot

pymodaq_utils.config.replace_item_in_list(items, old, new)[source]