diff --git a/CHANGELOG.md b/CHANGELOG.md index 03a05dc..2c86ed2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- Set minimum Basilisp version to >=0.4.0 +- Fix import alias resolution after defining a new namespace (#6) + ## 1.2.0 - Added nREPL Server support. diff --git a/basilisp_kernel/kernel.py b/basilisp_kernel/kernel.py index 1cc406d..3741dbf 100644 --- a/basilisp_kernel/kernel.py +++ b/basilisp_kernel/kernel.py @@ -17,9 +17,8 @@ ctx = compiler.CompilerContext(filename="basilisp-kernel", opts=opts) eof = object() -user_ns = runtime.Namespace.get_or_create(sym.symbol("user")) core_ns = runtime.Namespace.get(runtime.CORE_NS_SYM) -cli.eval_str("(ns user (:require clojure.core))", ctx, core_ns, eof) +ns_dyn_var = runtime.Var.find_safe(sym.symbol("*ns*", ns=runtime.CORE_NS)) _DELIMITED_WORD_PATTERN = re.compile(r"[\[\](){\}\s]+") @@ -29,7 +28,7 @@ def do_execute(code): runtime.Var.find_safe(sym.symbol("*err*", ns=runtime.CORE_NS)) : sys.stderr }): try: - return cli.eval_str(code, ctx, user_ns, eof) + return cli.eval_str(code, ctx, ns_dyn_var.deref(), eof) except reader.SyntaxError as e: msg = "".join(format_exception(e, reader.SyntaxError, e.__traceback__)) raise reader.SyntaxError(msg) from None @@ -54,6 +53,10 @@ class BasilispKernel(IPythonKernel): def __init__(self, **kwargs): super().__init__(**kwargs) self.imported = False + runtime.set_current_ns("user") + with runtime.ns_bindings("user") as ns: + ns.refer_all(core_ns) + def do_complete(self, acode, cursor_pos): code = acode[:cursor_pos] diff --git a/pyproject.toml b/pyproject.toml index a071862..5b3297c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ requires-python = ">=3.9" dependencies = [ "ipykernel", "jupyter_client", - "basilisp>=0.3.2", + "basilisp>=0.4.0", "basilisp-nrepl-async>=0.1.0", ] diff --git a/tests/basilisp_kernel/integration/notebook_test.lpy b/tests/basilisp_kernel/integration/notebook_test.lpy index df983ce..22cee6a 100644 --- a/tests/basilisp_kernel/integration/notebook_test.lpy +++ b/tests/basilisp_kernel/integration/notebook_test.lpy @@ -42,11 +42,11 @@ [{:metadata {}, :output_type "execute_result", :execution_count 1, - :data {(keyword nil "text/plain") "13"}}] + :data {:text/plain "13"}}] :execution_count 1, :source "(+ 4 9)",}] (for [cell cells] - (reduce dissoc cell [:id :metadata])))))) + (reduce dissoc cell [:id :metadata])))))) (finally (when (.is-alive km) (.shutdown-kernel km ** :now true)))))) #_(pp/pprint (notebook-execute-test)) @@ -85,12 +85,12 @@ (is *notebook*) (is *client*) (let [{:keys [cells]} (py->lisp (.execute *client*))] - (is (= {(keyword nil "text/plain") "39"} (get-in cells [0 :outputs 0 :data])) cells)))) + (is (= {:text/plain "39"} (get-in cells [0 :outputs 0 :data])) cells)))) #_(pp/pprint (with-notebook-test)) (defn code-output-text-get [cell] - (get-in cell [:outputs 0 :data (keyword nil "text/plain")])) + (get-in cell [:outputs 0 :data :text/plain])) (defn cell-output-get "Returns the `CELL`'s :outputs in the following format according to their `output_type`: @@ -108,7 +108,7 @@ (let [{nm :name text :text} output] (assoc-in acc [:stream nm] text)) "execute_result" - (let [text (get-in output [:data (keyword nil "text/plain")])] + (let [text (get-in output [:data :text/plain])] (assoc-in acc [:result :text] text)) )) {} (:outputs cell))) @@ -126,6 +126,18 @@ #_(pp/pprint (basilisp-notebook-test)) +(deftest ns-change-import-test + (testing "defining a new namespace and using import aliases" + (with-notebook '[(ns test.test) + (import [math :as m]) + (m/sqrt 4)] + (let [{:keys [cells]} (py->lisp (.execute *client*))] + (are [i result] (= result (cell-output-get (aget cells i))) + 0 {} + 1 {} + 2 {:result {:text "2.0"}}))))) +#_(pp/pprint (ns-change-import-test)) + (deftest nrepl-server-test (testing "starting server in notebook and remote changing atom" (with-notebook (concat [(list 'def 'tempdir *tempdir*)]