diff options
author | Ben Sima <ben@bsima.me> | 2024-04-10 19:56:46 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2024-04-10 19:56:46 -0400 |
commit | 2c09c7f73e2fc770f42b5dd2588aa9634b4e7c6e (patch) | |
tree | a6c49dddb7b1735a0f8de2a9a5f4efb605f16f36 /Biz/Repl.py | |
parent | 051973aba8953ebde51eb1436fb3994e7ae699dc (diff) |
Switch from black to ruff format
Ruff is faster and if it supports everything that black supports than why not? I
did have to pull in a more recent version from unstable, but that's easy to do
now. And I decided to just go ahead and configure ruff by turning on almost all
checks, which meant I had to fix a whole bunch of things, but I did that and
everything is okay now.
Diffstat (limited to 'Biz/Repl.py')
-rw-r--r-- | Biz/Repl.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/Biz/Repl.py b/Biz/Repl.py index 9844abf..9cc0c35 100644 --- a/Biz/Repl.py +++ b/Biz/Repl.py @@ -1,19 +1,25 @@ """ +Improve the standard Python REPL. + This module attempts to emulate the workflow of ghci or lisp repls. It uses importlib to load a namespace from the given path. It then binds 'r()' to a function that reloads the same namespace. """ import importlib +import logging import sys +from Biz import Log + def use(ns: str, path: str) -> None: """ - Load or reload the module named 'ns' from 'path'. Like `use` in the Guile - Scheme repl. + Load or reload the module named 'ns' from 'path'. + + Like `use` in the Guile Scheme repl. """ - info(f"loading {ns} from {path}") + logging.info("loading %s from %s", ns, 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 @@ -24,25 +30,24 @@ def use(ns: str, path: str) -> None: del globals()[name] sys.modules[ns] = module spec.loader.exec_module(module) - names = [x for x in module.__dict__] + names = list(module.__dict__) globals().update({k: getattr(module, k) for k in names}) -def info(s): - print(f"info: repl: {s}") - - if __name__ == "__main__": + Log.setup() NS = sys.argv[1] PATH = sys.argv[2] use(NS, PATH) - info("use reload() or _r() after making changes") + logging.info("use reload() or _r() after making changes") sys.ps1 = f"{NS}> " sys.ps2 = f"{NS}| " - def reload(): + def reload() -> None: + """Reload the namespace.""" return use(NS, PATH) - def _r(): + def _r() -> None: + """Shorthand: Reload the namespace.""" return use(NS, PATH) |