Skip to content

Commit 0f3476f

Browse files
committed
Set UNSAFE_PYO3_SKIP_VERSION_CHECK to work around pyo3 version check
1 parent f9c463c commit 0f3476f

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

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

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
package com.oracle.graal.python.builtins.modules;
2727

28+
import static com.oracle.graal.python.nodes.BuiltinNames.T_ENVIRON;
2829
import static com.oracle.graal.python.nodes.BuiltinNames.T_NT;
2930
import static com.oracle.graal.python.nodes.BuiltinNames.T_POSIX;
3031
import static com.oracle.graal.python.nodes.StringLiterals.T_DOT;
@@ -252,7 +253,7 @@ public void initialize(Python3Core core) {
252253
}
253254
PythonLanguage language = core.getLanguage();
254255
addBuiltinConstant("_have_functions", PFactory.createList(language, haveFunctions.toArray()));
255-
addBuiltinConstant("environ", PFactory.createDict(language));
256+
addBuiltinConstant(T_ENVIRON, PFactory.createDict(language));
256257

257258
LinkedHashMap<String, Object> sysconfigNames = new LinkedHashMap<>();
258259
for (IntConstant name : PosixConstants.sysconfigNames) {
@@ -313,16 +314,12 @@ public void postInitialize(Python3Core core) {
313314
// we don't want subprocesses to pick it up
314315
continue;
315316
}
316-
Object key, val;
317-
if (PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32) {
318-
if (entry.getKey().startsWith("=")) {
319-
// Hidden variable, shouldn't be visible to python
320-
continue;
321-
}
322-
key = toTruffleStringUncached(entry.getKey());
323-
} else {
324-
key = PFactory.createBytes(language, entry.getKey().getBytes());
317+
if (PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32 && entry.getKey().startsWith("=")) {
318+
// Hidden variable, shouldn't be visible to python
319+
continue;
325320
}
321+
Object key = toEnv(language, entry.getKey());
322+
Object val = toEnv(language, entry.getValue());
326323
if (pyenvLauncherKey.equals(entry.getKey())) {
327324
// On Mac, the CPython launcher uses this env variable to specify the real Python
328325
// executable. It will be honored by packages like "site". So, if it is set, we
@@ -334,31 +331,24 @@ public void postInitialize(Python3Core core) {
334331
posixLib.setenv(posixSupport, k, v, true);
335332
} catch (PosixException ignored) {
336333
}
337-
if (PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32) {
338-
val = value;
339-
} else {
340-
val = PFactory.createBytes(language, value.toJavaStringUncached().getBytes());
341-
}
342-
} else {
343-
if (PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32) {
344-
val = toTruffleStringUncached(entry.getValue());
345-
} else {
346-
val = PFactory.createBytes(language, (entry.getValue().getBytes()));
347-
}
334+
val = toEnv(language, value);
348335
}
349336
environ.setItem(key, val);
350337
}
351338
if (PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32) {
352339
// XXX: Until we fix pip
353-
environ.setItem(toTruffleStringUncached("PIP_NO_CACHE_DIR"), toTruffleStringUncached("0"));
340+
environ.setItem(toEnv(language, "PIP_NO_CACHE_DIR"), toEnv(language, "0"));
354341
}
342+
// XXX: Until a pyo3 version that doesn't have a different maximum version for GraalPy than
343+
// CPython gets widespread
344+
environ.setItem(toEnv(language, "UNSAFE_PYO3_SKIP_VERSION_CHECK"), toEnv(language, "1"));
355345
PythonModule posix;
356346
if (PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32) {
357347
posix = core.lookupBuiltinModule(T_NT);
358348
} else {
359349
posix = core.lookupBuiltinModule(T_POSIX);
360350
}
361-
Object environAttr = posix.getAttribute(tsLiteral("environ"));
351+
Object environAttr = posix.getAttribute(T_ENVIRON);
362352
((PDict) environAttr).setDictStorage(environ.getDictStorage());
363353

364354
if (posixLib.getBackend(posixSupport).toJavaStringUncached().equals("java")) {
@@ -370,6 +360,22 @@ public void postInitialize(Python3Core core) {
370360
}
371361
}
372362

363+
private static Object toEnv(PythonLanguage language, String value) {
364+
if (PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32) {
365+
return toTruffleStringUncached(value);
366+
} else {
367+
return PFactory.createBytes(language, value.getBytes());
368+
}
369+
}
370+
371+
private static Object toEnv(PythonLanguage language, TruffleString value) {
372+
if (PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32) {
373+
return value;
374+
} else {
375+
return PFactory.createBytes(language, value.toJavaStringUncached().getBytes());
376+
}
377+
}
378+
373379
@Builtin(name = "putenv", minNumOfPositionalArgs = 2, parameterNames = {"name", "value"})
374380
@ArgumentClinic(name = "name", conversionClass = FsConverterNode.class)
375381
@ArgumentClinic(name = "value", conversionClass = FsConverterNode.class)

0 commit comments

Comments
 (0)