@@ -45,7 +45,21 @@ def wrap_exec_module(self, module):
45
45
# __path__ must be an iterable of strings,
46
46
# we convert any valid __path__ to tuple of strings.
47
47
# Ref: https://docs.python.org/3/reference/import.html#module-path
48
- path = tuple (path ) if path else None
48
+ if not path :
49
+ path = None
50
+ elif isinstance (path , str ):
51
+ # Some package might change this, which is non-standard.
52
+ # There is no correct way to handle this.
53
+ # We retain the file location to maintain the original import function,
54
+ # and also record the `path` for debugging purposes.
55
+ import os .path
56
+ path = (os .path .dirname (file ), path )
57
+ else :
58
+ try :
59
+ path = tuple (path )
60
+ except TypeError :
61
+ _verbose (f"{ name } .__path__ is not iterable: { path } " , 1 )
62
+ path = None
49
63
meta_map [name ] = (package , file , path )
50
64
return module
51
65
@@ -68,8 +82,9 @@ def wrap_exec_module(self, module):
68
82
_verbose (f'executing module { line } triggers an SystemExit({ e .code } ), ignoring.' , 1 )
69
83
except Exception as e :
70
84
_verbose (f'executing module { line } triggers an { e .__class__ .__name__ } , traceback:' , 1 )
85
+ import sys
71
86
import traceback
72
- _verbose ('' .join (traceback .format_exception (e )), 1 )
87
+ _verbose ('' .join (traceback .format_exception (* sys . exc_info () )), 1 )
73
88
74
89
shared_class_data = tuple ([(k , v ) for k , v in {
75
90
k : (* meta_map [k ], code_map [k ])
0 commit comments