reproman.config

Registry-like monster for now simply borrowed from bigmess/pymvpa

TODO: integration with cmdline etc

class reproman.config.ConfigManager(filenames=None, load_default=True)[source]

Bases: reproman.support.configparserinc.SafeConfigParserWithIncludes, object

Central configuration registry for reproman.

The purpose of this class is to collect all configurable settings used by various parts of reproman. It is fairly simple and does only little more than the standard Python ConfigParser. Like ConfigParser it is blind to the data that it stores, i.e. no type checking is performed.

Configuration files (INI syntax) in multiple location are parsed when a class instance is created or whenever Config.reload() is called later on. Files are read and parsed in the order described by LOCATIONS_DOC.

Moreover, the constructor takes an optional argument with a list of additional file names to parse afterwards.

In addition to configuration files, this class also looks for special environment variables to read settings from. Names of such variables have to start with REPROMAN_ following by the an optional section name and the variable name itself (‘_’ as delimiter). If no section name is provided, the variables will be associated with section general. Some examples:

REPROMAN_VERBOSE=1

will become:

[general]
verbose = 1

However, REPROMAN_VERBOSE_OUTPUT=stdout becomes:

[verbose]
output = stdout

Any length of variable name as allowed, e.g. REPROMAN_SEC1_LONG_NAME=1 becomes:

[sec1]
long name = 1

Settings from custom configuration files (specified by the constructor argument) have the highest priority and override settings found in any of the config files read from default locations (which are themselves read in the order stated above – overwriting earlier configuration settings accordingly). Finally, the content of any REPROMAN_* environment variables overrides any settings read from any file.

dirs = <appdirs.AppDirs object>
get(section, option, default=None, **kwargs)[source]

Wrapper around SafeConfigParser.get() with a custom default value.

This method simply wraps the base class method, but adds a default keyword argument. The value of default is returned whenever the config parser does not have the requested option and/or section.

get_as_dtype(section, option, dtype, default=None)[source]

Convenience method to query options with a custom default and type

This method simply wraps the base class method, but adds a default keyword argument. The value of default is returned whenever the config parser does not have the requested option and/or section.

In addition, the returned value is converted into the specified dtype.

getboolean(section, option, default=None)[source]

Wrapper around SafeConfigParser.getboolean() with a custom default.

This method simply wraps the base class method, but adds a default keyword argument. The value of default is returned whenever the config parser does not have the requested option and/or section.

getpath(*args, **kwargs)[source]

Wrapper around get to do additional path treatments such as expanduser

See documentation for get

reload(filenames=None)[source]

Re-read settings from all configured locations.