Settings¶
- class libpermian.settings.Settings(cmdline_overrides, environment, settings_locations, default_settings_location='/home/docs/checkouts/readthedocs.org/user_builds/permian/checkouts/latest/libpermian/default.ini')¶
Priority aware container for configuration options. The settings may be defined in following places (sorted in priority order):
# cmdline argument # environment variable # ini file in cloned library # ini files in known locations (locations can be changed/added by cmdline argument or environment variable) # default ini files of plugins # default ini file of pipeline (located in libpermian directory)
The locations overrides are not considered to be settings and are treated separately.
- Parameters:
cmdline_overrides –
environment –
settings_locations (list) –
default_settings_location (str) –
- get(sections, option)¶
Get value of option in one of provided sections taking in account priority order of settings sources.
- Parameters:
sections (str or iterable) – Names of the sections that are tried in given order. It’s possible to also provide just one name.
option (str) – name of the option
- Returns:
value of option in section
- Return type:
str
- getboolean(sections, option)¶
Get value of option in one of sections using self.get and convert it into a boolean
- Parameters:
section (str) – Names of the sections that are tried in given order. It’s possible to also provide just one name.
option (str) – name of the option
- Returns:
value of option in section
- Return type:
bool
- getfloat(sections, option)¶
Get value of option in one of sections using self.get and convert it into a float
- Parameters:
section (str) – Names of the sections that are tried in given order. It’s possible to also provide just one name.
option (str) – name of the option
- Returns:
value of option in section
- Return type:
float
- getint(sections, option)¶
Get value of option in one of sections using self.get and convert it into a int
- Parameters:
section (str) – Names of the sections that are tried in given order. It’s possible to also provide just one name.
option (str) – name of the option
- Returns:
value of option in section
- Return type:
bool
- load_from_library(library_path, pattern='*.ini')¶
Locate all settings files in library and load them. The settings files are recognized by pattern and can be present in any subdirectory of library_path.
- Parameters:
library_path (str) – Path where library is located
pattern (str) – Glob pattern of files which will be considered as library settings files.
- options(sections)¶
Provides all known options of the section from all settings files/overrides. The option may be defined in any of those sources to be provided by this method.
- Parameters:
section –
- Returns:
options in sections
- Return type:
set
- overrides_from_env(env, pattern_fmt='PIPELINE_(?P<section>[^_]+)_(?P<option>.+)')¶
Finds all variables in env mathing the pattern_fmt pattern and converts them into a dict for ConfigParser.read_dict.
- Parameters:
env (dict) – environment variables
pattern_fmt (regexp, optional) – pattern for the variable name, must contain groups section and option, defaults to r’PIPELINE_(?P<section>[^_]+)_(?P<option>.+)’
- Returns:
settings found in env
- Return type:
dict
- sections()¶
Provides all known sections from all settings files/overrides. The section may be defined in any of those sources to be provided by this method.
- Returns:
known section
- Return type:
set
- sectionsView(sections)¶
- class libpermian.settings.SettingsSectionsView(settings, sections)¶
View on multiple sections of settings.