Pod namespaces come before namespaces from source

This commit is contained in:
Michiel Borkent 2022-06-20 12:14:48 +02:00
parent 0a55554bb8
commit 9ed705f8db
2 changed files with 41 additions and 34 deletions

View file

@ -773,40 +773,45 @@ Use bb run --help to show this help output.
_ (when jar _ (when jar
(cp/add-classpath jar)) (cp/add-classpath jar))
load-fn (fn [{:keys [:namespace :reload]}] load-fn (fn [{:keys [:namespace :reload]}]
(or (when-let [{:keys [:loader]} (let [{:keys [loader]}
@cp/cp-state] @cp/cp-state]
(if ;; ignore built-in namespaces when uberscripting, unless with :reload (or
(and uberscript (when ;; ignore built-in namespaces when uberscripting, unless with :reload
(not reload) (and uberscript
(or (contains? namespaces namespace) (not reload)
(contains? sci-namespaces/namespaces namespace))) (or (contains? namespaces namespace)
"" (contains? sci-namespaces/namespaces namespace)))
(when-let [res (cp/source-for-namespace loader namespace nil)] "")
(if uberscript ;; pod namespaces go before namespaces from source,
(do (swap! uberscript-sources conj (:source res)) ;; unless reload is used
(uberscript/uberscript {:ctx @common/ctx (when-not reload
:expressions [(:source res)]}) (when-let [pod (get @pod-namespaces namespace)]
{}) (if uberscript
res)))) (do
(if-let [pod (get @pod-namespaces namespace)] (swap! uberscript-sources conj
(if uberscript (format
(do "(babashka.pods/load-pod '%s \"%s\" '%s)\n"
(swap! uberscript-sources conj (:pod-spec pod) (:version (:opts pod))
(format (dissoc (:opts pod)
"(babashka.pods/load-pod '%s \"%s\" '%s)\n" :version :metadata)))
(:pod-spec pod) (:version (:opts pod)) {})
(dissoc (:opts pod) (pods/load-pod (:pod-spec pod) (:opts pod)))))
:version :metadata))) (when loader
{}) (when-let [res (cp/source-for-namespace loader namespace nil)]
(pods/load-pod (:pod-spec pod) (:opts pod))) (if uberscript
(case namespace (do (swap! uberscript-sources conj (:source res))
clojure.spec.alpha (uberscript/uberscript {:ctx @common/ctx
(binding [*out* *err*] :expressions [(:source res)]})
(println "[babashka] WARNING: Use the babashka-compatible version of clojure.spec.alpha, available here: https://github.com/babashka/spec.alpha")) {})
clojure.core.specs.alpha res)))
(binding [*out* *err*] (case namespace
(println "[babashka] WARNING: clojure.core.specs.alpha is removed from the classpath, unless you explicitly add the dependency.")) clojure.spec.alpha
nil)))) (binding [*out* *err*]
(println "[babashka] WARNING: Use the babashka-compatible version of clojure.spec.alpha, available here: https://github.com/babashka/spec.alpha"))
clojure.core.specs.alpha
(binding [*out* *err*]
(println "[babashka] WARNING: clojure.core.specs.alpha is removed from the classpath, unless you explicitly add the dependency."))
nil))))
main (if (and jar (not main)) main (if (and jar (not main))
(when-let [res (cp/getResource (when-let [res (cp/getResource
(cp/loader jar) (cp/loader jar)

View file

@ -35,6 +35,7 @@
(bb (pr-str `(do (babashka.deps/add-deps '{:deps {babashka/process {:git/url "https://github.com/babashka/process" :sha "4c6699d06b49773d3e5c5b4c11d3334fb78cc996"}}} (bb (pr-str `(do (babashka.deps/add-deps '{:deps {babashka/process {:git/url "https://github.com/babashka/process" :sha "4c6699d06b49773d3e5c5b4c11d3334fb78cc996"}}}
{:force true {:force true
:env {"PATH" (System/getenv "PATH") :env {"PATH" (System/getenv "PATH")
"JAVA_HOME" (System/getenv "JAVA_HOME")
"GITLIBS" ~(str libs-dir)}}) nil))) "GITLIBS" ~(str libs-dir)}}) nil)))
(bb (pr-str `(do (babashka.deps/add-deps '{:deps {babashka/process {:git/url "https://github.com/babashka/process" :sha "4c6699d06b49773d3e5c5b4c11d3334fb78cc996"}}} (bb (pr-str `(do (babashka.deps/add-deps '{:deps {babashka/process {:git/url "https://github.com/babashka/process" :sha "4c6699d06b49773d3e5c5b4c11d3334fb78cc996"}}}
{:force true {:force true
@ -86,6 +87,7 @@ true
libs-dir2 (fs/file tmp-dir ".gitlibs2") libs-dir2 (fs/file tmp-dir ".gitlibs2")
template (pr-str '(do (babashka.deps/clojure ["-Sforce" "-Spath" "-Sdeps" "{:deps {babashka/process {:git/url \"https://github.com/babashka/process\" :sha \"4c6699d06b49773d3e5c5b4c11d3334fb78cc996\"}}}"] template (pr-str '(do (babashka.deps/clojure ["-Sforce" "-Spath" "-Sdeps" "{:deps {babashka/process {:git/url \"https://github.com/babashka/process\" :sha \"4c6699d06b49773d3e5c5b4c11d3334fb78cc996\"}}}"]
{:out :string :env-key {"PATH" (System/getenv "PATH") {:out :string :env-key {"PATH" (System/getenv "PATH")
"JAVA_HOME" (System/getenv "JAVA_HOME")
"GITLIBS" :gitlibs}}) nil))] "GITLIBS" :gitlibs}}) nil))]
(bb (-> template (str/replace ":gitlibs" (pr-str (str libs-dir))) (bb (-> template (str/replace ":gitlibs" (pr-str (str libs-dir)))
(str/replace ":env-key" ":env"))) (str/replace ":env-key" ":env")))