mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[TEMP] Day 57, deep into debugging, I still don't know where is my module
This commit is contained in:
parent
ac3065abbc
commit
75a33da261
1 changed files with 57 additions and 2 deletions
|
|
@ -219,8 +219,63 @@ def global_cache(self) -> list[pkgutil.ModuleInfo]:
|
||||||
self._curr_sys_path = sys.path[:]
|
self._curr_sys_path = sys.path[:]
|
||||||
print('getting packages') # TEMPORARY -- debugging tests on windows
|
print('getting packages') # TEMPORARY -- debugging tests on windows
|
||||||
self._global_cache = list(pkgutil.iter_modules())
|
self._global_cache = list(pkgutil.iter_modules())
|
||||||
mymods = [p for p in self._global_cache if p.name == "mymodule"] # TEMPORARY -- debugging tests on windows
|
# === BEGIN TEMPORARY -- debugging tests on windows ===
|
||||||
print("modules:", mymods, list(self.iter_submodules(mymods))) # TEMPORARY -- debugging tests on windows
|
mymod = next((p for p in self._global_cache if p.name == "mymodule"), None)
|
||||||
|
if mymod:
|
||||||
|
spec = mymod.module_finder.find_spec(mymod.name, None)
|
||||||
|
if spec:
|
||||||
|
print("1")
|
||||||
|
assert spec.submodule_search_locations and len(spec.submodule_search_locations) == 1
|
||||||
|
print("2")
|
||||||
|
importer = pkgutil.get_importer(spec.submodule_search_locations[0])
|
||||||
|
print("3")
|
||||||
|
assert importer and isinstance(importer, FileFinder)
|
||||||
|
print("4")
|
||||||
|
if importer.path is None or not os.path.isdir(importer.path):
|
||||||
|
print("4a")
|
||||||
|
return
|
||||||
|
yielded = {}
|
||||||
|
import inspect
|
||||||
|
try:
|
||||||
|
filenames = os.listdir(importer.path)
|
||||||
|
except OSError:
|
||||||
|
# ignore unreadable directories like import does
|
||||||
|
print("4b")
|
||||||
|
filenames = []
|
||||||
|
print("4c", filenames)
|
||||||
|
filenames.sort() # handle packages before same-named modules
|
||||||
|
submods = []
|
||||||
|
for fn in filenames:
|
||||||
|
print("4d", fn)
|
||||||
|
modname = inspect.getmodulename(fn)
|
||||||
|
print("4e", modname)
|
||||||
|
if modname=='__init__' or modname in yielded:
|
||||||
|
print("4f", modname)
|
||||||
|
continue
|
||||||
|
path = os.path.join(importer.path, fn)
|
||||||
|
ispkg = False
|
||||||
|
if not modname and os.path.isdir(path) and '.' not in fn:
|
||||||
|
print("4g")
|
||||||
|
modname = fn
|
||||||
|
try:
|
||||||
|
dircontents = os.listdir(path)
|
||||||
|
except OSError:
|
||||||
|
# ignore unreadable directories like import does
|
||||||
|
dircontents = []
|
||||||
|
for fn in dircontents:
|
||||||
|
subname = inspect.getmodulename(fn)
|
||||||
|
if subname=='__init__':
|
||||||
|
ispkg = True
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
continue # not a package
|
||||||
|
if modname and '.' not in modname:
|
||||||
|
print("4h")
|
||||||
|
yielded[modname] = 1
|
||||||
|
submods.append((importer, modname, ispkg))
|
||||||
|
print("4i")
|
||||||
|
print("module:", mymod, submods)
|
||||||
|
# === END TEMPORARY ===
|
||||||
return self._global_cache
|
return self._global_cache
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue