babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
Eamonn Sullivan 2021-01-31T13:39:11.216700Z

Hi, complete newby here. I've decided to explore this one whole babashka thing that I hear so many great things about. I'm a (maybe) advanced beginner (at best) on Clojure and I'm going to try this afternoon to rewrite my very crufty bash backup script into something more fun to maintain and change. But what do you people use for tooling? I tried to create a backup.clj file in emacs and my Clojure set up kicked in, with clojure-lsp complaining about the 35,000+ files in this "project" (i.e., my home directory). I then tried to use clojure -X:new ... to create a simple small deps.edn project to work in, so I'd get all the niceness of CIDER, but the syntax is a bit different, isn't it, for things like imports and requires. How do people generally write these? Do you write them first in Clojure (or ClojureScript) and then make the last-minute adjustments?

borkdude 2021-01-31T13:42:56.217500Z

@eamonn.sullivan The simplest way to get started is just write a script.clj with a shebang or just execute it with bb script.clj

borkdude 2021-01-31T13:43:20.217800Z

The syntax for babashka is exactly the same as clojure

borkdude 2021-01-31T13:44:00.218700Z

To get going maybe read https://book.babashka.org/#usage

Eamonn Sullivan 2021-01-31T13:44:28.219200Z

OK, so I just be mostly OK working in Clojure (to use Cider and LSP) and then adding the shebang at the end, to make it stand-alone?

Eamonn Sullivan 2021-01-31T13:44:53.219700Z

Ah, I will have a read of the manual too!

borkdude 2021-01-31T13:45:14.220100Z

#!/usr/bin/env bb
(println "Hello world!")

Eamonn Sullivan 2021-01-31T13:48:41.222700Z

Yes, I got that far fairly quickly from the examples. And I got it kind of working in a short period of time. What I'm running into is that when I open the bb script in Emacs to edit it, my configuration gets confused. I have so many things set up to start when the extension in the buffer ends in *.clj, and those don't expect to work with a shell script. Clojure-lsp is trying to find the project definition, for example.

borkdude 2021-01-31T13:49:49.223800Z

I think that might be good to mention in the #lsp channel. LSP should support scripts. You can write standalone scripts in JVM clojure too. cc @ericdallo

borkdude 2021-01-31T13:51:27.224600Z

I think @pez also asked about this once (he is the originating author of Calva, which is now also using clojure-lsp)

borkdude 2021-01-31T13:51:46.224900Z

Anyway, maybe for now you can turn lsp off 🤷

borkdude 2021-01-31T13:53:47.225800Z

@eamonn.sullivan Just clojure-mode and clj-kondo should be good enough for babashka, for small scripts. Babashka also supports a REPL, but for small scripts I find it sufficient to just run it from the terminal each time

Eamonn Sullivan 2021-01-31T13:54:27.226200Z

:thumbsup: Giving it a go now.

pez 2021-01-31T14:12:12.232200Z

Something has changed in clojure-lsp since I asked about that. Now it just works. I have code navigation, documentation lookup, outline, clj-kondo linting, … the lot, when opening my babashka scripts, even though they have shebangs. I start bb with the --nrepl-server and enjoy the REPL workflow I am used to after connecting Calva. At the end of some “entry” scripts I have check if it is running as a script or in the repl. That is mainly so that loading the file in the REPL is a way to perform some basic smoke testing.

borkdude 2021-01-31T14:13:14.232500Z

Hmm, maybe that got fixed in LSP then. Maybe upgrade @eamonn.sullivan?

pez 2021-01-31T14:17:56.234600Z

It is so sweet I have a hard time fathoming it. Maybe babashka is about to position itself as Clojure’s killer app? It is hard to see who, in their right mind, and after some carefully designed introduction, would choose to script in anything but babashka.

5💯1💖
Eamonn Sullivan 2021-01-31T14:21:11.236300Z

Yeah, I literally just discovered (from the aforementioned manual) bb --nrepl-server and now have a full cider/lsp experience. Very nice! Thanks again for this. I might never write another bash script.

1☝️
ericdallo 2021-01-31T15:44:52.237700Z

Cool, this should work with lsp indeed, we support both project and single file clojure code, any issues LMK in #lsp :)

Eamonn Sullivan 2021-01-31T20:48:40.241400Z

Hi, all, a question: I'm writing my first babashka script and I'd like to write some tests for it. I think I've followed the instructions in the babashka book about my project structure/test_runner, but I'm getting a strange error when I try to redefine a function in the script using with-redefs: clojure.lang.ExceptionInfo: Method format on class sci.impl.fns$fun$arity_0__16223 not allowed! . My repo is here: https://github.com/eamonnsullivan/backup-scripts. I'm just trying to write my first, simple test around date handling before I tackle some of the harder ones. Can anyone spot my simple mistake?

borkdude 2021-01-31T21:00:06.242100Z

@eamonn.sullivan The reason you are getting this error is that you are re-defining date as a function in your tests, while in your normal code it's a date, not a function

Eamonn Sullivan 2021-01-31T21:04:00.242300Z

Doh! Thanks. It's too late to still be working on this...

borkdude 2021-01-31T21:06:09.242500Z

No worries, the error message is a bit cryptic here

borkdude 2021-01-31T22:20:20.244300Z

Added lots of functions to babashka.fs today. You can already use this lib as a git lib and it's built into bb in the fs branch (see #babashka_circleci_builds or visit the builds via Github). I want to wait on some feedback for a while before it will end up in babashka. Please test and review! https://github.com/babashka/fs#usage API docs: https://babashka.org/fs/

4🚀