Fork me on GitHub
#babashka
<
2020-07-30
>
cfleming07:07:16

A few people have reported that Cursive can’t connect to the babashka REPL, because it tries to do some things (mostly around completion) that aren’t supported. Is there any way that I can detect on connection that I’m connected to babashka and not Clojure? Is there a *babashka-version* var or anything like that?

vlaaad07:07:07

I was about to suggest a workaround to make cursive chill out about the remote process, but then I noticed who’s the author of the question 😄

cfleming07:07:30

Haha, I’m interested in workarounds too 🙂

vlaaad07:07:04

https://github.com/mfikes/tubular create local repl configuration (using clojure.main) that calls tubular main that connects to remote repl

cfleming07:07:31

Oh right, and using a socket REPL.

vlaaad07:07:07

cursive thinks it’s local repl and just sends forms to it, while in reality we pipe those forms from dummy jvm process to our remote target

cfleming07:07:10

If I can detect that I’m connecting to babashka, then I can make Cursive’s socket REPL work with it too.

vlaaad07:07:39

I think @borkdude did something related to reader conditionals

vlaaad07:07:04

like support for #?(:bb "I'm in bb!") or something…

cfleming07:07:28

Looks like I could also test for the presence of some of the babashka namespaces too, like babashka.classpath.

vlaaad08:07:55

ah, maybe you need to enable that explicitly…

cfleming08:07:57

Yeah, I see that in the doc. So something like (def babashka? #?(:bb true :clj false))

borkdude08:07:28

There's also a system property to check the babashka version: https://github.com/borkdude/babashka#system-properties To sum up, you can do this with reader conditionals, check for babashka.classpath namespace or check the system property, all valid ways

borkdude11:07:13

Got the Windows build for bb working on my dev machine:

PS C:\Users\borkdude> Measure-Command { bb -e "(+ 1 2 3)"  | Out-Default }
6


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 23
Ticks             : 236056
TotalDays         : 2.73212962962963E-07
TotalHours        : 6.55711111111111E-06
TotalMinutes      : 0.000393426666666667
TotalSeconds      : 0.0236056
TotalMilliseconds : 23.6056

👍 6
borkdude11:07:02

PS C:\Users\borkdude> bb -e "(System/getProperty \`"os.name\`")"
"Windows 10"

dharrigan12:07:58

Hi - just a small thing, perhaps worth noting? In the first example on the babashka github website, here ls | bb -i '(filter #(-> % io/file .isDirectory) *input*)', that will return () (I was wondering why, did I break something - yes sorta) - it's because ls is aliased in my shell

dharrigan12:07:18

❯ which ls        
ls: aliased to ls --color=always

dharrigan12:07:26

❯ ls | bb -i '(filter #(-> % io/file .isDirectory) *input*)'
()

dharrigan12:07:43

this, works naturally, if one uses the full path /usr/bin/ls | bb -i '(filter #(-> % io/file .isDirectory) *input*)'

dharrigan12:07:02

So, perhaps a little gotcha that may throw some people trying out bb for the first time 🙂

borkdude12:07:31

Maybe a different example from ls would be even better.

dharrigan13:07:12

Well, it still can be used, if it is escaped 🙂

dharrigan13:07:34

i.e., \ls ..... or "ls" ....

dharrigan13:07:04

that will ensure anyone who has aliased ls, when running the example, will force the unaliased version to be used 🙂

dharrigan13:07:32

It's a good example, quick and easy, just a little gotcha.

onetom14:07:44

i would really like to see an up to date babashka version accessible via the nix package manager (https://nixos.org/download.html), which works on both macOS and linux. if anyone else is into using nix or wants to get into it, im more than happy to hop on a https://screen.so screen sharing session and demo how im using it or i can help to debug issues on your setup. (the documentation is a bit hidden on that download page under the More... tab, so here is a direct link, if you want to give it a quick try: https://nixos.org/nix/manual#chap-quick-start it won't interfere with your system at all, because it puts everything under a /nix/ directory, so don't worry about trying it out.)

cfleming20:07:56

Following on from my question yesterday, is there a reliable way to tell that a particular file is intended for babashka? Obviously I could look for the shebang and try to work out if it indicates bb, but that might not always be there. babashka scripts will probably need special handling in Cursive.

cfleming21:07:14

Is it common to write babashka scripts that are also intended to be used as plain Clojure?

isak21:07:13

> is there a reliable way to tell that a particular file is intended for babashka? I don't think so, because it seems like he is trying to make more and more Clojure libraries just work as is

Adrian Smith21:07:50

Is it possible to use babashka with honeysql I've tried: bb -f hello.clj -cp \"(clojure -Sdeps '{:deps {honeysql {:mvn/version "1.0.444"}}}' -Spath)\" but when I try and require (require '[honeysql.format :refer :all]) it says "Could not require honeysql.format"

Adrian Smith21:07:09

*command-line-args* prints (-cp "src:/Users/adriansmith/.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1.jar:/Users/adriansmith/.m2/repository/honeysql/honeysql/1.0.444/honeysql-1.0.444.jar:/Users/adriansmith/.m2/repository/org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar:/Users/adriansmith/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar")

borkdude07:07:51

Yes, honeysql does work with babashka. Also this works on my machine:

bb -f hello.clj -cp "$(clojure -Sdeps '{:deps {honeysql {:mvn/version "1.0.444"}}}' -Spath)"

borkdude07:07:09

Your shell syntax looks slightly different.

Adrian Smith09:07:11

yeah I use fish by default, it seems like using bash makes no difference:

borkdude09:07:32

Can you print what bb --version gives?

Adrian Smith10:07:59

babashka v0.0.25 ah that definitely doesn't seem right

borkdude10:07:47

probably an old version on the path

Adrian Smith10:07:33

yep brew link cleared that up thank you

roklenarcic10:07:43

Yeah I’m having a similar problem. I have a deps project with 1 dependency;

hickory                      {:mvn/version "0.7.1"}
And my script contains one line: `
(ns parse (:require [hickory.core :as hickory]))
And I run the script as such:
bb --classpath $(clojure -Spath) -m parse
clojure.lang.ExceptionInfo: Unable to resolve classname: org.jsoup.Jsoup [at hickory/core.clj, line , column ]
So the hickory dependency is visible, but its dependency isn’t. I’ve checked the clojure -Spath output and I see that Jsoup jar is in the classpath… I am at a loss at what I’m doing wrong. babashka v0.1.3

borkdude10:07:48

@U66G3SGP5 That's a different problem. You can't run arbitrary deps with babashka, especially not those who bring in Java dependencies

borkdude10:07:57

Take a look here of what's tested: https://github.com/borkdude/babashka/blob/master/doc/libraries.md If you want hickory/Jsoup-ish stuff, take a look at the babashka pods, also listed there.