Aliases

class sofia_redux.scan.configuration.aliases.Aliases(allow_error=False, verbose=True)[source]

Bases: Options

Initialize the configuration aliases.

Aliases in the configuration are shorthand names for certain configuration keys such as ‘sky’ for ‘correlated.sky’ which may then be used to access values in the configuration appropriately. For example, using the above alias example, sky.gain would always point to correlated.sky.gain for any configuration operations.

Configuration values may also be aliased to other existing configuration values using the {?<key>} format. For example, if in the configuration foo={?bar}, then the value for bar would be retrieved when requesting foo.

Parameters:
allow_errorbool, optional

If True, allow poorly formatted options to be skipped rather than raising an error.

verbosebool, optional

If True, issues a warning when a poorly option is encountered.

Attributes Summary

substitute_pattern

Methods Summary

__call__(thing)

Unalias whatever value is passed into the alias.

copy()

Return a copy of the aliases.

resolve_configuration(configuration)

Resolve all configuration branch names.

unalias_branch(options)

Unalias a single options branch of the configuration.

unalias_branch_values(configuration, branch)

Unalias all values in an options branch.

unalias_dot_string(key)

Unalias all configuration paths in a given key.

unalias_value(configuration, value)

Unalias a value from the configuration.

update(configuration_options)

Update the stored aliases with those from another configuration.

Attributes Documentation

substitute_pattern = '(?<={\\?).*?(?=})'

Methods Documentation

__call__(thing)[source]

Unalias whatever value is passed into the alias.

Parameters:
thingstr or dict or ConfigObj

The object to unalias.

Returns:
dict or str or ConfigObj
copy()[source]

Return a copy of the aliases.

Returns:
Aliases
resolve_configuration(configuration)[source]

Resolve all configuration branch names.

All branches within the Configuration options are checked such that any aliased branch names will be replaced by the correct unaliased branch paths/names. This requires iteration due to the possibility of certain one alias referencing a branch that has not yet been unaliased, but will be.

Parameters:
configurationConfiguration
Returns:
None
unalias_branch(options)[source]

Unalias a single options branch of the configuration.

Returns a potentially multi-levelled dictionary for a given single levelled dictionary if the key is currently aliased. For example, if ‘sky’ was aliased to ‘correlated.sky’, then passing {‘sky’: {‘gainrange’: ‘0.3:3’}} into unalias_branch would return {‘correlated’: {‘sky’: {‘gainrange’: ‘0.3:3’}}}.

Parameters:
optionsConfigObj or dict

The options branch to unalias. Must be of length 1 (only contain a single key).

Returns:
unaliased_optionsdict
classmethod unalias_branch_values(configuration, branch, copy=True)[source]

Unalias all values in an options branch.

Parameters:
configurationConfiguration

The configuration used to unalias values.

branchdict or ConfigObj or str

Either a configuration options branch to unalias, or a single string value to unalias.

copybool, optional

If True, return a copy of the branch. Otherwise, the given branch will be updated in place.

Returns:
new_branchdict or ConfigObj or str

The updated branch.

unalias_dot_string(key)[source]

Unalias all configuration paths in a given key.

An alias is a name in the configuration used to represent another configuration keyword. For example, if correlated.sky was aliased to sky, then alias.unalias_dot_string(‘sky.mode’) would return ‘correlated.sky.mode’.

Parameters:
keystr
Returns:
str
classmethod unalias_value(configuration, value)[source]

Unalias a value from the configuration.

Aliased values in the configuration may be defined in the configuration by using {?key} in place of the value where key represents another configuration value. For example, if the configuration contains the option my_value = abc, passing {?my_value} into unalias_value would return abc.

Parameters:
configurationConfiguration

The configuration to examine when unaliasing the given value.

valuestr or object

Only string values will be unaliased. Anything else will be returned in the output.

Returns:
unaliased_valuestr
update(configuration_options)[source]

Update the stored aliases with those from another configuration.

Parameters:
configuration_optionsdict or ConfigObj

The configuration options to read and parse.

Returns:
None