summaryrefslogtreecommitdiff
path: root/Biz
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2024-04-03 22:15:12 -0400
committerBen Sima <ben@bsima.me>2024-04-10 09:48:58 -0400
commit383b375a13ffdfd42547747b4e1a5fd165c28f48 (patch)
treeb8a3a096911ac3a1beb4c3c9f58872ca88a30231 /Biz
parent74f03809a76847c3c026e832d985354638fd9f40 (diff)
Improvements to the Python repl
Adding some helpful info to the repl startup because I kept forgetting that I even had this reload function. Also, don't call it 'r' because I often do like r = some_function() to store results, and then I can't reload anymore.
Diffstat (limited to 'Biz')
-rw-r--r--Biz/Repl.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Biz/Repl.py b/Biz/Repl.py
index 0732fae..9844abf 100644
--- a/Biz/Repl.py
+++ b/Biz/Repl.py
@@ -13,6 +13,7 @@ def use(ns: str, path: str) -> None:
Load or reload the module named 'ns' from 'path'. Like `use` in the Guile
Scheme repl.
"""
+ info(f"loading {ns} from {path}")
spec = importlib.util.spec_from_file_location(ns, path)
module = importlib.util.module_from_spec(spec)
# delete module and its imported names if its already loaded
@@ -27,10 +28,21 @@ def use(ns: str, path: str) -> None:
globals().update({k: getattr(module, k) for k in names})
+def info(s):
+ print(f"info: repl: {s}")
+
+
if __name__ == "__main__":
NS = sys.argv[1]
PATH = sys.argv[2]
use(NS, PATH)
- def r():
+ info("use reload() or _r() after making changes")
+ sys.ps1 = f"{NS}> "
+ sys.ps2 = f"{NS}| "
+
+ def reload():
+ return use(NS, PATH)
+
+ def _r():
return use(NS, PATH)