From 801d4e9e7001389403f0d02ab508e98e3e1cd4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20J=C3=A4genstedt?= Date: Fri, 23 Apr 2021 17:10:50 +0200 Subject: [PATCH] Unset __PYVENV_LAUNCHER__ on macOS to avoid virtualenv weirdness Exactly how this all works isn't clear, but since the fix in https://github.com/python/cpython/pull/9516 was to simply hide the environment variable from the interpreter it seems reasonably safe. Fixes https://github.com/web-platform-tests/wpt/issues/27377. --- tools/wpt/virtualenv.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/wpt/virtualenv.py b/tools/wpt/virtualenv.py index 1cfb1506cfb4b9..b20a928880209a 100644 --- a/tools/wpt/virtualenv.py +++ b/tools/wpt/virtualenv.py @@ -91,6 +91,13 @@ def working_set(self): return self._working_set def activate(self): + if sys.platform == 'darwin': + # The default Python on macOS sets a __PYVENV_LAUNCHER__ environment + # variable which affects invocation of python (e.g. via pip) in a + # virtualenv. Unset it if present to avoid this. More background: + # https://github.com/web-platform-tests/wpt/issues/27377 + # https://github.com/python/cpython/pull/9516 + os.environ.pop('__PYVENV_LAUNCHER__', None) path = os.path.join(self.bin_path, "activate_this.py") with open(path) as f: exec(f.read(), {"__file__": path})