@@ -842,9 +842,12 @@ private void initializeJavaCore() {
842842 builtinsModule = builtinModules .get (BuiltinNames .BUILTINS );
843843 }
844844
845+ private static final String IMPORTLIB_NAME = "_frozen_importlib" ;
846+ private static final String IMPORTLIB_EXTERNAL_NAME = "_frozen_importlib_external" ;
847+
845848 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 ;
848851
849852 PyObjectCallMethodObjArgs callNode = PyObjectCallMethodObjArgs .getUncached ();
850853 WriteAttributeToDynamicObjectNode writeNode = WriteAttributeToDynamicObjectNode .getUncached ();
@@ -856,18 +859,21 @@ private void initializeImportlib() {
856859
857860 if (bootstrap == null ) {
858861 // 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" );
862863 bootstrap = createModule ("importlib._bootstrap" );
863- writeNode .execute (bootstrap , __PACKAGE__ , "importlib" );
864- setItem .execute (null , sysModules , importlibName , bootstrap );
865864 loadFile ("importlib/_bootstrap_external" , getContext ().getStdlibHome (), bootstrapExternal );
866865 loadFile ("importlib/_bootstrap" , getContext ().getStdlibHome (), bootstrap );
867866 } 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>" );
870870 }
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" );
871877
872878 callNode .execute (null , bootstrap , "_install" , getSysModule (), lookupBuiltinModule ("_imp" ));
873879 writeNode .execute (getBuiltins (), "__import__" , readNode .execute (bootstrap , "__import__" ));
@@ -878,12 +884,6 @@ private void initializeImportlib() {
878884 PythonBuiltinClass moduleType = lookupType (PythonBuiltinClassType .PythonModule );
879885 writeNode .execute (moduleType , __REPR__ , readNode .execute (bootstrap , "_module_repr" ));
880886 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" );
887887 }
888888
889889 private void initializePython3Core (String coreHome ) {
0 commit comments