polaris.config.PolarisConfigParser
- class polaris.config.PolarisConfigParser(filepath=None)[source]
A “meta” config parser that keeps a dictionary of config parsers and their sources to combine when needed. The custom config parser allows provenance of the source of different config options and allows the “user” config options to always take precedence over other config options (even if they are added later).
This version simply overrides the
combine()method to also ensure that certain paths are absolute, rather than relative.- Variables:
filepath (str) – A filepath within the work directory where this config will be written out
tasks (set of polaris.Task) – A list of tasks that use this config
- __init__(filepath=None)[source]
Make a new (empty) config parser
- Parameters:
filepath (str, optional) – A filepath within the work directory where this config will be written out
Methods
__init__([filepath])Make a new (empty) config parser
add_from_file(filename)Add the contents of a config file to the parser.
add_from_package(package, config_filename[, ...])Add the contents of a config file to the parser.
add_section(section[, user])Add an empty section.
add_user_config(filename)Add a the contents of a user config file to the parser.
append(other)Append a deep copy of another config parser to this one.
combine([raw])Combine the config files into one
copy()Get a deep copy of the config parser
defaults()Get the options in the special
[DEFAULT]section.explain(section, option)Explain the provenance of an option.
get(section, option, **kwargs)Get an option value for a given section.
getboolean(section, option, **kwargs)Get an option boolean value for a given section.
getexpression(section, option[, dtype, ...])Get an option as an expression (typically a list, though tuples and dicts are also available).
getfloat(section, option, **kwargs)Get an option float value for a given section.
getint(section, option, **kwargs)Get an option integer value for a given section.
getlist(section, option[, dtype, fallback])Get an option value as a list for a given section.
getnumpy(section, option[, dtype, backend, ...])Shortcut for expressions requiring NumPy.
has_option(section, option)Whether the given section has the given option
has_section(section)Whether the given section is part of the config
items([section])Get section or option items from the combined config.
keys()Get the section names in the combined config (including
DEFAULT).list_files()Get a list of files contributing to the combined config options
options(section)Get the list of option names available in the given section.
prepend(other)Prepend a deep copy of another config parser to this one.
read_dict(dictionary[, source, user])Add config options read from a nested dictionary.
read_file(f[, source, user])Add config options read from an open file or iterable of lines.
read_string(string[, source, user])Add config options read from a string.
register_symbol(name, obj)Make 'name' available to the safe expression backend.
remove_option(section, option)Remove an option from a section across all layers.
remove_section(section)Remove a section and all of its options across all layers.
sections()Get the list of section names in the combined config.
set(section, option[, value, comment, user])Set the value of the given option in the given section. The file from
setup()A method that can be overridden to add config options during polaris setup
validate(validator)Call a user-provided validator function on the config as a nested dict.
values()Get a
tranche.section.Sectionwrapper for each section.write(fp[, include_sources, ...])Write the config options to the given file pointer.