Fork me on GitHub
#babashka
<
2021-03-13
>
vlad_poh04:03:57

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

djblue04:03:54

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

djblue04:03:50

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

đź‘Ť 4
calva 4
❤️ 3
djblue04:03:04

Does that help?

vlad_poh05:03:11

ooo cool thanks

mmz14:03:40

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-himik15:03:48

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?

borkdude15:03:00

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

p-himik15:03:08

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

borkdude15:03:29

@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

borkdude15:03:39

You can then even store env vars in EDN :)

p-himik15:03:51

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. :)

borkdude15:03:12

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

p-himik15:03:58

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

lread19:03:59

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

lread19:03:29

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.

borkdude19:03:15

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

lread19:03:29

Well… there are more than a few failures…

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

lread19:03:41

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

borkdude19:03:10

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

lread19:03:31

JVM for current trial.

borkdude19:03:40

are you on JVM 11? might be necessary

borkdude19:03:16

I will try on my Windows box as well

lread19:03:04

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

lread19:03:32

getting same number of errors/failures on JDK11

lread19:03:48

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

borkdude19:03:14

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

lread19:03:04

Ya that makes sense.

lread19:03:16

Need any help on this one?

lread19:03:35

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

borkdude19:03:10

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)

borkdude19:03:18

and then fix the tests

borkdude19:03:28

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

lread19:03:14

sounds good

lread20:03:00

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

lread20:03:11

oh maybe just the matcher…

lread20:03:54

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

borkdude20:03:43

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

lread20:03:58

sounds good