Skip to content

Commit 4053f05

Browse files
authored
Prevent sys.prefix from leaking into child process on macOS (#1648)
1 parent f9fbd94 commit 4053f05

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

docs/changelog/1643.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix cross interpreter support when the host python sets ``sys.base_executable`` based on ``__PYVENV_LAUNCHER__`` -
2+
by :user:`cjolowicz`

src/virtualenv/discovery/cached_py_info.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,21 @@ def _get_fs_path():
101101
def _run_subprocess(cls, exe):
102102
resolved_path = Path(os.path.abspath(__file__)).parent / "py_info.py"
103103
with ensure_file_on_disk(resolved_path) as resolved_path:
104+
104105
cmd = [exe, "-s", str(resolved_path)]
106+
# prevent sys.prefix from leaking into the child process - see https://bugs.python.org/issue22490
107+
env = os.environ.copy()
108+
env.pop("__PYVENV_LAUNCHER__", None)
105109

106110
logging.debug("get interpreter info via cmd: %s", LogCmd(cmd))
107111
try:
108112
process = Popen(
109-
cmd, universal_newlines=True, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE
113+
cmd,
114+
universal_newlines=True,
115+
stdin=subprocess.PIPE,
116+
stderr=subprocess.PIPE,
117+
stdout=subprocess.PIPE,
118+
env=env,
110119
)
111120
out, err = process.communicate()
112121
code = process.returncode

0 commit comments

Comments
 (0)