diff --git a/feature-selmer/babashka/impl/selmer.clj b/feature-selmer/babashka/impl/selmer.clj index 14ce03c8..32aeba3e 100644 --- a/feature-selmer/babashka/impl/selmer.clj +++ b/feature-selmer/babashka/impl/selmer.clj @@ -60,7 +60,7 @@ (selmer.parser/render-template template context-map))) (defn sci-ns-resolve [ns fqs] - (sci/eval-form @ctx (list 'clojure.core/ns-resolve ns (list 'quote fqs)))) + (sci/eval-form (ctx) (list 'clojure.core/ns-resolve ns (list 'quote fqs)))) (defn force! [x] (if (instance? clojure.lang.IDeref x) @x x)) diff --git a/feature-xml/babashka/impl/xml.clj b/feature-xml/babashka/impl/xml.clj index 123310e5..0018cb70 100644 --- a/feature-xml/babashka/impl/xml.clj +++ b/feature-xml/babashka/impl/xml.clj @@ -40,8 +40,8 @@ #_(assert (<= (count ans)) (pr-str ans)) (let [xn (xml/uri-symbol n) al (symbol (clj-ns-name a))] - (sci/eval-form @ctx `(create-ns (quote ~xn))) - (sci/eval-form @ctx `(alias (quote ~al) (quote ~xn))) + (sci/eval-form (ctx) `(create-ns (quote ~xn))) + (sci/eval-form (ctx) `(alias (quote ~al) (quote ~xn))) (recur rst))))) (def xml-namespace diff --git a/src/babashka/impl/clojure/core.clj b/src/babashka/impl/clojure/core.clj index 1c269aed..fa202d41 100644 --- a/src/babashka/impl/clojure/core.clj +++ b/src/babashka/impl/clojure/core.clj @@ -167,7 +167,7 @@ 'default-data-readers (copy-core-var default-data-readers) 'xml-seq (copy-core-var xml-seq) 'read+string (new-var 'read+string (fn [& args] - (apply read+string @common/ctx args))) + (apply read+string (common/ctx) args))) '*command-line-args* command-line-args '*warn-on-reflection* warn-on-reflection '*compile-files* compile-files diff --git a/src/babashka/impl/clojure/test.clj b/src/babashka/impl/clojure/test.clj index b16d16de..422947a2 100644 --- a/src/babashka/impl/clojure/test.clj +++ b/src/babashka/impl/clojure/test.clj @@ -408,7 +408,7 @@ {:added "1.1"} [x] (if (symbol? x) - (when-let [v (second (resolve/lookup @ctx x false))] + (when-let [v (second (resolve/lookup (ctx) x false))] (when-let [value (if (instance? sci.lang.Var v) (get-possibly-unbound-var v) v)] @@ -826,7 +826,7 @@ Because the intent is to run a single test, there is no check for the namespace test-ns-hook." {:added "1.11"} [test-symbol] - (let [test-var (sci/resolve @ctx test-symbol)] + (let [test-var (sci/resolve (ctx) test-symbol)] (cond (nil? test-var) (sci/binding [sci/out sci/err] diff --git a/src/babashka/impl/common.clj b/src/babashka/impl/common.clj index 4a8057d7..ec03b968 100644 --- a/src/babashka/impl/common.clj +++ b/src/babashka/impl/common.clj @@ -1,10 +1,11 @@ (ns babashka.impl.common (:require [clojure.java.io :as io] - [clojure.string :as str])) + [clojure.string :as str] + [sci.ctx-store :as ctx-store])) ;; placeholder for ctx -(def ctx (volatile! nil)) +(defn ctx [] (ctx-store/get-ctx)) (def bb-edn (volatile! nil)) (def debug (volatile! false)) (def version (str/trim (slurp (io/resource "BABASHKA_VERSION")))) diff --git a/src/babashka/impl/nrepl_server.clj b/src/babashka/impl/nrepl_server.clj index 6340e6d6..5b3569cb 100644 --- a/src/babashka/impl/nrepl_server.clj +++ b/src/babashka/impl/nrepl_server.clj @@ -15,7 +15,7 @@ :describe {"versions" {"babashka" common/version}} :thread-bind [babashka.impl.clojure.core/warn-on-reflection]} opts)] - (server/start-server! @common/ctx opts)))) + (server/start-server! (common/ctx) opts)))) (def nrepl-server-namespace (let [ns-sci (sci/create-ns 'babashka.nrepl.server)] diff --git a/src/babashka/impl/patches/datafy.clj b/src/babashka/impl/patches/datafy.clj index 738e664c..386cb5dc 100644 --- a/src/babashka/impl/patches/datafy.clj +++ b/src/babashka/impl/patches/datafy.clj @@ -34,7 +34,7 @@ Namespace (datafy [n] (with-meta {:name (sci-ns-name n) - :publics (->> n (sci-ns-publics @ctx) sortmap) - :imports (->> n (sci-ns-imports @ctx) sortmap) - :interns (->> n (sci-ns-interns @ctx) sortmap)} + :publics (->> n (sci-ns-publics (ctx)) sortmap) + :imports (->> n (sci-ns-imports (ctx)) sortmap) + :interns (->> n (sci-ns-interns (ctx)) sortmap)} (meta n)))) diff --git a/src/babashka/impl/pods.clj b/src/babashka/impl/pods.clj index 54e7cf22..75752c20 100644 --- a/src/babashka/impl/pods.clj +++ b/src/babashka/impl/pods.clj @@ -1,13 +1,14 @@ (ns babashka.impl.pods {:no-doc true} (:refer-clojure :exclude [read]) - (:require [babashka.impl.common :refer [ctx bb-edn]] - [babashka.pods.sci :as pods] - [sci.core :as sci] - [clojure.java.io :as io])) + (:require + [babashka.impl.common :refer [bb-edn ctx]] + [babashka.pods.sci :as pods] + [clojure.java.io :as io] + [sci.core :as sci])) (defn load-pod [& args] - (apply pods/load-pod @ctx args)) + (apply pods/load-pod (ctx) args)) (defn load-pods-metadata [pods-map opts] (reduce-kv diff --git a/src/babashka/impl/server.clj b/src/babashka/impl/server.clj index 1bb01f2b..78af54c7 100644 --- a/src/babashka/impl/server.clj +++ b/src/babashka/impl/server.clj @@ -7,15 +7,15 @@ (def sns (sci/create-ns 'clojure.core.server nil)) (def prepl (fn [& args] - (apply server/prepl @common/ctx args))) + (apply server/prepl (common/ctx) args))) (def io-prepl (fn [& args] - (apply server/io-prepl @common/ctx args))) + (apply server/io-prepl (common/ctx) args))) (def start-server (fn [& args] - (apply server/start-server @common/ctx args))) + (apply server/start-server (common/ctx) args))) (def clojure-core-server-namespace {'repl (sci/copy-var socket-repl/repl sns) diff --git a/src/babashka/impl/socket_repl.clj b/src/babashka/impl/socket_repl.clj index b5532fec..55ed2ca9 100644 --- a/src/babashka/impl/socket_repl.clj +++ b/src/babashka/impl/socket_repl.clj @@ -11,7 +11,7 @@ ;; this is mapped to clojure.core.server/repl in babashka.main (def repl (fn [] - (repl/repl @common/ctx))) + (repl/repl (common/ctx)))) (defn parse-opts [opts] (let [opts (str/trim opts) diff --git a/src/babashka/impl/tasks.clj b/src/babashka/impl/tasks.clj index a5d9592c..99c25162 100644 --- a/src/babashka/impl/tasks.clj +++ b/src/babashka/impl/tasks.clj @@ -455,15 +455,15 @@ ([task {:keys [:parallel] :or {parallel (:parallel (current-task))}}] (let [[[expr]] (assemble-task task parallel)] - (sci/eval-string* @ctx expr)))) + (sci/eval-string* (ctx) expr)))) (defn exec ([sym] (let [snippet (cli/exec-fn-snippet sym)] - (sci/eval-string* @ctx snippet))) + (sci/eval-string* (ctx) snippet))) ([sym extra-opts] (let [snippet (cli/exec-fn-snippet sym extra-opts)] - (sci/eval-string* @ctx snippet)))) + (sci/eval-string* (ctx) snippet)))) (def tasks-namespace {'shell (sci/copy-var shell sci-ns) diff --git a/src/babashka/impl/test.clj b/src/babashka/impl/test.clj index 2d3e95a5..4566b4ce 100644 --- a/src/babashka/impl/test.clj +++ b/src/babashka/impl/test.clj @@ -5,7 +5,7 @@ (defn contextualize [f] (fn [& args] - (apply f @ctx args))) + (apply f (ctx) args))) (def tns t/tns) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 42ef4266..a4a086e2 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -58,6 +58,7 @@ [hf.depstar.uberjar :as uberjar] [sci.addons :as addons] [sci.core :as sci] + [sci.ctx-store :as ctx-store] [sci.impl.copy-vars :as sci-copy-vars] [sci.impl.io :as sio] [sci.impl.namespaces :as sci-namespaces] @@ -303,7 +304,7 @@ Use bb run --help to show this help output. s (slurp f)] (sci/with-bindings {sci/ns @sci/ns sci/file (.getAbsolutePath f)} - (sci/eval-string* @common/ctx s)))) + (sci/eval-string* (common/ctx) s)))) (defn start-socket-repl! [address ctx] (socket-repl/start-repl! address ctx)) @@ -373,7 +374,7 @@ Use bb run --help to show this help output. 'repl (sci/new-var 'repl (fn [& opts] (let [opts (apply hash-map opts)] - (repl/start-repl! @common/ctx opts))) {:ns clojure-main-ns}) + (repl/start-repl! (common/ctx) opts))) {:ns clojure-main-ns}) 'with-bindings (sci/copy-var clojure-main/with-bindings clojure-main-ns)} 'clojure.test t/clojure-test-namespace 'clojure.math math-namespace @@ -847,7 +848,7 @@ Use bb run --help to show this help output. (when-let [res (cp/source-for-namespace loader namespace nil)] (if uberscript (do (swap! uberscript-sources conj (:source res)) - (uberscript/uberscript {:ctx @common/ctx + (uberscript/uberscript {:ctx (common/ctx) :expressions [(:source res)]}) {}) res))) @@ -882,7 +883,7 @@ Use bb run --help to show this help output. :proxy-fn proxy-fn} opts (addons/future opts) sci-ctx (sci/init opts) - _ (vreset! common/ctx sci-ctx) + _ (ctx-store/reset-ctx! sci-ctx) _ (when-let [pods (:pods @common/bb-edn)] (when-let [pod-metadata (pods/load-pods-metadata pods {:download-only (download-only?)})] diff --git a/test/babashka/impl/socket_repl_test.clj b/test/babashka/impl/socket_repl_test.clj index 5e6e587c..ca0efd7b 100644 --- a/test/babashka/impl/socket_repl_test.clj +++ b/test/babashka/impl/socket_repl_test.clj @@ -48,7 +48,7 @@ (if tu/jvm? (let [ctx (init {:namespaces {'clojure.core.server clojure-core-server-namespace} :features #{:bb}})] - (vreset! common/ctx ctx) + (vreset! common/ctx (fn [] ctx)) (start-repl! "0.0.0.0:1666" ctx)) (do (vreset! server-process (p/process ["./bb" "socket-repl" "localhost:1666"])) @@ -81,7 +81,7 @@ :env (atom {}) :namespaces {'clojure.core.server clojure-core-server-namespace} :features #{:bb}})] - (vreset! common/ctx ctx) + (vreset! common/ctx (fn [] ctx)) (start-repl! "{:address \"localhost\" :accept clojure.core.server/repl :port 1666}" ctx)) (do (vreset! server-process @@ -105,7 +105,7 @@ :env (atom {}) :namespaces {'clojure.core.server clojure-core-server-namespace} :features #{:bb}})] - (vreset! common/ctx ctx) + (vreset! common/ctx (fn [] ctx)) (start-repl! "{:address \"localhost\" :accept clojure.core.server/io-prepl :port 1666}" ctx)) (do (vreset! server-process