wiz.environ

wiz.environ.ENV_PATTERN = re.compile('\\${(\\w+)}|\\$(\\w+)')

Compiled regular expression to identify environment variables in string.

wiz.environ.initiate(mapping=None)[source]

Return the minimal environment mapping to augment.

Parameters:mapping – Custom environment mapping which will be added to the initial environment. Default is None.
wiz.environ.sanitize(mapping)[source]

Return sanitized environment mapping.

Resolve all key references within mapping values and remove all self-references:

>>> sanitize({
...     "PLUGIN": "${HOME}/.app:/path/to/somewhere:${PLUGIN}",
...     "HOME": "/usr/people/me"
... })

{
    "HOME": "/usr/people/me",
    "PLUGIN": "/usr/people/me/.app:/path/to/somewhere"
}
Parameters:mapping – Environment mapping to sanitize.
Returns:Sanitized environment mapping.
wiz.environ.contains(text, name)[source]

Indicate whether text contains a reference to variable name.

Example:

>>> contains("${HOME}/path/to/data", "HOME")

True
Parameters:
  • text – String which can contain environment variable (e.g. “${PATH}/to/somewhere”).
  • name – Name of an environment variable (e.g. “PATH”).
Returns:

Boolean value.

wiz.environ.substitute(text, environment)[source]

Substitute all environment variables in text from environment.

Example:

>>> substitute("${HOME}/path/to/data", {"HOME": "/usr/people/john-doe"})

/usr/people/john-doe/path/to/data
Parameters:
  • text – String which can contain environment variable (e.g. “${PATH}/to/somewhere”).
  • environment – Mapping of environment variables with their respective values.
Returns:

Resolved text string.