nip.utils.env.set_env_variables#
- nip.utils.env.set_env_variables(variables: dict, preserve_in_context_changes: bool = True)[source]#
Context manager to temporarily set environment variables.
This allows you to set environment variables for the duration of a block of code, and then restore the original values afterwards.
If an environment variable listed in
variables
is modified during the context, it will not be restored to its original value. This means that- Parameters:
variables (dict) – A dictionary of environment variable names and their values to set.
preserve_in_context_changes (bool, optional) – If True, any environment variable in
variables
that is modified during the context will not be restored to its original value. If False, all environment variables invariables
will be restored to their original values, even if they were modified during the context.