From 5a53403b542f14db1233e29badfed56e6c3d2302 Mon Sep 17 00:00:00 2001 From: ikappaki Date: Mon, 2 Dec 2024 21:35:38 +0000 Subject: [PATCH] close --- CHANGELOG.md | 4 +++ README.md | 8 ++--- basilisp_kernel/nrepl_server.lpy | 62 ++++++++++++++++---------------- 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70b6ccd..bef0d22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- Added nREPL Server support. +- Dropped Python 3.8 support and added 3.13 in CI testing. +- Set minimum Basilisp version to >=0.3.2. + ## 1.1.0 - Optimized output to stdout/stderr by removing proxy string intermediary. diff --git a/README.md b/README.md index 0fb12b9..049116a 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Start your Jupyter notebook server: jupyter notebook ``` -In the Jupyter interface, select the Basilisp kernel when creating a new notebook. +In the Jupyter interface, select the `Basilisp` Kernel when creating a new notebook. ## Examples @@ -58,7 +58,7 @@ The Basilisp Kernel includes an nREPL server, allowing remote interaction with n Start the nREPL in your notebook by running: ```clojure (require '[basilisp-kernel.nrepl-server :refer [server-start server-shut]]) -(def server (server-start {})) +(def server (server-start)) => nREPL server started on port 58966 on host 127.0.0.1 - nrepl://127.0.0.1:58966 => #'user/server ``` @@ -72,9 +72,9 @@ For additional configuration options, such as specifying a port with `:port` or => :shut ``` -## Getting started with Basilisp Notebooks +## Getting Started with Basilisp Notebooks Development -Below are various methods to help you start writing Basilisp code that can be loaded in a Notebook. +Below are various methods to help you start writing Basilisp code that can be loaded in a Basilisp notebook. ### 🔋 Batteries Included Project: `basilex-notebook` diff --git a/basilisp_kernel/nrepl_server.lpy b/basilisp_kernel/nrepl_server.lpy index 07bb499..1f37be9 100644 --- a/basilisp_kernel/nrepl_server.lpy +++ b/basilisp_kernel/nrepl_server.lpy @@ -26,7 +26,7 @@ "Starts the nrepl-server in async mode according to `OPTS`, using a asyncio task to schedule any pending client work every 100ms. - `OPTS` is a map that can have the following keys + `OPTS` is a map that can have the following keys. It defaults to {}. `:dir` The directory where the `.nrepl-port` file should be created at. It defaults to the current working directory if not given or @@ -49,38 +49,40 @@ connections. `:shutdown!` A function to shutdown the server." - [{:keys [host port dir interval-sec] :as opts - :or {port 0 - interval-sec 0.1}}] - (let [host (if (or (nil? host) (empty? (str/trim host))) - "127.0.0.1" - host) - nrepl-port-dir (if (or (nil? dir) (empty? (str/trim dir))) - "." - dir)] + ([] + (server-start {})) + ([{:keys [host port dir interval-sec] :as opts + :or {port 0 + interval-sec 0.1}}] + (let [host (if (or (nil? host) (empty? (str/trim host))) + "127.0.0.1" + host) + nrepl-port-dir (if (or (nil? dir) (empty? (str/trim dir))) + "." + dir)] - (if (not (os.path/isdir nrepl-port-dir)) - {:error (u/error-make [:nrepl-server-start :nrepl-port-dir-not-a-dir nrepl-port-dir])} + (if (not (os.path/isdir nrepl-port-dir)) + {:error (u/error-make [:nrepl-server-start :nrepl-port-dir-not-a-dir nrepl-port-dir])} - (let [{:keys [error work-fn shutdown-fn] :as ret} - (nr/server-start! {:async? true - :host host - :port port - :nrepl-port-file (os.path/join nrepl-port-dir ".nrepl-port")})] - (if error - (binding [*out* sys/stderr] - (println :server-start-error (u/error->str error)) - {:error error}) + (let [{:keys [error work-fn shutdown-fn] :as ret} + (nr/server-start! {:async? true + :host host + :port port + :nrepl-port-file (os.path/join nrepl-port-dir ".nrepl-port")})] + (if error + (binding [*out* sys/stderr] + (println :server-start-error (u/error->str error)) + {:error error}) - (let [shutdown?* (volatile! false) - shutdown! #(do (vreset! shutdown?* true) - (shutdown-fn) - :shut) - loop (asyncio/get-running-loop) - task (.create-task loop (work-task interval-sec work-fn shutdown?* shutdown!))] - (-> (select-keys ret [:host :port :nrepl-port-file]) - (assoc :shutdown! shutdown! - :_task task)))))))) + (let [shutdown?* (volatile! false) + shutdown! #(do (vreset! shutdown?* true) + (shutdown-fn) + :shut) + loop (asyncio/get-running-loop) + task (.create-task loop (work-task interval-sec work-fn shutdown?* shutdown!))] + (-> (select-keys ret [:host :port :nrepl-port-file]) + (assoc :shutdown! shutdown! + :_task task))))))))) (defn ^:inline server-shut "Convenience function to shutdown the `SERVER`."