Fix REPL issues
@@ -161,13 +161,14 @@ def __runREPL__(repl_name="", namespace={}, banner=None):
sys.excepthook = excepthook
sys.displayhook = displayhook
- __namespace__ = {"clear":ClearREPL()}
- __namespace__.update(namespace)
- __repl_namespace__[repl_name] = __namespace__
+ __repl_namespace__[repl_name] = {"clear":ClearREPL(), "__name__":repl_name.split(".")[0], "__file__":repl_name}
+ __repl_namespace__[repl_name].update(namespace)
+
+ __namespace__ = __repl_namespace__[repl_name]
def read(prompt):
import console
- console.__repl_namespace__[repl_name] = __namespace__
+ __namespace__.update(console.__repl_namespace__[repl_name])
return input(prompt, highlight=True)
@@ -183,7 +184,7 @@ def __runREPL__(repl_name="", namespace={}, banner=None):
# MARK: - Running
-def __clear_mods__(is_widget=False):
+def __clear_mods__():
try:
del sys.modules["pip"]
except KeyError:
@@ -221,7 +222,6 @@ def __clear_mods__(is_widget=False):
except KeyError:
pass
- if not is_widget:
try:
del sys.modules["widgets"]
except KeyError:
@@ -265,6 +265,8 @@ def __clear_mods__(is_widget=False):
pass
+__widget_id__ = None
+
if "widget" not in os.environ:
__script__ = None
@@ -277,7 +279,7 @@ if "widget" not in os.environ:
__are_breakpoints_set__ = True
- def run_script(path, replMode=False, debug=False, breakpoints=[], is_widget=False):
+ def run_script(path, replMode=False, debug=False, breakpoints=[], runREPL=True):
"""
Run the script at given path catching exceptions.
@@ -288,10 +290,11 @@ if "widget" not in os.environ:
replMode: If set to `True`, errors will not be handled.
debug: Set to `True` for debugging.
breakpoints: Lines to break if debugging.
+ runREPL: Set it to `True` for running the REPL.
"""
__repl_namespace__[path.split("/")[-1]] = {}
- __clear_mods__(is_widget)
+ __clear_mods__()
python = Python.shared
python.addScriptToList(path)
@@ -354,10 +357,6 @@ if "widget" not in os.environ:
except PermissionError:
pass
- if Python.shared.widgetLink is not None:
- import widgets
- widgets.link = str(Python.shared.widgetLink)
-
# Kill the REPL running for this script
global __repl_threads__
if path in __repl_threads__:
@@ -549,7 +548,7 @@ if "widget" not in os.environ:
Python.shared.isScriptRunning = False
Python.shared.removeScriptFromList(path)
- if path.endswith(".repl.py"): # Is REPL
+ if path.endswith(".repl.py") or not runREPL:
return
if type(t) is tuple and len(t) == 3 and not is_watch_script:
