Skip to content

Commit

Permalink
close
Browse files Browse the repository at this point in the history
  • Loading branch information
ikappaki committed Dec 2, 2024
1 parent c127247 commit 5a53403
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
```
Expand All @@ -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`

Expand Down
62 changes: 32 additions & 30 deletions basilisp_kernel/nrepl_server.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`."
Expand Down

0 comments on commit 5a53403

Please sign in to comment.