sapling/eden/test_support/environment_variable.py
Xavier Deguillard a29d465ee8 fs: fix license header
Summary:
With Facebook having been renamed Meta Platforms, we need to change the license
headers.

Reviewed By: fanzeyi

Differential Revision: D33407812

fbshipit-source-id: b11bfbbf13a48873f0cea75f212cc7b07a68fb2e
2022-01-04 15:00:07 -08:00

34 lines
861 B
Python

#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.
import abc
import contextlib
import os
from typing import Any, Callable, Generator, Mapping, Optional
def _setenv(name: str, value: Optional[str]) -> None:
if value is None:
os.environ.pop(name, None)
else:
os.environ[name] = value
@contextlib.contextmanager
def setenv_scope(name: str, value: Optional[str]) -> Generator[None, None, None]:
old_value = os.environ.get(name)
_setenv(name, value)
yield
_setenv(name, old_value)
@contextlib.contextmanager
def unsetenv_scope(name: str) -> Generator[None, None, None]:
old_value = os.environ.get(name)
os.environ.pop(name, None)
yield
_setenv(name, old_value)