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 ?
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.
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
afaik, the more general gist is that the arg to resource should be a relative path from a classpath root
Yes, this should work the same as with Clojure - if not I consider it a bug
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
Glad to hear, thanks for sharing!
@ramblurr If you post a link to your project in #announcements, I'll pick it up when I put together the Clojure Deref.
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)
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
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?
Keeping the code separate allows me to easily debug in a JVM repl, which can be nice.
For 2) I have used both run and :depends an example is https://github.com/lread/test-doc-blocks/blob/main/bb.edn.
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!
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.
Yes, you can call any fn, in scripts. Does not have to be main.
Another thing you might run into in bb.edn is that some clojure code is not valid edn. Like #"foo.*" and #(booya %)
Example of calling non-main fns in etaoin from https://github.com/clj-commons/etaoin/blob/2d0a4feac0fbcc67157194b4c4d95fc320121640/bb.edn#L65-L68 to https://github.com/clj-commons/etaoin/blob/2d0a4feac0fbcc67157194b4c4d95fc320121640/script/test.clj#L120-L126.
Yeah, I hit the #(...) issue "because EDN" but that makes perfect sense.
I'm happy that you are dipping your toes into babashka, Sean. I hope that you find bb as delightful as I do.
Delightful enough to switch next.jdbc and HoneySQL over to it 🙂
Next, I might add bb.edn to deps-new generated projects as an optional alternative to build.clj 🙂
Interesting! A delightful thing for me is to type bb tasks on any of my projects to quickly see what I can do.
Yeah, that and autocompletion via the shell on tasks is very nice.
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
> "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
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.
honeysql PR switching to bb tasks: https://github.com/seancorfield/honeysql/pull/584