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)
| 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): |