allensdk.config.app.application_config module¶
-
class
allensdk.config.app.application_config.
ApplicationConfig
(defaults, name='app', halp='Run application.', default_log_config=None)[source]¶ Bases:
object
Convenience class that handles of application configuration from environment variables, .conf files and the command line using Python standard libraries and formats.
-
apply_configuration_from_command_line
(parsed_args)[source]¶ Read application configuration variables from the command line.
Unassigned variables are left unchanged if previously assigned, set to their default values, or None if no default is specified at init time. Assigned variables will overwrite the previous value.
see: https://docs.python.org/2/howto/argparse.html
Parameters: - parsed_args : dict
the arguments as parsed from the command line.
-
apply_configuration_from_environment
()[source]¶ Read application configuration variables from the environment.
The variable names are upper case and have a prefix defined by the application.
-
apply_configuration_from_file
(config_file_path)[source]¶ Read application configuration variables from a .conf file.
Unassigned variables are set to their default values or None if no default is specified at init time. The variables are found in a section named by the application.
Parameters: - config_file_path : string
path to to an INI (.conf) or JSON format application config file.
Returns: - see: https://docs.python.org/2/library/configparser.html
-
create_argparser
()[source]¶ Initialization for the command-line parsing stage.
An application specific prefix is applied to argument names.
Parameters: - prog : string
Application specific prefix for argument names.
- description : string
A brief ‘help’ description of the application.
Returns: - argParse.ArgumentParser
The initialized argument parser object.
Notes
Defaults are set at the first environment reading. Command line args only override them when present
-
from_json_file
(json_path)[source]¶ Read an application configuration from a JSON format file.
Parameters: - json_path : string
Path to the JSON file.
Returns: - string
An application configuration in INI format
-
from_json_string
(json_string)[source]¶ Read a configuration from a JSON format string.
Parameters: - json_string : string
A JSON-formatted string containing an application configuration.
Returns: - string
An application configuration in INI format
-
load
(command_line_args, disable_existing_loggers=True)[source]¶ Load application configuration options, first from the environment, then from the configuration file, then from the command line.
Each stage of loading can override the previous stage.
Parameters: - command_line_args : dict
Parameters passed to the application.
- disable_existing_loggers : boolean
Reset the logging system or not.
Returns: - fileConfig
Configuration object with all levels applied
-
parse_command_line_args
(args)[source]¶ Simply call the internal argparser object.
Parameters: - args : array
Parameters passed to the application.
Returns: - Namespace
Parsed paramenters.
-
to_config_string
(description)[source]¶ Create a configuration string from a dict.
Parameters: - description : dict
Configuration options for an application.
Returns: - string
Equivalent configuration as an INI format string
Notes
The Python configparser library natively supports this functionality in Python 3.
-