easybuild.tools.environment module

Utility module for modifying os.environ

author:Toon Willems (Ghent University)
author:Ward Poelmans (Ghent University)

Return tracked changes made in environment.

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

Compares two 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


Reset the changes tracked by this module


Restore active environment based on specified dictionary.


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


Sanitize environment.

This function:

  • Filters out empty entries from environment variables like $PATH, $LD_LIBRARY_PATH, etc. Empty entries make no sense, and can cause problems, see for example https://github.com/easybuilders/easybuild-easyconfigs/issues/9843 .

  • 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


Write current changes to filename and reset environment afterwards