Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions basilisp_kernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]+")

Expand All @@ -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
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

Expand Down
22 changes: 17 additions & 5 deletions tests/basilisp_kernel/integration/notebook_test.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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`:
Expand All @@ -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)))
Expand All @@ -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*)]
Expand Down
Loading