easybuild.tools.environment module

Utility module for modifying os.environ

author:Toon Willems (Ghent University)
author:Ward Poelmans (Ghent University)
easybuild.tools.environment.get_changes()

Return tracked changes made in environment.

easybuild.tools.environment.modify_env(old, new, verbose=True)

Compares 2 os.environ dumps. Adapts final environment.

easybuild.tools.environment.read_environment(env_vars, strict=False)

Read variables from the environment :param env_vars: a dict with key a name, value a environment variable name :param strict: boolean, if True enforces that all specified environment variables are found

easybuild.tools.environment.reset_changes()

Reset the changes tracked by this module

easybuild.tools.environment.restore_env(env)

Restore active environment based on specified dictionary.

easybuild.tools.environment.restore_env_vars(env_keys)

Restore the environment by setting the keys in the env_keys dict again with their old value

easybuild.tools.environment.sanitize_env()

Sanitize environment.

This function undefines all $PYTHON* environment variables, since they may affect the build/install procedure of Python packages.

cfr. https://docs.python.org/2/using/cmdline.html#environment-variables

While the $PYTHON* environment variables may be relevant/required for EasyBuild itself, and for any non-stdlib Python packages it uses, they are irrelevant (and potentially harmful) when installing Python packages.

Note that this is not an airtight protection against the Python being used in the build/install procedure picking up non-stdlib Python packages (e.g., setuptools, vsc-base, ...), thanks to the magic of .pth files, cfr. https://docs.python.org/2/library/site.html .

easybuild.tools.environment.setvar(key, value, verbose=True)

put key in the environment with value tracks added keys until write_changes has been called

Parameters:verbose – include message in dry run output for defining this environment variable
easybuild.tools.environment.unset_env_vars(keys, verbose=True)

Unset the keys given in the environment Returns a dict with the old values of the unset keys

easybuild.tools.environment.write_changes(filename)

Write current changes to filename and reset environment afterwards