Skip to content

Commit 98643a2

Browse files
committed
lispy-python.py (chfile): Update
1 parent 097dd66 commit 98643a2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lispy-python.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#* Imports
2121
import ast
2222
import collections
23+
import importlib
2324
import inspect
2425
import io
2526
import json
@@ -149,12 +150,21 @@ def get_import_name(fname: str) -> str:
149150
def 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

159169
def 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

598608
def reload_module(fname):
599-
import importlib
600609
to_reload = []
601610
for (name, module) in sys.modules.copy().items():
602611
try:

0 commit comments

Comments
 (0)