Skip to content

Commit 28f22e6

Browse files
committed
Pop PIP_REQUIRE_VIRTUALENV from isolated environment
Fixes #90.
1 parent 10bf02e commit 28f22e6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/build/env.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ def _replace_env(self, key, new): # type: (str, Optional[str]) -> None
8686
self._env[key] = os.environ.get(key, None)
8787
os.environ[key] = new
8888

89+
def _pop_env(self, key): # type: (str) -> None
90+
self._env[key] = os.environ.pop(key, None)
91+
8992
def _restore_env(self): # type: () -> None
9093
for key, val in self._env.items():
9194
if val is None:
@@ -143,6 +146,7 @@ def __enter__(self): # type: () -> IsolatedEnvironment
143146
self._replace_env('PATH', os.pathsep.join(exe_path))
144147
self._replace_env('PYTHONPATH', os.pathsep.join(sys_path))
145148
self._replace_env('PYTHONHOME', self.path)
149+
self._pop_env('PIP_REQUIRE_VIRTUALENV')
146150

147151
self._symlink_relative(sysconfig.get_path('include'))
148152
self._symlink_relative(sysconfig.get_path('platinclude'))

tests/test_env.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import build.env
1111

1212

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

5555

56+
def test_isolated_environment_setup_require_virtualenv(mocker):
57+
mocker.patch.dict(os.environ, {"PIP_REQUIRE_VIRTUALENV": "true"})
58+
with build.env.IsolatedEnvironment.for_current():
59+
assert "PIP_REQUIRE_VIRTUALENV" not in os.environ
60+
assert os.environ["PIP_REQUIRE_VIRTUALENV"] == "true"
61+
62+
5663
def test_isolated_environment_install(mocker):
5764
with build.env.IsolatedEnvironment.for_current() as env:
5865
mocker.patch('subprocess.check_call')

0 commit comments

Comments
 (0)