2.1.1.1. wc_utils.config package¶
2.1.1.1.1. Submodules¶
2.1.1.1.2. wc_utils.config.core module¶
Read configuration settings from files, environment variables, and function arguments
- Author
Jonathan Karr <karr@mssm.edu>
- Author
Arthur Goldberg <Arthur.Goldberg@mssm.edu>
- Date
2016-10-25
- Copyright
2016-2018, Karr Lab
- License
MIT
-
class
wc_utils.config.core.
AltResourceName
(file_in_package)[source]¶ Bases:
object
Get pathname of resource file; a substitute for pkg_resources.resource_filename
Finds paths to resource files in a package that cannot be imported by the standard Python import system.
Usage:
`pkg_resources.resource_filename(package, *path_components_of_resource_in_package)
`AltResourceName(any_file_in_package).resource_filename(*path_components_of_resource_in_package)
-
static
get_package_root
(file_in_package)[source]¶ Obtain root directory of a package by following __init__.py files up the file hierarchy
- Parameters
file_in_package (
str
) – pathname of a file in a package- Returns
pathname of root of package
- Return type
str
- Raises
ValueError – if file_in_package is not the pathname of a file in a package
-
class
wc_utils.config.core.
ConfigManager
(paths=None)[source]¶ Bases:
object
Obtain configuration information from ini files, environment variables, and/or function arguments.
Load configuration information from an ini format file, environment variables, and/or function arguments. Validate the configuration against a configuration schema. Return the configuration as a nested dictionary.
Optionally, configuration values can be templates for substitution with
string.Template
.-
get_config
(extra=None, context=None)[source]¶ Setup configuration from config file(s), environment variables, and/or function arguments.
Setup configuration from default values specified in paths.default.
If paths.user is set, find the first file in it that exists, and override the default configuration with the values specified in the file.
Override configuration with values from environment variables. Environment variables can be set with the following syntax:
CONFIG.level1.level2...=val
Override configuration with additional configuration in extra.
Substitute context into templates
Validate configuration against the schema specified in paths.schema.
- Parameters
extra (
dict
, optional) – additional configuration to overridecontext (
dict
, optional) – context for template substitution
- Returns
nested dictionary with the configuration settings loaded from the configuration source(s).
- Return type
configobj.ConfigObj
- Raises
InvalidConfigError – if configuration doesn’t validate against schema
ValueError – if no configuration is found
-
validate
(config, value_sources)[source]¶ Validate configuration
- Parameters
config (
ConfigObj
) – configuration- Raises
InvalidConfigError – if configuration doesn’t validate against schema
ValueError – if no configuration is found
-
-
class
wc_utils.config.core.
ConfigPaths
(default=None, schema=None, user=None)[source]¶ Bases:
object
Paths to configuration files and schema
-
exception
wc_utils.config.core.
ExtraValuesError
(sources, config)[source]¶ Bases:
Exception
Represents an error due to extra configuration that is not part of the schema
-
exception
wc_utils.config.core.
InvalidConfigError
(sources, config, result)[source]¶ Bases:
Exception
Represents an error due to reading an invalid configuration that doesn’t adhere to the schema
-
wc_utils.config.core.
any_checker
(value)[source]¶ Convert value to its built-in data type if possible
Convert a string value to its built-in data type (integer, float, boolean, str or list of these) if possible
- Parameters
value (
object
) – a value to be converted- Returns
the converted value
- Return type
type
- Raises
VdtTypeError – if the value cannot be converted