|
243 | 243 | import com.oracle.graal.python.builtins.objects.type.TypeBuiltins;
|
244 | 244 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
|
245 | 245 | import com.oracle.graal.python.builtins.objects.zipimporter.ZipImporterBuiltins;
|
| 246 | +import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs; |
246 | 247 | import com.oracle.graal.python.nodes.BuiltinNames;
|
247 | 248 | import com.oracle.graal.python.nodes.call.GenericInvokeNode;
|
| 249 | +import com.oracle.graal.python.nodes.statement.AbstractImportNode; |
248 | 250 | import com.oracle.graal.python.runtime.PythonCodeSerializer;
|
249 | 251 | import com.oracle.graal.python.runtime.PythonContext;
|
250 | 252 | import com.oracle.graal.python.runtime.PythonOptions;
|
@@ -301,7 +303,9 @@ private static String[] initializeCoreFiles() {
|
301 | 303 | "base_exception",
|
302 | 304 | PythonCextBuiltins.PYTHON_CEXT,
|
303 | 305 | "_collections",
|
304 |
| - "_codecs", |
| 306 | + // TODO: see the encodings initialization before _codecs_truffle.py is |
| 307 | + // loaded in initializePython3Core; |
| 308 | + // once _codecs_truffle.py is gone, it should not be necessary |
305 | 309 | "_codecs_truffle",
|
306 | 310 | "bytes",
|
307 | 311 | "bytearray",
|
@@ -654,11 +658,26 @@ private void initializeJavaCore() {
|
654 | 658 | private void initializePython3Core(String coreHome) {
|
655 | 659 | loadFile(BuiltinNames.BUILTINS, coreHome);
|
656 | 660 | for (String s : coreFiles) {
|
| 661 | + // TODO: once _codecs_truffle.py is gone, this should not be necessary |
| 662 | + if (s.equals("_codecs_truffle")) { |
| 663 | + importEncoding(); |
| 664 | + } |
657 | 665 | loadFile(s, coreHome);
|
658 | 666 | }
|
659 | 667 | initialized = true;
|
660 | 668 | }
|
661 | 669 |
|
| 670 | + private void importEncoding() { |
| 671 | + PythonModule sys = lookupBuiltinModule("sys"); |
| 672 | + Object sysPath = sys.getAttribute("path"); |
| 673 | + PyObjectCallMethodObjArgs.getUncached().execute(null, sysPath, "insert", 0, getContext().getStdlibHome()); |
| 674 | + try { |
| 675 | + AbstractImportNode.importModule("encodings"); |
| 676 | + } finally { |
| 677 | + PyObjectCallMethodObjArgs.getUncached().execute(null, sysPath, "pop"); |
| 678 | + } |
| 679 | + } |
| 680 | + |
662 | 681 | /**
|
663 | 682 | * Run post-initialization code that needs a fully working Python environment. This will be run
|
664 | 683 | * eagerly when the context is initialized on the JVM or a new context is created on SVM, but is
|
|
0 commit comments