babashka

Oliver Marks 2025-07-24T13:08:07.508969Z

Got a resources query I am using babashka tasks, I am pulling in a library which has some yaml files in its resources folder I would like to read them, I am trying (io/resource) but getting nil, should babashka be able to find these. My aim is to have a shared task file with some resources that each project needs, so that I can updated the shared task file instead of each project independently so open to other options ?

Bob B 2025-07-24T13:45:46.202819Z

From what I can see, it looks like it's more or less the same as clj. A jar file being on the classpath is the root of the jar, so if the path arg to resource is relative to the root of a jar, it resolves.

Oliver Marks 2025-07-24T14:02:36.054899Z

I was not sure if it would be the same as its not really a jar in git and bb is native so things felt a bit different, most likely its me doing something wrong

Bob B 2025-07-24T14:08:37.303649Z

afaik, the more general gist is that the arg to resource should be a relative path from a classpath root

👍 2
borkdude 2025-07-24T14:22:52.710839Z

Yes, this should work the same as with Clojure - if not I consider it a bug

Casey 2025-07-24T14:13:05.844389Z

I'm using babashka for more and more things, it's really a great systems scripting tool. The whole ecosystem is just fabulous: fs, process, and cli. My latest creation today is https://github.com/Ramblurr/spdx-util. A real light bulb went off for me when I realized how seamless/easy it is to use bb to pop open an nrepl server, jack in with emacs, tinker with some script, then tear it all down.. you don't need a project dir or a deps.edn or any ceremony at all

4
6
🎉 5
borkdude 2025-07-24T15:18:43.500419Z

Glad to hear, thanks for sharing!

neumann 2025-07-24T17:02:28.327309Z

@ramblurr If you post a link to your project in #announcements, I'll pick it up when I put together the Clojure Deref.

Casey 2025-07-25T06:19:51.882649Z

Oh thanks for the offer neumann, this is just a little utility i put out there but it's mainly for my own use, I don't think other folks will see much interest in it (aside from an example the bb cli stack, which is why I put it on github)

👍 1
seancorfield 2025-07-24T15:21:43.686859Z

Coupla Qs now I'm using bb tasks "in anger"... 1) if I have duplicated code, is the "idiomatic approach" to put that in a "private" task and run it from other tasks "like a function"? 2) if I need tasks to "communicate" with each other, like passing arguments to functions, is it idiomatic to use binding to manipulate *command-line-args*? For reference, here's my bb.edn with two such -<tasks>: https://github.com/seancorfield/honeysql/blob/develop/bb.edn

lread 2025-07-24T15:30:03.736169Z

For 1) I tend to keep my bb.edn light and put the supporting code under a script dir. Example: rewrite-clj https://github.com/clj-commons/rewrite-clj/blob/main/bb.edn and https://github.com/clj-commons/rewrite-clj/tree/main/script. I think this strategy might help with your duplicated code?

➕ 3
lread 2025-07-24T15:31:17.467389Z

Keeping the code separate allows me to easily debug in a JVM repl, which can be nice.

lread 2025-07-24T15:33:06.332959Z

For 2) I have used both run and :depends an example is https://github.com/lread/test-doc-blocks/blob/main/bb.edn.

lread 2025-07-24T15:37:35.985569Z

I think my rewrite-clj bb scripts existed before bb tasks was released... so maybe that's why the separation is so extreme for that project!

seancorfield 2025-07-24T15:37:48.593539Z

1) Interesting. Not sure I want a separate script with a -main for every task -- that's a lot of files and boilerplate that I'm trying to avoid 🙂 -- but good to see how easy it is to invoke other scripts. 2) Ah, :init defining functions you want to use later... that's slick. I haven't looked into lifecycle hooks like that (and :enter / :leave). I see your multi-version testing follows a similar pattern to mine (to some extent -- in terms of binding and *command-line-args* to "communicate" between tasks.

lread 2025-07-24T15:39:40.315319Z

Yes, you can call any fn, in scripts. Does not have to be main.

lread 2025-07-24T15:41:58.721259Z

Another thing you might run into in bb.edn is that some clojure code is not valid edn. Like #"foo.*" and #(booya %)

seancorfield 2025-07-24T15:50:03.201079Z

Yeah, I hit the #(...) issue "because EDN" but that makes perfect sense.

👍 1
lread 2025-07-24T15:55:38.239399Z

I'm happy that you are dipping your toes into babashka, Sean. I hope that you find bb as delightful as I do.

seancorfield 2025-07-24T15:57:51.231919Z

Delightful enough to switch next.jdbc and HoneySQL over to it 🙂

🎉 2
seancorfield 2025-07-24T15:59:10.710829Z

Next, I might add bb.edn to deps-new generated projects as an optional alternative to build.clj 🙂

lread 2025-07-24T16:03:00.399049Z

Interesting! A delightful thing for me is to type bb tasks on any of my projects to quickly see what I can do.

💯 2
1
seancorfield 2025-07-24T16:03:39.612209Z

Yeah, that and autocompletion via the shell on tasks is very nice.

👍 1
💯 3
escherize 2025-07-24T17:58:22.442259Z

We use it in anger at metabase, I wrote a cli parser that adds a few bells and whistles like option parsing, argument schemas, and automatic --help handling. it is open source if you want to take a look at our https://github.com/metabase/metabase/blob/run-png-optimizer-on-typedocs-label-only/bb.edn#L209-L239

escherize 2025-07-24T17:59:56.909559Z

> "because EDN" Same with regexes, also functions defined in the current-task need to be eval'd so they aren't symbols: https://github.com/metabase/metabase/blob/master/mage/mage/cli.clj#L75-L77

escherize 2025-07-24T18:02:11.966919Z

The extra indirection is due to that tool supporting non-clojure people, so I wrapped it with a top level shell script, that way they don't need to learn about babashka et al, to run the tasks they need.

seancorfield 2025-07-24T02:47:34.200339Z

honeysql PR switching to bb tasks: https://github.com/seancorfield/honeysql/pull/584

1
🎉 4