File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 2020#* Imports
2121import ast
2222import collections
23+ import importlib
2324import inspect
2425import io
2526import json
@@ -149,12 +150,21 @@ def get_import_name(fname: str) -> str:
149150def chfile (f : str ) -> None :
150151 tf = top_level ()
151152 tf .f_globals ["__file__" ] = f
152- tf .f_globals ["__name__" ] = get_import_name (f )
153+ name = get_import_name (f )
154+ tf .f_globals ["__name__" ] = name
153155 d = os .path .dirname (f )
154156 try :
155157 os .chdir (d )
158+ if "sys" not in tf .f_globals :
159+ tf .f_globals ["sys" ] = importlib .import_module ("sys" )
160+ if name not in tf .f_globals ["sys" ].modules :
161+ try :
162+ mod = importlib .import_module (name )
163+ tf .f_globals ["sys" ].modules [name ] = mod
164+ except :
165+ pass
156166 except :
157- pass
167+ raise
158168
159169def arglist (sym : Callable ) -> List [str ]:
160170 def format_arg (arg_pair : Tuple [str , Optional [str ]]) -> str :
@@ -596,7 +606,6 @@ def reload():
596606 top_level ().f_globals ["lp" ] = mod
597607
598608def reload_module (fname ):
599- import importlib
600609 to_reload = []
601610 for (name , module ) in sys .modules .copy ().items ():
602611 try :
You can’t perform that action at this time.
0 commit comments