Switch to use ctx-store for global context
This commit is contained in:
parent
495ded8a50
commit
b458d79b29
14 changed files with 35 additions and 32 deletions
|
|
@ -60,7 +60,7 @@
|
||||||
(selmer.parser/render-template template context-map)))
|
(selmer.parser/render-template template context-map)))
|
||||||
|
|
||||||
(defn sci-ns-resolve [ns fqs]
|
(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]
|
(defn force! [x]
|
||||||
(if (instance? clojure.lang.IDeref x) @x x))
|
(if (instance? clojure.lang.IDeref x) @x x))
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@
|
||||||
#_(assert (<= (count ans)) (pr-str ans))
|
#_(assert (<= (count ans)) (pr-str ans))
|
||||||
(let [xn (xml/uri-symbol n)
|
(let [xn (xml/uri-symbol n)
|
||||||
al (symbol (clj-ns-name a))]
|
al (symbol (clj-ns-name a))]
|
||||||
(sci/eval-form @ctx `(create-ns (quote ~xn)))
|
(sci/eval-form (ctx) `(create-ns (quote ~xn)))
|
||||||
(sci/eval-form @ctx `(alias (quote ~al) (quote ~xn)))
|
(sci/eval-form (ctx) `(alias (quote ~al) (quote ~xn)))
|
||||||
(recur rst)))))
|
(recur rst)))))
|
||||||
|
|
||||||
(def xml-namespace
|
(def xml-namespace
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@
|
||||||
'default-data-readers (copy-core-var default-data-readers)
|
'default-data-readers (copy-core-var default-data-readers)
|
||||||
'xml-seq (copy-core-var xml-seq)
|
'xml-seq (copy-core-var xml-seq)
|
||||||
'read+string (new-var 'read+string (fn [& args]
|
'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
|
'*command-line-args* command-line-args
|
||||||
'*warn-on-reflection* warn-on-reflection
|
'*warn-on-reflection* warn-on-reflection
|
||||||
'*compile-files* compile-files
|
'*compile-files* compile-files
|
||||||
|
|
|
||||||
|
|
@ -408,7 +408,7 @@
|
||||||
{:added "1.1"}
|
{:added "1.1"}
|
||||||
[x]
|
[x]
|
||||||
(if (symbol? 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)
|
(when-let [value (if (instance? sci.lang.Var v)
|
||||||
(get-possibly-unbound-var v)
|
(get-possibly-unbound-var v)
|
||||||
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."
|
Because the intent is to run a single test, there is no check for the namespace test-ns-hook."
|
||||||
{:added "1.11"}
|
{:added "1.11"}
|
||||||
[test-symbol]
|
[test-symbol]
|
||||||
(let [test-var (sci/resolve @ctx test-symbol)]
|
(let [test-var (sci/resolve (ctx) test-symbol)]
|
||||||
(cond
|
(cond
|
||||||
(nil? test-var)
|
(nil? test-var)
|
||||||
(sci/binding [sci/out sci/err]
|
(sci/binding [sci/out sci/err]
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
(ns babashka.impl.common
|
(ns babashka.impl.common
|
||||||
(:require
|
(:require
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]
|
||||||
|
[sci.ctx-store :as ctx-store]))
|
||||||
|
|
||||||
;; placeholder for ctx
|
;; placeholder for ctx
|
||||||
(def ctx (volatile! nil))
|
(defn ctx [] (ctx-store/get-ctx))
|
||||||
(def bb-edn (volatile! nil))
|
(def bb-edn (volatile! nil))
|
||||||
(def debug (volatile! false))
|
(def debug (volatile! false))
|
||||||
(def version (str/trim (slurp (io/resource "BABASHKA_VERSION"))))
|
(def version (str/trim (slurp (io/resource "BABASHKA_VERSION"))))
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
:describe {"versions" {"babashka" common/version}}
|
:describe {"versions" {"babashka" common/version}}
|
||||||
:thread-bind [babashka.impl.clojure.core/warn-on-reflection]}
|
:thread-bind [babashka.impl.clojure.core/warn-on-reflection]}
|
||||||
opts)]
|
opts)]
|
||||||
(server/start-server! @common/ctx opts))))
|
(server/start-server! (common/ctx) opts))))
|
||||||
|
|
||||||
(def nrepl-server-namespace
|
(def nrepl-server-namespace
|
||||||
(let [ns-sci (sci/create-ns 'babashka.nrepl.server)]
|
(let [ns-sci (sci/create-ns 'babashka.nrepl.server)]
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
Namespace
|
Namespace
|
||||||
(datafy [n]
|
(datafy [n]
|
||||||
(with-meta {:name (sci-ns-name n)
|
(with-meta {:name (sci-ns-name n)
|
||||||
:publics (->> n (sci-ns-publics @ctx) sortmap)
|
:publics (->> n (sci-ns-publics (ctx)) sortmap)
|
||||||
:imports (->> n (sci-ns-imports @ctx) sortmap)
|
:imports (->> n (sci-ns-imports (ctx)) sortmap)
|
||||||
:interns (->> n (sci-ns-interns @ctx) sortmap)}
|
:interns (->> n (sci-ns-interns (ctx)) sortmap)}
|
||||||
(meta n))))
|
(meta n))))
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
(ns babashka.impl.pods
|
(ns babashka.impl.pods
|
||||||
{:no-doc true}
|
{:no-doc true}
|
||||||
(:refer-clojure :exclude [read])
|
(:refer-clojure :exclude [read])
|
||||||
(:require [babashka.impl.common :refer [ctx bb-edn]]
|
(:require
|
||||||
[babashka.pods.sci :as pods]
|
[babashka.impl.common :refer [bb-edn ctx]]
|
||||||
[sci.core :as sci]
|
[babashka.pods.sci :as pods]
|
||||||
[clojure.java.io :as io]))
|
[clojure.java.io :as io]
|
||||||
|
[sci.core :as sci]))
|
||||||
|
|
||||||
(defn load-pod [& args]
|
(defn load-pod [& args]
|
||||||
(apply pods/load-pod @ctx args))
|
(apply pods/load-pod (ctx) args))
|
||||||
|
|
||||||
(defn load-pods-metadata [pods-map opts]
|
(defn load-pods-metadata [pods-map opts]
|
||||||
(reduce-kv
|
(reduce-kv
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,15 @@
|
||||||
(def sns (sci/create-ns 'clojure.core.server nil))
|
(def sns (sci/create-ns 'clojure.core.server nil))
|
||||||
|
|
||||||
(def prepl (fn [& args]
|
(def prepl (fn [& args]
|
||||||
(apply server/prepl @common/ctx args)))
|
(apply server/prepl (common/ctx) args)))
|
||||||
|
|
||||||
(def io-prepl
|
(def io-prepl
|
||||||
(fn [& args]
|
(fn [& args]
|
||||||
(apply server/io-prepl @common/ctx args)))
|
(apply server/io-prepl (common/ctx) args)))
|
||||||
|
|
||||||
(def start-server
|
(def start-server
|
||||||
(fn [& args]
|
(fn [& args]
|
||||||
(apply server/start-server @common/ctx args)))
|
(apply server/start-server (common/ctx) args)))
|
||||||
|
|
||||||
(def clojure-core-server-namespace
|
(def clojure-core-server-namespace
|
||||||
{'repl (sci/copy-var socket-repl/repl sns)
|
{'repl (sci/copy-var socket-repl/repl sns)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
;; this is mapped to clojure.core.server/repl in babashka.main
|
;; this is mapped to clojure.core.server/repl in babashka.main
|
||||||
(def repl (fn []
|
(def repl (fn []
|
||||||
(repl/repl @common/ctx)))
|
(repl/repl (common/ctx))))
|
||||||
|
|
||||||
(defn parse-opts [opts]
|
(defn parse-opts [opts]
|
||||||
(let [opts (str/trim opts)
|
(let [opts (str/trim opts)
|
||||||
|
|
|
||||||
|
|
@ -455,15 +455,15 @@
|
||||||
([task {:keys [:parallel]
|
([task {:keys [:parallel]
|
||||||
:or {parallel (:parallel (current-task))}}]
|
:or {parallel (:parallel (current-task))}}]
|
||||||
(let [[[expr]] (assemble-task task parallel)]
|
(let [[[expr]] (assemble-task task parallel)]
|
||||||
(sci/eval-string* @ctx expr))))
|
(sci/eval-string* (ctx) expr))))
|
||||||
|
|
||||||
(defn exec
|
(defn exec
|
||||||
([sym]
|
([sym]
|
||||||
(let [snippet (cli/exec-fn-snippet sym)]
|
(let [snippet (cli/exec-fn-snippet sym)]
|
||||||
(sci/eval-string* @ctx snippet)))
|
(sci/eval-string* (ctx) snippet)))
|
||||||
([sym extra-opts]
|
([sym extra-opts]
|
||||||
(let [snippet (cli/exec-fn-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
|
(def tasks-namespace
|
||||||
{'shell (sci/copy-var shell sci-ns)
|
{'shell (sci/copy-var shell sci-ns)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
(defn contextualize [f]
|
(defn contextualize [f]
|
||||||
(fn [& args]
|
(fn [& args]
|
||||||
(apply f @ctx args)))
|
(apply f (ctx) args)))
|
||||||
|
|
||||||
(def tns t/tns)
|
(def tns t/tns)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@
|
||||||
[hf.depstar.uberjar :as uberjar]
|
[hf.depstar.uberjar :as uberjar]
|
||||||
[sci.addons :as addons]
|
[sci.addons :as addons]
|
||||||
[sci.core :as sci]
|
[sci.core :as sci]
|
||||||
|
[sci.ctx-store :as ctx-store]
|
||||||
[sci.impl.copy-vars :as sci-copy-vars]
|
[sci.impl.copy-vars :as sci-copy-vars]
|
||||||
[sci.impl.io :as sio]
|
[sci.impl.io :as sio]
|
||||||
[sci.impl.namespaces :as sci-namespaces]
|
[sci.impl.namespaces :as sci-namespaces]
|
||||||
|
|
@ -303,7 +304,7 @@ Use bb run --help to show this help output.
|
||||||
s (slurp f)]
|
s (slurp f)]
|
||||||
(sci/with-bindings {sci/ns @sci/ns
|
(sci/with-bindings {sci/ns @sci/ns
|
||||||
sci/file (.getAbsolutePath f)}
|
sci/file (.getAbsolutePath f)}
|
||||||
(sci/eval-string* @common/ctx s))))
|
(sci/eval-string* (common/ctx) s))))
|
||||||
|
|
||||||
(defn start-socket-repl! [address ctx]
|
(defn start-socket-repl! [address ctx]
|
||||||
(socket-repl/start-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
|
'repl (sci/new-var 'repl
|
||||||
(fn [& opts]
|
(fn [& opts]
|
||||||
(let [opts (apply hash-map 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)}
|
'with-bindings (sci/copy-var clojure-main/with-bindings clojure-main-ns)}
|
||||||
'clojure.test t/clojure-test-namespace
|
'clojure.test t/clojure-test-namespace
|
||||||
'clojure.math math-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)]
|
(when-let [res (cp/source-for-namespace loader namespace nil)]
|
||||||
(if uberscript
|
(if uberscript
|
||||||
(do (swap! uberscript-sources conj (:source res))
|
(do (swap! uberscript-sources conj (:source res))
|
||||||
(uberscript/uberscript {:ctx @common/ctx
|
(uberscript/uberscript {:ctx (common/ctx)
|
||||||
:expressions [(:source res)]})
|
:expressions [(:source res)]})
|
||||||
{})
|
{})
|
||||||
res)))
|
res)))
|
||||||
|
|
@ -882,7 +883,7 @@ Use bb run --help to show this help output.
|
||||||
:proxy-fn proxy-fn}
|
:proxy-fn proxy-fn}
|
||||||
opts (addons/future opts)
|
opts (addons/future opts)
|
||||||
sci-ctx (sci/init 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 [pods (:pods @common/bb-edn)]
|
||||||
(when-let [pod-metadata (pods/load-pods-metadata
|
(when-let [pod-metadata (pods/load-pods-metadata
|
||||||
pods {:download-only (download-only?)})]
|
pods {:download-only (download-only?)})]
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@
|
||||||
(if tu/jvm?
|
(if tu/jvm?
|
||||||
(let [ctx (init {:namespaces {'clojure.core.server clojure-core-server-namespace}
|
(let [ctx (init {:namespaces {'clojure.core.server clojure-core-server-namespace}
|
||||||
:features #{:bb}})]
|
:features #{:bb}})]
|
||||||
(vreset! common/ctx ctx)
|
(vreset! common/ctx (fn [] ctx))
|
||||||
(start-repl! "0.0.0.0:1666" ctx))
|
(start-repl! "0.0.0.0:1666" ctx))
|
||||||
(do (vreset! server-process
|
(do (vreset! server-process
|
||||||
(p/process ["./bb" "socket-repl" "localhost:1666"]))
|
(p/process ["./bb" "socket-repl" "localhost:1666"]))
|
||||||
|
|
@ -81,7 +81,7 @@
|
||||||
:env (atom {})
|
:env (atom {})
|
||||||
:namespaces {'clojure.core.server clojure-core-server-namespace}
|
:namespaces {'clojure.core.server clojure-core-server-namespace}
|
||||||
:features #{:bb}})]
|
:features #{:bb}})]
|
||||||
(vreset! common/ctx ctx)
|
(vreset! common/ctx (fn [] ctx))
|
||||||
(start-repl! "{:address \"localhost\" :accept clojure.core.server/repl :port 1666}"
|
(start-repl! "{:address \"localhost\" :accept clojure.core.server/repl :port 1666}"
|
||||||
ctx))
|
ctx))
|
||||||
(do (vreset! server-process
|
(do (vreset! server-process
|
||||||
|
|
@ -105,7 +105,7 @@
|
||||||
:env (atom {})
|
:env (atom {})
|
||||||
:namespaces {'clojure.core.server clojure-core-server-namespace}
|
:namespaces {'clojure.core.server clojure-core-server-namespace}
|
||||||
:features #{:bb}})]
|
:features #{:bb}})]
|
||||||
(vreset! common/ctx ctx)
|
(vreset! common/ctx (fn [] ctx))
|
||||||
(start-repl! "{:address \"localhost\" :accept clojure.core.server/io-prepl :port 1666}"
|
(start-repl! "{:address \"localhost\" :accept clojure.core.server/io-prepl :port 1666}"
|
||||||
ctx))
|
ctx))
|
||||||
(do (vreset! server-process
|
(do (vreset! server-process
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue