This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-08
Channels
- # announcements (1)
- # babashka (28)
- # beginners (30)
- # calva (1)
- # cider (13)
- # clojure (26)
- # clojure-brasil (2)
- # clojure-europe (29)
- # clojure-italy (1)
- # clojure-nl (1)
- # clojure-norway (16)
- # clojure-spec (4)
- # clojure-uk (5)
- # cursive (17)
- # data-science (15)
- # datomic (8)
- # emacs (8)
- # events (1)
- # hyperfiddle (54)
- # joyride (18)
- # jvm (2)
- # kaocha (8)
- # lsp (8)
- # malli (4)
- # missionary (11)
- # reagent (5)
- # reitit (13)
- # releases (2)
- # rum (2)
- # scittle (6)
- # shadow-cljs (3)
babashka is beautiful. I wanted to be able to run make foo
anywhere in my repo, and it was a perfect chance to write some clojure+bb once again 😄 if someone wants to critique my attempt, you’re welcome to (🧵)
#!/usr/bin/env bb
(require '[babashka.fs :as :fs]
'[babashka.process :refer [shell]])
(def make "/usr/bin/make")
(defn find-root
([] (find-root (fs/cwd)))
([wd] (cond
(fs/exists? (fs/path wd "Makefile")) {:dir wd}
(fs/same-file? (fs/home) wd) :not-found
(fs/exists? (fs/path wd ".git")) :not-found
:else (find-root (fs/parent wd)))))
(defn run-make [wd & args]
(if (= :not-found wd)
(throw (Exception. "Makefile not found"))
(apply shell wd make args)))
(when (= *file* (System/getProperty "babashka.file"))
(apply run-make (find-root) *command-line-args*))
Neat idea. A couple suggestions:
• Replace the recursive find-root
call with a call to recur
.
• Replace (throw (Exception. "Makefile not found"))
with (throw (ex-info "Makefile not found" {:babashka/exit 1}))
, which will make Babashka print out the error message cleaner than the exception stack trace stuff.
There is a PR for a similar function as find-root
here:
https://github.com/babashka/fs/issues/112
Something here tells me that I was right about not including it yet, since it seems the requirements of the above variant are slightly different
thank you all for the feedback, this is very valuable to me 😃
> I think babashka can exec
? That might be better than subprocess
AFAICT it doesn’t support :dir
, though. I could be missing something
I’ve looked into the source, but a “fix” for that is beyond me 😅
yeah for my purposes, the extra shell doesn’t matter. the time the actual make invocation takes dominates the script 🙃
for future reference, https://gist.github.com/srenatus/bbea51ca88ca93da7fa4414c4f749c1a
changed it now to throw an exception when the make call itself errors:
(-> (apply shell (assoc wd :continue true) make args)
:exit
System/exit)))
I upgraded to the latest version of bb
today and suddenly slurp
didn't work to fetch data from apis. So I switched to http-client
and still it fails to fetch. For example: Why does (http/get "
throw a null exception but I am able to fetch from the same address via Curl cli?
I am behind a company firewall
Woops, sorry I thought messaging below myself would merge the messges into a thread (like MS teams).
I will try the jvm settings
also maybe re-download the previous version of bb manually via github releases into another directory and try it as well. I have no idea why things should have changed, but perhaps you can find the exact version when it changed
Now, I am not quite familiar I am doing this right. Is this the way?
{:paths ["src"] :deps {tick/tick {:mvn/version "RELEASE"} org.babashka/http-client {:mvn/version "0.3.11"}} :jvm-opts ["-Dhttp.proxyHost=127.0.0.1" "-Dhttp.proxyPort=3128" "-Dhttps.proxyHost=127.0.0.1" "-Dhttps.proxyPort=3128" "-Dhttps.nonProxyHosts=localhost"]}