babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
vlad_poh 2021-03-13T04:21:57.194600Z

Hi y'all how do i use babashka in calva?

djblue 2021-03-13T04:45:54.194700Z

Babashka has an nrepl server you can connect to for interactive development

djblue 2021-03-13T04:49:50.194900Z

--nrepl-server      Start nREPL server. Specify port (e.g. 1667) or host and port separated by colon (e.g. 127.0.0.1:1667).

đź‘Ť 1
1
❤️ 1
djblue 2021-03-13T04:50:04.195100Z

Does that help?

vlad_poh 2021-03-13T05:23:11.195300Z

ooo cool thanks

2021-03-13T14:40:40.198600Z

Can anyone point me to a minimal example on how to use babashka as org-babel clojure backend for .org code blocks in emacs? (or is this a bad idea)?

p-himik 2021-03-13T15:10:48.200500Z

I decided to rewrite one of the bash scripts in babashka. The problem: it reads environment variables from a .env file in CWD. I came up with this:

#!/usr/bin/env bash

":" ; set -a
":" ; . .env
":" ; set +a
":" ; exec bb "$0" "$@"
":" ; exit

(require '[babashka.process :as p]
         '[clojure.string :as str])

;; The script continues.
Is it reasonable? Is there a better way?

borkdude 2021-03-13T15:23:00.200800Z

@p-himik that's fine with me :)

p-himik 2021-03-13T15:24:08.201200Z

Thanks! And with this blessing, I shall continue on this endeavor.

borkdude 2021-03-13T15:31:29.201700Z

@p-himik This is how you can do it with bb, launching itself another time:

(require '[babashka.process :as p])

(when-not (System/getenv "continue_script")
  (-> (p/process ['bb *file*] {:inherit true
                               :env (assoc (into {} (System/getenv))
                                           "SOME_COOL_ENV_VAR" "123"
                                           "continue_script" "true")})
      p/check)
  (System/exit 0))

(println (System/getenv "SOME_COOL_ENV_VAR")) ;; 123

borkdude 2021-03-13T15:31:39.202Z

You can then even store env vars in EDN :)

p-himik 2021-03-13T15:34:51.203300Z

Right, but the issue is that that .env file is used by many other things - I can't just remove it. Maybe if I rewrite everything shell-related, but I'd like to postpone that. :)

borkdude 2021-03-13T15:35:12.203600Z

yeah, you can also just parse the .env file, not that hard

p-himik 2021-03-13T15:35:58.204500Z

Harder than I'd like. :) Comments, escape sequences, quotes, variable expansions. It's not a fixed format, alas.

borkdude 2021-03-13T15:36:06.204700Z

oh ok :)

lread 2021-03-13T19:17:59.205900Z

@borkdude do you know if the delightful babashka/fs works on Windows?

borkdude 2021-03-13T19:19:01.206400Z

it should

lread 2021-03-13T19:22:29.209Z

It might not? Not sure. Just got a failure for one of my scripts on Windows, thought it might just be my usage of fs/glob but just tried a clojure -M:test for babashka/fs on a Windows 10 virtual machine and see some failures.

borkdude 2021-03-13T19:23:15.209500Z

Can you be more specific? I currently don't have Windows-specific tests for this lib, but that sounds like a good idea

lread 2021-03-13T19:24:29.210Z

Well… there are more than a few failures…

Ran 32 tests containing 82 assertions.
9 failures, 8 errors.

lread 2021-03-13T19:25:41.210700Z

It might be easiest for you to try yourself when you find a moment.

borkdude 2021-03-13T19:26:40.211Z

omg

borkdude 2021-03-13T19:27:10.211500Z

@lee Are you using it from bb or as a JVM lib?

lread 2021-03-13T19:27:31.211900Z

JVM for current trial.

borkdude 2021-03-13T19:27:40.212100Z

are you on JVM 11? might be necessary

borkdude 2021-03-13T19:28:16.212400Z

I will try on my Windows box as well

lread 2021-03-13T19:29:04.213100Z

I ran on JDK8 on my virtual machine… will try JDK11…

lread 2021-03-13T19:31:32.213500Z

getting same number of errors/failures on JDK11

lread 2021-03-13T19:35:48.214200Z

I see some hardcoded /, but that should not matter, / works on all OSes.

borkdude 2021-03-13T19:38:14.214700Z

Can reproduce on Windows. A couple of those errors are coming from posix file permission checks, which are not available on Windows, so that is kind of expected

lread 2021-03-13T19:39:04.215Z

Ya that makes sense.

lread 2021-03-13T19:40:16.215700Z

Need any help on this one?

lread 2021-03-13T19:40:35.216100Z

I can take a peek if you like. Lemme know.

borkdude 2021-03-13T19:43:10.216800Z

Yeah, help is surely appreciated. I think we can add an appveyor config like the other projects (I think babashka.curl has one that might fit for this project well)

borkdude 2021-03-13T19:43:18.217Z

and then fix the tests

borkdude 2021-03-13T19:43:28.217300Z

let me install the appveyor thing and then we can see the tests failing

lread 2021-03-13T19:53:14.217500Z

sounds good

lread 2021-03-13T20:00:00.218100Z

hmm… I just said that / works on all OSes, but maybe not for glob path matcher(?).

lread 2021-03-13T20:02:11.218800Z

oh maybe just the matcher…

lread 2021-03-13T20:02:54.219100Z

I suppose we should thread this, might be noise for many?

borkdude 2021-03-13T20:03:43.219700Z

the spec of that glob syntax is here: True that it is different for Windows: https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#getPathMatcher(java.lang.String) Let's take it to the babashka-sci-dev channel, I'll invite you there

lread 2021-03-13T20:03:58.220Z

sounds good