@@ -842,9 +842,12 @@ private void initializeJavaCore() {
842
842
builtinsModule = builtinModules .get (BuiltinNames .BUILTINS );
843
843
}
844
844
845
+ private static final String IMPORTLIB_NAME = "_frozen_importlib" ;
846
+ private static final String IMPORTLIB_EXTERNAL_NAME = "_frozen_importlib_external" ;
847
+
845
848
private void initializeImportlib () {
846
- String importlibName = "_frozen_importlib" ;
847
- PythonModule bootstrap = ImpModuleBuiltins . importFrozenModuleObject ( this , importlibName , false ) ;
849
+ PythonModule bootstrap = ImpModuleBuiltins . importFrozenModuleObject ( this , IMPORTLIB_NAME , false ) ;
850
+ PythonModule bootstrapExternal ;
848
851
849
852
PyObjectCallMethodObjArgs callNode = PyObjectCallMethodObjArgs .getUncached ();
850
853
WriteAttributeToDynamicObjectNode writeNode = WriteAttributeToDynamicObjectNode .getUncached ();
@@ -856,18 +859,21 @@ private void initializeImportlib() {
856
859
857
860
if (bootstrap == null ) {
858
861
// true when the frozen module is not available
859
- PythonModule bootstrapExternal = createModule ("importlib._bootstrap_external" );
860
- writeNode .execute (bootstrapExternal , __PACKAGE__ , "importlib" );
861
- setItem .execute (null , sysModules , "_frozen_importlib_external" , bootstrapExternal );
862
+ bootstrapExternal = createModule ("importlib._bootstrap_external" );
862
863
bootstrap = createModule ("importlib._bootstrap" );
863
- writeNode .execute (bootstrap , __PACKAGE__ , "importlib" );
864
- setItem .execute (null , sysModules , importlibName , bootstrap );
865
864
loadFile ("importlib/_bootstrap_external" , getContext ().getStdlibHome (), bootstrapExternal );
866
865
loadFile ("importlib/_bootstrap" , getContext ().getStdlibHome (), bootstrap );
867
866
} else {
868
- setItem .execute (null , sysModules , importlibName , bootstrap );
869
- LOGGER .log (Level .FINE , () -> "import '_frozen_importlib' # <frozen>" );
867
+ bootstrapExternal = ImpModuleBuiltins .importFrozenModuleObject (this , IMPORTLIB_EXTERNAL_NAME , true );
868
+ LOGGER .log (Level .FINE , () -> "import '" + IMPORTLIB_NAME + "' # <frozen>" );
869
+ LOGGER .log (Level .FINE , () -> "import '" + IMPORTLIB_EXTERNAL_NAME + "' # <frozen>" );
870
870
}
871
+ setItem .execute (null , sysModules , IMPORTLIB_NAME , bootstrap );
872
+ setItem .execute (null , sysModules , IMPORTLIB_EXTERNAL_NAME , bootstrapExternal );
873
+
874
+ // __package__ needs to be set and doesn't get set by _bootstrap setup
875
+ writeNode .execute (bootstrap , __PACKAGE__ , "importlib" );
876
+ writeNode .execute (bootstrapExternal , __PACKAGE__ , "importlib" );
871
877
872
878
callNode .execute (null , bootstrap , "_install" , getSysModule (), lookupBuiltinModule ("_imp" ));
873
879
writeNode .execute (getBuiltins (), "__import__" , readNode .execute (bootstrap , "__import__" ));
@@ -878,12 +884,6 @@ private void initializeImportlib() {
878
884
PythonBuiltinClass moduleType = lookupType (PythonBuiltinClassType .PythonModule );
879
885
writeNode .execute (moduleType , __REPR__ , readNode .execute (bootstrap , "_module_repr" ));
880
886
SpecialMethodSlot .reinitializeSpecialMethodSlots (moduleType , getLanguage ());
881
-
882
- // __package__ needs to be set and doesn't get set by _bootstrap setup
883
- writeNode .execute (bootstrap , __PACKAGE__ , "importlib" );
884
-
885
- PythonModule bootstrapExternal = (PythonModule ) getSysModules ().getItem ("_frozen_importlib_external" );
886
- writeNode .execute (bootstrapExternal , __PACKAGE__ , "importlib" );
887
887
}
888
888
889
889
private void initializePython3Core (String coreHome ) {
0 commit comments