class pecans.utilities.config.BetterConfig(*args, **kwargs)[source]

Extension of configparser.RawConfigParser customized for use with PECANS

This class adds a section_as_dict() method that allows you to quickly return a section of the parser as a dictionary. It also overrides the configparser.RawConfigParser.read() method to parse input values from strings into Python types using the function set as the attribute valuexform.

read(filenames, encoding=None)[source]

Read one or more configuration files and stores their values internally :param filenames: the file or files to read :type filenames: str or list :param encoding: any encoding recognized by open() :return: the list of files successfully read

section_as_dict(section)[source]

Return the requested section’s options as a dictionary :param section: the section name :type section: str

Returns:

the dictionary representation of the section

Return type:

dict

exception pecans.utilities.config.ConfigurationError[source]

An error that represents something wrong in the PECANS configuration.

This should be raised specifically if there is something wrong with what the user has given in the config file.

pecans.utilities.config.get_domain_size_from_config(config, all_dims=False)[source]

Helper function that reads the domain size (as a tuple) from a configuration object.

Parameters:
  • config (BetterConfig) – the configuration object to read the domain size from.

  • all_dims (bool) – whether to include just non-zero dimensions (False, default) or all dimensions (True)

Returns:

the shape of the domain, as a tuple with 1, 2, or 3 elements depending if the domain is 1-, 2-, or 3- D.

Return type:

tuple of int

pecans.utilities.config.load_config_file(config_file)[source]

Reads a configuration file and returns a BetterConfig instance representing it

This function automatically instantiates a BetterConfig instance, sets it to parse values into Python literals (including tuples or dicts) :param config_file: the file to read. :type config_file: str or list :return: the BetterConfig object