Skip to content

Commit

Permalink
env: pop PIP_REQUIRE_VIRTUALENV from isolated environment
Browse files Browse the repository at this point in the history
Fixes pypa#90.
  • Loading branch information
adamchainz committed Sep 11, 2020
1 parent 3d2491f commit b805ff7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/build/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def _replace_env(self, key, new): # type: (str, Optional[str]) -> None
self._env[key] = os.environ.get(key, None)
os.environ[key] = new

def _pop_env(self, key): # type: (str) -> None
self._env[key] = os.environ.pop(key, None)

def _restore_env(self): # type: () -> None
for key, val in self._env.items():
if val is None:
Expand Down Expand Up @@ -141,6 +144,7 @@ def __enter__(self): # type: () -> IsolatedEnvironment
self._replace_env('PATH', os.pathsep.join(exe_path))
self._replace_env('PYTHONPATH', os.pathsep.join(sys_path))
self._replace_env('PYTHONHOME', self.path)
self._pop_env('PIP_REQUIRE_VIRTUALENV')

self._symlink_relative(sysconfig.get_path('include'))
self._symlink_relative(sysconfig.get_path('platinclude'))
Expand Down
9 changes: 8 additions & 1 deletion tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import build.env


def test_isolated_environment_setup(mocker):
def test_isolated_environment_setup():
old_path = os.environ['PATH']
with build.env.IsolatedEnvironment.for_current() as env:
if os.name != 'nt':
Expand Down Expand Up @@ -53,6 +53,13 @@ def test_isolated_environment_setup(mocker):
assert os.path.exists(path)


def test_isolated_environment_setup_require_virtualenv(mocker):
mocker.patch.dict(os.environ, {"PIP_REQUIRE_VIRTUALENV": "true"})
with build.env.IsolatedEnvironment.for_current():
assert "PIP_REQUIRE_VIRTUALENV" not in os.environ
assert os.environ["PIP_REQUIRE_VIRTUALENV"] == "true"


def test_isolated_environment_install(mocker):
with build.env.IsolatedEnvironment.for_current() as env:
mocker.patch('subprocess.check_call')
Expand Down

0 comments on commit b805ff7

Please sign in to comment.