1
# Copyright 2014 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Environment-related utilities."""
6
from __future__ import (
16
'environment_variables',
19
from contextlib import contextmanager
24
def environment_variables(variables):
25
"""Context manager: temporarily set the given environment variables.
27
The variables are reset to their original settings afterwards.
29
:param variables: A dict mapping environment variables to their temporary
32
prior_environ = os.environ.copy()
33
os.environ.update(variables)
38
os.environ.update(prior_environ)