@@ -219,8 +219,63 @@ def global_cache(self) -> list[pkgutil.ModuleInfo]:
219219 self ._curr_sys_path = sys .path [:]
220220 print ('getting packages' ) # TEMPORARY -- debugging tests on windows
221221 self ._global_cache = list (pkgutil .iter_modules ())
222- mymods = [p for p in self ._global_cache if p .name == "mymodule" ] # TEMPORARY -- debugging tests on windows
223- print ("modules:" , mymods , list (self .iter_submodules (mymods ))) # TEMPORARY -- debugging tests on windows
222+ # === BEGIN TEMPORARY -- debugging tests on windows ===
223+ mymod = next ((p for p in self ._global_cache if p .name == "mymodule" ), None )
224+ if mymod :
225+ spec = mymod .module_finder .find_spec (mymod .name , None )
226+ if spec :
227+ print ("1" )
228+ assert spec .submodule_search_locations and len (spec .submodule_search_locations ) == 1
229+ print ("2" )
230+ importer = pkgutil .get_importer (spec .submodule_search_locations [0 ])
231+ print ("3" )
232+ assert importer and isinstance (importer , FileFinder )
233+ print ("4" )
234+ if importer .path is None or not os .path .isdir (importer .path ):
235+ print ("4a" )
236+ return
237+ yielded = {}
238+ import inspect
239+ try :
240+ filenames = os .listdir (importer .path )
241+ except OSError :
242+ # ignore unreadable directories like import does
243+ print ("4b" )
244+ filenames = []
245+ print ("4c" , filenames )
246+ filenames .sort () # handle packages before same-named modules
247+ submods = []
248+ for fn in filenames :
249+ print ("4d" , fn )
250+ modname = inspect .getmodulename (fn )
251+ print ("4e" , modname )
252+ if modname == '__init__' or modname in yielded :
253+ print ("4f" , modname )
254+ continue
255+ path = os .path .join (importer .path , fn )
256+ ispkg = False
257+ if not modname and os .path .isdir (path ) and '.' not in fn :
258+ print ("4g" )
259+ modname = fn
260+ try :
261+ dircontents = os .listdir (path )
262+ except OSError :
263+ # ignore unreadable directories like import does
264+ dircontents = []
265+ for fn in dircontents :
266+ subname = inspect .getmodulename (fn )
267+ if subname == '__init__' :
268+ ispkg = True
269+ break
270+ else :
271+ continue # not a package
272+ if modname and '.' not in modname :
273+ print ("4h" )
274+ yielded [modname ] = 1
275+ submods .append ((importer , modname , ispkg ))
276+ print ("4i" )
277+ print ("module:" , mymod , submods )
278+ # === END TEMPORARY ===
224279 return self ._global_cache
225280
226281
0 commit comments