Skip to content

Commit

Permalink
fix: retain os.environ obj in utils.sandboxed_env
Browse files Browse the repository at this point in the history
Previously bioconda_utils.utils.sandboxed_env assigned os.environ with a
newly created dict and did not restore it to the original os.environ
object -- breaking pytest.monkeypatch.setenv (and my sanity...).

Signed-off-by: Marcel Bargull <[email protected]>
  • Loading branch information
mbargull committed May 8, 2024
1 parent 44731d5 commit cec8a0f
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions bioconda_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,19 +408,18 @@ def sandboxed_env(env):
the existing `os.environ` or the provided **env** that match
ENV_VAR_WHITELIST globs.
"""
os_environ = os.environ
orig = os_environ.copy()
env = dict(env)
orig = os.environ.copy()

_env = {k: v for k, v in orig.items() if allowed_env_var(k)}
_env.update({k: str(v) for k, v in env.items() if allowed_env_var(k)})

os.environ = _env

try:
os_environ.clear()
os_environ.update({k: v for k, v in orig.items() if allowed_env_var(k)})
os_environ.update({k: str(v) for k, v in env.items() if allowed_env_var(k)})
yield
finally:
os.environ.clear()
os.environ.update(orig)
os_environ.clear()
os_environ.update(orig)


def load_all_meta(recipe, config=None, finalize=True):
Expand Down

0 comments on commit cec8a0f

Please sign in to comment.