MCPcopy
hub / github.com/pex-tool/pex / patch

Method patch

pex/variables.py:365–390  ·  view source on GitHub ↗

Update the environment for the duration of a context. Any environment variable with a value of `None` will be removed from the environment if present. The rest will be added to the environment or else updated if already present in the environment.

(self, **kw)

Source from the content-addressed store, hash-verified

363
364 @contextmanager
365 def patch(self, **kw):
366 # type: (**Optional[str]) -> Iterator[Dict[str, str]]
367 """Update the environment for the duration of a context.
368
369 Any environment variable with a value of `None` will be removed from the environment if
370 present. The rest will be added to the environment or else updated if already present in
371 the environment.
372 """
373 disable_env = self._maybe_get_bool_var("PEX_DISABLE_VARIABLES", kw)
374
375 old_environ = self._environ
376 self._environ = self._environ.copy()
377 if disable_env:
378 for k in list(self._environ):
379 if k != "PEX_DISABLE_VARIABLES" and k.startswith("PEX_"):
380 self._environ.pop(k)
381 for k, v in kw.items():
382 if v is None:
383 self._environ.pop(k, None)
384 elif disable_env and k != "PEX_DISABLE_VARIABLES" and k.startswith("PEX_"):
385 self._environ.pop(k, None)
386 else:
387 self._environ[k] = v
388
389 yield self._environ
390 self._environ = old_environ
391
392 @defaulted_property(default=False)
393 def PEX_DISABLE_VARIABLES(self):

Callers 15

test_disable_patchFunction · 0.95
test_patchFunction · 0.95
ensure_venvFunction · 0.45
bootstrap_pexFunction · 0.45
_ensure_installedFunction · 0.45
create_pipFunction · 0.45
test_use_pip_configFunction · 0.45
test_keyring_providerFunction · 0.45
temporary_pex_rootFunction · 0.45

Calls 3

_maybe_get_bool_varMethod · 0.95
copyMethod · 0.45
popMethod · 0.45

Tested by 15

test_disable_patchFunction · 0.76
test_patchFunction · 0.76
create_pipFunction · 0.36
test_use_pip_configFunction · 0.36
test_keyring_providerFunction · 0.36
temporary_pex_rootFunction · 0.36
test_deterministic_walkFunction · 0.36
cacheFunction · 0.36
test_pp_invalidFunction · 0.36