From 383b375a13ffdfd42547747b4e1a5fd165c28f48 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Wed, 3 Apr 2024 22:15:12 -0400 Subject: 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. --- Biz/Repl.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'Biz/Repl.py') 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) -- cgit v1.2.3