Skip to content

Commit 83a2ec1

Browse files
committed
Overwrite env var "__PYVENV_LAUNCHER__" if specified.
1 parent 53baa0e commit 83a2ec1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2018, 2020, Oracle and/or its affiliates.
33
* Copyright (c) 2014, Regents of the University of California
44
*
55
* All rights reserved.
@@ -287,9 +287,17 @@ public void postInitialize(PythonCore core) {
287287
Map<String, String> getenv = System.getenv();
288288
PDict environ = core.factory().createDict();
289289
for (Entry<String, String> entry : getenv.entrySet()) {
290-
environ.setItem(core.factory().createBytes(entry.getKey().getBytes()), core.factory().createBytes(entry.getValue().getBytes()));
290+
String value;
291+
if ("__PYVENV_LAUNCHER__".equals(entry.getKey())) {
292+
// On Mac, the CPython launcher uses this env variable to specify the real Python
293+
// executable. It will be honored by packages like "site". So, if it is set, we
294+
// overwrite it with our executable to ensure that subprocesses will use us.
295+
value = PythonOptions.getOption(core.getContext(), PythonOptions.Executable);
296+
} else {
297+
value = entry.getValue();
298+
}
299+
environ.setItem(core.factory().createBytes(entry.getKey().getBytes()), core.factory().createBytes(value.getBytes()));
291300
}
292-
293301
PythonModule posix = core.lookupBuiltinModule("posix");
294302
Object environAttr = posix.getAttribute("environ");
295303
((PDict) environAttr).setDictStorage(environ.getDictStorage());

0 commit comments

Comments
 (0)