babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
ABeltramo 2021-02-04T08:56:37.301900Z

Hello guys, can someone help me setting up Intellij + cursive with babashka? I can't get it to recognise dependencies. Do I have to create a dummy lein project with babashka as a dependency to make it work?

borkdude 2021-02-04T08:57:35.302700Z

@beltramo.ale If you want auto-completion things and have Cursive analyze the dependencies then probably it's enough to add a deps.edn with the deps you are using in your script(s)

ABeltramo 2021-02-04T09:00:50.305100Z

Thanks, I'll try that! How does it play with pods? I would like to use lispyclouds/docker but my guess is that (require '[pod.lispyclouds.docker :as docker]) will never be accepted by cursive because the dependency from clojure should be: [clj-docker-client.core :as docker] .

borkdude 2021-02-04T09:01:33.305800Z

@beltramo.ale If you use the babashka nREPL server you can get auto-completions for this, but pods aren't dependencies that can easily be statically analyzed

ABeltramo 2021-02-04T09:02:56.306600Z

Right, I see.. Is there a better IDE for developing babashka scripts? What do you guys use then?

Eamonn Sullivan 2021-02-04T09:30:17.310200Z

I'm trying to run an nrepl (`bb --nrepl-server 1667`) with cider in emacs. This seems to work fine, usually, but this morning the repl just dies silently when I try to eval a buffer. I'm sure it's just an error in my code, but I don't get any error messages (either on the bb side, nor on the cider side). Is there a way to see what's going wrong? I tried --verbose with no result.

Eamonn Sullivan 2021-02-04T09:34:56.310400Z

Ah, I see what's happening. I'm trying to eval the whole buffer, so it's running the code and spitting out a usage message (i.e., because I don't have the required args). I didn't spot that amidst the "closed unexpectedly" message from cider.

Eamonn Sullivan 2021-02-04T09:35:02.310600Z

Nevermind me.

borkdude 2021-02-04T09:47:17.310900Z

I use emacs

borkdude 2021-02-04T09:48:41.311800Z

@beltramo.ale Developing bb scripts should not require a lot from an editor. Just paredit + syntax highlighting maybe. Bb scripts start so fast that you usually barely need a REPL, although many people do prefer one.

borkdude 2021-02-04T09:49:37.312400Z

If IntelliJ / Cursive gives you trouble for developing a script, maybe discuss it with the author to add better support for it.

solf 2021-02-04T09:50:32.313800Z

Here's the commands I made to spawn and connect to a babashka repl, from emacs/CIDER: https://gist.github.com/llacom/f391f41cbf4de91739b52bf8bb1a6d54

solf 2021-02-04T09:51:05.315100Z

I meant to improve them before sharing, but never took the time. It works for me at least :man-shrugging:

ABeltramo 2021-02-04T09:51:20.315400Z

Yeah I just saw https://github.com/cursive-ide/cursive/issues/2452 the issue is that since it can't recognise imports just set everything as errors and it's unusable. I'm trying calva and it seems to do the trick. Thanks for the help, and the amazing work behind Babashka!

pez 2021-02-04T10:02:08.318800Z

Calva uses both clojure-lsp and nrepl for the completions. And clojure-lsp also makes a lot of other features available. You can probably get a lot of the similar experience in Emacs using CIDER + lsp-mode. But with Calva it is out-of-the-box. Not possible to opt-out, even . 😃

Mno 2021-02-04T10:26:43.319900Z

“Oh no I can’t opt out of this very helpful feature”. Now that’s the kind of problems I want.

borkdude 2021-02-04T10:29:05.320600Z

I think it's good to have opinions (defaults), but not to be stubborn: always give people a way out, unless your tool can't function without it

2021-02-04T12:13:33.321700Z

It might not be the right place, but is there any magic trick to have pprint with cider using bb --nrepl-server ?

borkdude 2021-02-04T12:13:53.321900Z

@neo2551 There is an open PR for this in babashka.nrepl which is currently stalled. Maybe you could help out by reading the issue and seeing what remains to be done.

borkdude 2021-02-04T12:15:19.322400Z

I think it's more or less done

2021-02-04T12:15:21.322500Z

Thanks! I believe you are too nice with respect to my skills!

2021-02-04T12:15:43.323Z

But I will give a shot tomorrow.

2021-02-04T12:15:59.323500Z

Thanks for pointing me out to the solutoin.

borkdude 2021-02-04T12:16:10.323700Z

https://github.com/babashka/babashka.nrepl/pull/33

grazfather 2021-02-04T15:00:36.324Z

Should that cause the nrepl to crash, though?

Eamonn Sullivan 2021-02-04T15:02:17.324200Z

Nah, just exit normally, with a usage. Cuz that's what I asked it to do. I rewrote the script to have a -main function and then did something like this

(when (= *file* (System/getProperty "babashka.file"))
  (-main))
So now I can eval the whole buffer and use the functions, but the script itself doesn't run.

grazfather 2021-02-04T15:02:51.324400Z

Is the issue just the pprint-fn where with-out-str should wrap it?

grazfather 2021-02-04T15:03:18.324600Z

as in, the only remaining one? I can’t push to his branch and it would be a shame to have to open a new PR and lose the review history just to fix that one thing. Can you push on his branch?

grazfather 2021-02-04T15:03:56.324800Z

Ah, makes sense

borkdude 2021-02-04T15:04:46.325Z

I can merge his PR to a branch and then you can open a new PR to that branch

grazfather 2021-02-04T15:06:56.325200Z

I can do that

grazfather 2021-02-04T15:07:13.325400Z

or i can open a new PR, your preference of course

grazfather 2021-02-04T15:08:04.325600Z

if you remember, I only saw babashka yesterday, so getting set up with sci and everything might take me some time

grazfather 2021-02-04T15:08:18.325800Z

I just wanted to encourage the PR to not die 🙂

borkdude 2021-02-04T15:21:11.326Z

@grazfather I merged to the pprint branch now. Feel free to continue with a new PR on that branch

borkdude 2021-02-04T15:21:30.326200Z

I made a few comments in the old PR which have not been processed yet. Notable the one about *out*

👍 1
Eamonn Sullivan 2021-02-04T17:18:49.331700Z

So, I finished my first moderately-sized https://github.com/eamonnsullivan/backup-scripts/blob/master/src/eamonnsullivan/backup.clj. It will probably make any competent babashka user's eyes bleed, is basically a translation of a bash script, but it was fun to do. I originally had more actual Clojure (as opposed to calls to clojure.java.shell) in it, but I stripped that back after I basically wiped a PC while trying to test it. 😮 (The problem turned out to be an incorrect exclude to rsync, so I was copying over a symlink to / and when I tried to remove the directory using pure and naive Clojure, it went down that rabbit hole.) I am definitely hooked!

👍 4
borkdude 2021-02-04T17:22:08.333300Z

@eamonn.sullivan Looks like a legit script to me! Great job and hope you have recovered from your disk erasure well

grazfather 2021-02-04T23:26:24.334Z

it’s merged in now! just update your bb