Fix #1541: respect bb.edn adjacent to invoked file (#1542)

This commit is contained in:
Michiel Borkent 2023-04-21 13:50:53 +02:00 committed by GitHub
parent 1644c94fda
commit 26967df643
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 5 deletions

View file

@ -50,8 +50,8 @@
org.clojure/data.priority-map {:mvn/version "1.1.0"}
insn/insn {:mvn/version "0.5.2"}
org.clojure/core.rrb-vector {:mvn/version "0.1.2"}
org.babashka/cli {:mvn/version "0.6.50"}
org.babashka/http-client {:mvn/version "0.1.8"}
org.babashka/cli {:mvn/version "0.7.51"}
org.babashka/http-client {:mvn/version "0.2.9"}
;; native image bloat with ordered 1.5.10
org.flatland/ordered {:mvn/version "1.5.9"}}
:aliases {:babashka/dev

View file

@ -154,7 +154,7 @@ Global opts:
-cp, --classpath Classpath to use. Overrides bb.edn classpath.
--debug Print debug information and internal stacktrace in case of exception.
--init <file> Load file after any preloads and prior to evaluation/subcommands.
--config <file> Replacing bb.edn with file. Relative paths are resolved relative to file.
--config <file> Replace bb.edn with file. Defaults to bb.edn adjacent to invoked file or bb.edn in current dir. Relative paths are resolved relative to file.
--deps-root <dir> Treat dir as root of relative paths in config.
--prn Print result via clojure.core/prn
-Sforce Force recalculation of the classpath (don't use the cache)
@ -1123,7 +1123,7 @@ Use bb run --help to show this help output.
(defn main [& args]
(let [[args global-opts] (parse-global-opts args)
{:keys [:jar] :as file-opt} (when (some-> args first io/file .isFile)
{:keys [:jar :file] :as file-opt} (when (some-> args first io/file .isFile)
(parse-file-opt args global-opts))
config (:config global-opts)
merge-deps (:merge-deps global-opts)
@ -1131,7 +1131,12 @@ Use bb run --help to show this help output.
bb-edn-file (cond
config (when (fs/exists? config) (abs-path config))
jar (some-> [jar] cp/new-loader (cp/resource "META-INF/bb.edn") .toString)
:else (when (fs/exists? "bb.edn") (abs-path "bb.edn")))
:else (if (and file (fs/exists? file))
(let [rel-bb-edn (fs/file (fs/parent file) "bb.edn")]
(when (fs/exists? rel-bb-edn)
(abs-path rel-bb-edn)))
(when (fs/exists? "bb.edn")
(abs-path "bb.edn"))))
bb-edn (when (or bb-edn-file merge-deps)
(when bb-edn-file (System/setProperty "babashka.config" bb-edn-file))
(let [raw-string (when bb-edn-file (slurp bb-edn-file))

View file

@ -0,0 +1 @@
{:deps {medley/medley {:mvn/version "1.3.0"}}}

View file

@ -0,0 +1,6 @@
#!/usr/bin/env bb
(ns medley
(:require [medley.core :as medley]))
(prn (medley/index-by :id [{:id 1}]))

View file

@ -518,3 +518,6 @@ even more stuff here\"
out (bb "--config" config "cp")
entries (cp/split-classpath out)]
(is (= (fs/parent f) (fs/parent (first entries)))))))))
(deftest adjacent-bb-edn-test
(is (= {1 {:id 1}} (bb "test-resources/adjacent_bb/medley.bb"))))