lezargus.library.config module#

Controls the inputting of configuration files.

This also serves to bring all of the configuration parameters into a more accessible space which other parts of Lezargus can use.

Note these configuration constant parameters are all accessed using capital letters regardless of the configuration file’s labels. Because of this, the names must also obey a stricter set of Python variable naming conventions. Namely, capital letter names and only alphanumeric characters.

There are constant parameters which are stored here which are not otherwise changeable by the configuration file.

lezargus.library.config.apply_configuration(configuration: dict) None[source]#

Apply the configuration, input structured as a dictionary.

Note configuration files should be flat, there should be no nested configuration parameters.

Applied configuration values are stored as attached variables to this module. Applying the configurations to this module’s global namespace is the preferred method of applying the configuration. As these configurations will not change, they are constant like and thus can be accessed in a more Pythonic manner.

Parameters:

configuration (dict) – The configuration dictionary we are going to apply.

Return type:

None

lezargus.library.config.create_configuration_file(filename: str, overwrite: bool = False) None[source]#

Create a copy of the default configuration file to the given location.

Parameters:
  • filename (str) – The pathname or filename where the configuration file should be put to. If it does not have the proper yaml extension, it will be added.

  • overwrite (bool, default = False) – If the file already exists, overwrite it. If False, it would raise an error instead.

Return type:

None

lezargus.library.config.load_configuration_file(filename: str) None[source]#

Load a configuration file, then apply it.

Reads a configuration file, the applies it to the current configuration. Note configuration files should be flat, there should be no nested configuration parameters.

Parameters:

filename (str) – The filename of the configuration file, with the extension. Will raise if the filename is not the correct extension, just as a quick check.

Return type:

None

lezargus.library.config.read_configuration_file(filename: str) dict[source]#

Read the configuration file and output a dictionary of parameters.

Note configuration files should be flat, there should be no nested configuration parameters.

Parameters:

filename (str) – The filename of the configuration file, with the extension. Will raise if the filename is not the correct extension, just as a quick check.

Returns:

configuration – The dictionary which contains all of the configuration parameters within it.

Return type:

dict

lezargus.library.config.sanitize_configuration(configuration: dict) dict[source]#

Sanitize the configuration, conforming it to the Lezargus standards.

Sometimes configurations input by users do not exactly follow the expectations of Lezargus, so, here, we sanitize it as much as we can. Should some level of sanitation fail, then we inform the user.

Parameters:

configuration (dict) – The configuration we are going to sanitize.

Returns:

sanitized_configuration – The configuration, after sanitization.

Return type:

dict

lezargus.library.config.sanitize_configuration_key(key: str) str[source]#

Sanitize only the configuration key name.

The key sanitization makes sure that the key follows the below criteria:

  • The key contains only letters and single underscores as word demarcations.

  • The key is all uppercase and is unique across all variations of cases.

Parameters:

key (str) – The configuration key to sanitize.

Returns:

sanitized_key – The key, sanitized.

Return type:

str

lezargus.library.config.sanitize_configuration_value(value: object) int | float | str[source]#

Sanitize only the configuration value to a string.

Value sanitization ensures just three properties:

  • The value in question can be serialized to and from a numeric or string.

  • The value is not a dictionary.

  • The value string can fit on one line.

We need to require strings because that is the format yaml ensures.

Parameters:

value (str) – The configuration value to sanitize.

Returns:

sanitized_value – The value, sanitized.

Return type:

int, float, or str

lezargus.library.config.update_configuration_file(filename: str, configuration: dict | None = None, new_filename: str | None = None) None[source]#

Update a configuration file with new configuration parameters.

This function updates a configuration with the provided configuration parameters. This is a file manipulation function and does not affect the actual runtime configuration. This function is mostly used to update outdated configuration files with newer templates while keeping any changed configurations.

The configuration file is overwritten unless a new filename is provided.

Parameters:
  • filename (str) – The configuration file which we will update (either in place or with a copy). Configurations in the file are preserved unless overridden.

  • configuration (dict, default = None) – Lat minute overriding configurations to apply to the updated configuration file. Keynames must match for an override to occur. By default, no overriding configurations. If None, we assume no overriding configurations.

  • new_filename (str, default = None) – A new configuration filename to use if the original file is not to be overwritten.

Return type:

None

lezargus.library.config.write_configuration_file(filename: str, configuration: dict, overwrite: bool = False) None[source]#

Write a configuration file based on provided configurations.

Note configuration files should be flat, there should be no nested configuration parameters. Moreover, we only write configurations present as default or as overwritten by the provided configuration. This function does not account for current live configurations.

Parameters:
  • filename (str) – The filename of the configuration file to be saved, with the extension. Will raise if the filename is not the correct extension.

  • configuration (dict) – The configuration which we will save, along with any defaults present in the main configuration file.

  • overwrite (bool) – If True, we overwrite the configuration file if already present.

Return type:

None