From 6a7baf2a9069d33aab3c08907d24f760256053e3 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Tue, 30 Mar 2021 18:06:56 +0200 Subject: [PATCH] v0.3.1 --- resources/BABASHKA_VERSION | 2 +- src/babashka/main.clj | 21 +++++++++++---------- test/babashka/bb_edn_test.clj | 8 ++++++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/resources/BABASHKA_VERSION b/resources/BABASHKA_VERSION index 9f6605e0..a2268e2d 100644 --- a/resources/BABASHKA_VERSION +++ b/resources/BABASHKA_VERSION @@ -1 +1 @@ -0.3.1-SNAPSHOT \ No newline at end of file +0.3.1 \ No newline at end of file diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 12515de2..ccd08e7e 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -111,7 +111,7 @@ or: bb [classpath opts] subcommand [subcommand opts] [cmdline args] Classpath: - -cp, --classpath Classpath to use. + -cp, --classpath Classpath to use. Overrides bb.edn classpath. Evaluation: @@ -562,8 +562,16 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.") uberscript-sources (atom ()) classpath (or classpath (System/getenv "BABASHKA_CLASSPATH")) - _ (when classpath - (cp/add-classpath classpath)) + _ (if classpath + (cp/add-classpath classpath) + ;; when classpath isn't set, we calculate it from bb.edn, if present + (let [bb-edn-file (or (System/getenv "BABASHKA_EDN") + "bb.edn")] + (when (fs/exists? bb-edn-file) + (let [edn (edn/read-string (slurp bb-edn-file))] + (vreset! bb-edn edn))) + ;; we mutate the atom from tests as well, so despite the above it can contain a bb.edn + (when-let [bb-edn @bb-edn] (deps/add-deps bb-edn)))) abs-path (when file (let [abs-path (.getAbsolutePath (io/file file))] (vars/bindRoot sci/file abs-path) @@ -715,13 +723,6 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.") exit-code)))) (defn main [& args] - (let [bb-edn-file (or (System/getenv "BABASHKA_EDN") - "bb.edn")] - (when (fs/exists? bb-edn-file) - (let [edn (edn/read-string (slurp bb-edn-file))] - (vreset! bb-edn edn))) - ;; we mutate the atom from tests as well, so despite the above it can contain a bb.edn - (when-let [bb-edn @bb-edn] (deps/add-deps bb-edn))) (let [opts (parse-opts args)] (exec opts))) diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 41ad4e55..b0488b4f 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -4,7 +4,7 @@ [babashka.test-utils :as test-utils] [clojure.edn :as edn] [clojure.string :as str] - [clojure.test :as test :refer [deftest is]])) + [clojure.test :as test :refer [deftest is testing]])) (defn bb [& args] (edn/read-string @@ -35,7 +35,11 @@ (deftest deps-test (with-config '{:deps {medley/medley {:mvn/version "1.3.0"}}} (is (= '{1 {:id 1}, 2 {:id 2}} - (bb "-e" "(require 'medley.core)" "-e" "(medley.core/index-by :id [{:id 1} {:id 2}])"))))) + (bb "-e" "(require 'medley.core)" "-e" "(medley.core/index-by :id [{:id 1} {:id 2}])")))) + (testing "--classpath option overrides bb.edn" + (with-config '{:deps {medley/medley {:mvn/version "1.3.0"}}} + (is (= "src" + (bb "-cp" "src" "-e" "(babashka.classpath/get-classpath)")))))) ;; TODO: ;; Do we want to support the same parsing as the clj CLI?