babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
lspector 2021-07-03T02:20:59.305400Z

What's the most elegant way to get the equivalent of something like ls *.log , with a result that is a sequence of the file name strings, in my babashka script? I tried using sh but couldn't make it work with the *. I resorted to the following which works but it seems like there must be a much better way:

(filter #(= ".log" (apply str (take-last 4 %)))
        (map #(.getName %) (.listFiles (File. "."))))

borkdude 2021-07-03T07:25:49.306400Z

Yes or list-dir

👍 1
kokada 2021-07-03T03:01:08.305500Z

https://babashka.org/fs/babashka.fs.html#var-glob ?

❤️ 1
lspector 2021-07-03T03:26:12.305800Z

Nice. So it seems the equivalent of the code I posted above, if I've done (require '[babashka.fs :as fs]), is:

(map fs/file-name (fs/glob "." "*.log"))

Helins 2021-07-03T12:43:40.306800Z

I am preparing a monorepo where each subproject has its own bb.edn file. However, there are sets of useful tasks that I'd like to reuse in some of them. What would you recommend for avoiding any copy/pasting?

lispyclouds 2021-07-03T12:58:23.306900Z

you can put them in a common place like https://github.com/wilkerlucio/pathom-viz/blob/master/src/tasks/tasks.clj then refer them in the corresponding bb.edns like https://github.com/wilkerlucio/pathom-viz/blob/master/bb.edn

borkdude 2021-07-03T13:10:40.307200Z

that's what I would recommend as well

Helins 2021-07-03T13:15:08.307400Z

Indeed, that's what I have been doing but it still implies copying the tasks themselves, and if you change the :doc you have to do it everywhere, for instance. So it was getting messy.

borkdude 2021-07-03T13:16:19.307700Z

Perhaps generate the tasks file using Selmer? perhaps a little hacky ;)

Helins 2021-07-03T13:20:12.310500Z

Related to previous but different. For very common tasks that end up pretty much in all subprojects (eg. test), I am trying to define them in my root bb.edn and specify a :dir when calling (clojure ...) (where a subproject lives and has its deps.ednfile). However I am having an issue with a dep that points to a :local/root:

Error building classpath. Manifest type not detected when finding deps ...
In spite of the path to that jar being correct. Doesn't happen when executing directly from the subproject dir

borkdude 2021-07-04T10:17:33.332500Z

ok, I think I fixed it on master. Could you try out a binary from master? Available in #babashka-circleci-builds in a few minutes

borkdude 2021-07-04T10:18:18.332700Z

I'll add a test for it later

borkdude 2021-07-04T10:34:01.332900Z

don't remember which os you use, bit here's a linux one: https://20537-201467090-gh.circle-artifacts.com/0/release/babashka-0.4.7-SNAPSHOT-linux-amd64.tar.gz

borkdude 2021-07-04T10:47:49.333100Z

For me at least it works locally now:

borkdude@MBP2019 /tmp $ bb -e '@(babashka.deps/clojure ["-Sforce" "-M" "-r"] {:dir "proj1"})'
Clojure 1.10.1
user=> (require 'medley.core)
nil

borkdude 2021-07-05T16:32:42.340200Z

@adam678 ok, made some more tests + fixes. I think it should be good now... https://20567-201467090-gh.circle-artifacts.com/0/release/babashka-0.4.7-SNAPSHOT-linux-amd64.tar.gz

Helins 2021-07-05T18:37:28.345600Z

@borkdude Excellent, I'll give it a go tomorrow, thanks

Helins 2021-07-06T09:11:11.359Z

Seems to work fine now, REPL starts and classpath is properly computed 🙂

borkdude 2021-07-06T09:21:22.359200Z

🎉

Helins 2021-07-03T13:20:32.310600Z

All right, using the heavy artillery then 😛

borkdude 2021-07-03T13:22:28.311300Z

Does it happen when you use (shell {:dir ...} "clojure ...") instead? if not, then it might be a bug somewhere in bb

Helins 2021-07-03T13:33:58.311700Z

It seems to work using shell, yes

Helins 2021-07-03T13:53:20.311900Z

Yep, all is perfect from what I see

borkdude 2021-07-03T13:53:49.312100Z

hmmm, can you make a repro for me? I can look into fixing it

Helins 2021-07-03T13:56:18.312300Z

Sure if I manage to reproduce it 🙂

borkdude 2021-07-03T13:56:24.312500Z

<3

borkdude 2021-07-03T13:57:25.313200Z

Haven't mentioned it here yet, but yesterday I made a CLI that exposes specter so you can use its DSL to filter/transform some EDN from stdin: https://github.com/borkdude/specter-cli/releases

borkdude 2021-07-03T15:54:30.313300Z

Is you can still reproduce it locally, it might also be a caching issue (in .cpcache)

rwstauner 2021-07-03T18:27:20.314800Z

is there a way to get the path to the currently in use babashka interpreter? something like $0? so that i could call the same bb to run a child script without needing it to be in $PATH ?

borkdude 2021-07-03T18:31:11.315Z

actually yes, let me look it up

rwstauner 2021-07-03T18:32:27.315200Z

🙇

rwstauner 2021-07-03T18:32:45.315700Z

i looked in docs and checked (System/properties) but haven't found anything yet

rwstauner 2021-07-03T18:32:53.316Z

am currently trying to discover vars in the repl 🙂

borkdude 2021-07-03T18:35:02.316400Z

@clj149

$ bb -e '(-&gt; (java.lang.ProcessHandle/current) .info .command .get)'
"/Users/borkdude/Dropbox/bin/bb"

❤️ 1
borkdude 2021-07-03T18:35:25.316700Z

Perhaps good to document somewhere

rwstauner 2021-07-03T18:35:44.317Z

:awesome: thank you!

borkdude 2021-07-03T18:37:16.317200Z

I documented it here: https://github.com/babashka/babashka/wiki/Bash-and-Babashka-equivalents#current-process-executable

😍 1
👌 1
Cora (she/her) 2021-07-03T19:34:54.318600Z

hmmm so I could combine jet with specter-cli to replace something like jq for manipulating json

borkdude 2021-07-03T19:37:21.319200Z

@corasaurus-hex You could, but jet also already has a query language and the --func option for normal Clojure functions

Cora (she/her) 2021-07-03T19:40:46.322200Z

oh! I didn't know it had that 😅

Cora (she/her) 2021-07-03T19:40:46.322300Z

does adding specter to jet make sense?

Cora (she/her) 2021-07-03T19:40:46.322400Z

I mean if making specter-cli made sense, meaning jet wasn't cutting it, does it make sense to add it to jet?

Cora (she/her) 2021-07-03T19:40:46.322500Z

it's entirely possible i'm missing loads of context here

Cora (she/her) 2021-07-03T19:40:46.322600Z

both are extremely cool

Cora (she/her) 2021-07-03T19:41:44.323700Z

I just really can't wrap my head around jq's language for some reason

Cora (she/her) 2021-07-03T19:41:56.324200Z

I have really really tried

borkdude 2021-07-03T19:42:46.325200Z

Same here, that's why I just use jet with either --query or --func. I don't know yet about adding specter to jet, I actually am not that experienced with it, but someone in the #sci wanted it to use together with sci, so I made it work for that reason

Cora (she/her) 2021-07-03T19:43:18.325500Z

ohhh I see

borkdude 2021-07-03T19:43:18.325600Z

it seems like a good candidate

Cora (she/her) 2021-07-03T19:43:29.325800Z

makes sense

Cora (she/her) 2021-07-03T19:44:38.327700Z

I ought to sell my team on jet vs jq. we're a clojure shop anyways and our mildly complicated jq is basically unmaintaintable

borkdude 2021-07-03T19:45:24.328200Z

cool. sometimes I also just use bb for json. some people have aliases for that (https://twitter.com/quoll/status/1401141320010420232)

borkdude 2021-07-03T19:46:35.328900Z

I think @nate also shared one back in the early days where you could provide an expression, it's not so hard to figure out

borkdude 2021-07-03T19:47:56.329100Z

oh I found something: https://twitter.com/ndj/status/1249505127729213441

borkdude 2021-07-03T19:48:39.329400Z

and then I shared another one here: https://twitter.com/borkdude/status/1249818512295632897

Cora (she/her) 2021-07-03T19:49:57.330400Z

a collection of jet & bb one-liners would be really cool

Cora (she/her) 2021-07-03T19:50:02.330700Z

especially aliases

borkdude 2021-07-03T19:50:24.331100Z

what you can also do instead of aliases is make an executable bb script and dump that in a bin folder

Cora (she/her) 2021-07-03T19:50:47.331600Z

I have one of those for symlinking my dotfiles

borkdude 2021-07-03T21:45:31.331700Z

@adam678 I was able to reproduce it: https://github.com/babashka/babashka/issues/914

borkdude 2021-07-03T21:46:23.332100Z

This happens because the clojure task is a 2 step process: 1) deps resolved using tools.deps.alpha, 2) the actual clojure JVM process. But the options currently only apply against the second step where the process is launched.