babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
mike_ananev 2021-05-01T14:23:48.319900Z

@borkdude I've tried new possibilities like :init, :enter, :leave They are awesome and significantly reduced my scripts. Are they subject to change or stable in babashka?

mike_ananev 2021-05-01T14:25:12.321600Z

BTW, :private is not available in current-task (bb v0.3.7)

borkdude 2021-05-01T14:25:57.322500Z

Good to hear! Can you share your bb.edn? Everything regarding :tasks should be regarded instable, until this issue is closed: https://github.com/babashka/babashka/issues/778 :private should be available when the task is named like -foo or is explicitly marked :private. Else the private key might not be there.

mike_ananev 2021-05-01T14:26:43.323500Z

Thank you.

borkdude 2021-05-01T14:27:47.324700Z

Based on feedback things might still change, but I think we're heading into the right direction. I think in June or so it will be announced as stable.

borkdude 2021-05-01T14:38:15.325500Z

I love the layout of your bb.edn, do you do this manually or using a tool? If that is a tool, I think I need it

mike_ananev 2021-05-01T14:42:58.326100Z

it is Idea + Cursive + format code in Cursive

borkdude 2021-05-01T14:44:46.326800Z

@ericdallo Can LSP do it that neatly, aligning the values on the same column?

borkdude 2021-05-01T14:46:11.327300Z

I see that clojure-align does this somewhat for local maps, but not globally

mike_ananev 2021-05-01T15:25:34.328500Z

@borkdude you can achieve the same format using cljstyle tool. But you need to rename file extension edn to clj

greglook 2021-05-01T15:27:17.328600Z

You could also add edn to the extensions if you wanted, or set a pattern regex to match just that filename if you don’t want it to apply to all edn files. https://github.com/greglook/cljstyle/blob/main/doc/configuration.md#file-settings

borkdude 2021-05-01T15:28:29.329100Z

@greg316 Since babashka now comes with rewrite-clj, is it possible to support (a subset of) clj-style as a bb script?

mike_ananev 2021-05-01T15:29:14.329500Z

or just add to .cljstyle

:extensions #{"clj" "cljs" "edn"}

mike_ananev 2021-05-01T15:29:32.329700Z

in :files section

greglook 2021-05-01T15:29:32.329900Z

Good question; what’s the use-case for that? (cljstyle in bb)

borkdude 2021-05-01T15:29:46.330200Z

eh, formatting? :)

greglook 2021-05-01T15:30:15.330400Z

well yeah that’s what it does 😛 - more asking, why do that instead of the standalone binary?

borkdude 2021-05-01T15:30:28.330600Z

you could make cljstyle a dependency in your bb.edn and then have a format task and invoke it programmatically (e.g. on the bb.edn file itself)

greglook 2021-05-01T15:31:39.330900Z

hmm I see - it is written in such a way that you could use it as a library, but I’m not sure what would need to change to use it from bb instead of regular clojure

borkdude 2021-05-01T15:32:14.331100Z

well, bb (currently) does not expose tools.reader for example and also doesn't have the google diff tool. I'm not sure why they are used in cljstyle?

greglook 2021-05-01T15:32:29.331300Z

there’s also the cljstyle pipe command if you just wanted to shell out to it and use it on a specific block of text

greglook 2021-05-01T15:32:49.331500Z

diff is for cljstyle check printing out the diff of corrections it expects / would make with fix

borkdude 2021-05-01T15:33:21.331700Z

it seems you are not actually using tools.reader directly

borkdude 2021-05-01T15:33:39.331900Z

so if your formatting namespaces can be isolated from the rest, without bumping into these unsupported deps, it should already work

mike_ananev 2021-05-01T15:33:45.332100Z

@borkdude what is correct dependency coordinates for cljstyle to include into bb.edn?

borkdude 2021-05-01T15:34:07.332300Z

https://clojars.org/mvxcvi/cljstyle

borkdude 2021-05-01T15:37:35.332600Z

@greg316 Running into this one: > https://github.com/greglook/cljstyle/blob/main/src/cljstyle/format/zloc.clj#L9 bb doesn't expose that class (and should not have to, I think, it's an implementation detail). Are you ok with introducing a :bb reader conditional?

greglook 2021-05-01T15:38:32.332900Z

I would love to have a better way to satisfy the string? predicate it’s used in, referring directly to that class felt gross

borkdude 2021-05-01T15:39:52.333100Z

I have a couple of those predicates in clj-kondo, lemme check

borkdude 2021-05-01T15:40:09.333300Z

and there's also an issue in rewrite-clj for this \cc @lee

ericdallo 2021-05-01T15:40:20.333500Z

Yeah, to make something generic I'd prefer doing that on cljfmt as there are already issues requesting that

ericdallo 2021-05-01T15:40:26.333700Z

but it'd be a cool feature indeed

ericdallo 2021-05-01T15:41:49.333900Z

https://github.com/weavejester/cljfmt/issues/36

borkdude 2021-05-01T16:06:15.334200Z

I am looking into some other stuff to get cljstyle working, hopefully

greglook 2021-05-01T16:10:11.334400Z

Great. 🙂 I’ll be on the road for a couple weeks, but happy to look at the changes when I get back!

borkdude 2021-05-01T16:11:05.334600Z

I can make a temporary fork to run meanwhile :)

borkdude 2021-05-01T16:11:09.334800Z

have fun!

borkdude 2021-05-01T16:26:38.335Z

Now that rewrite-clj also supports CLJS I guess we could also have a cljstyle that works in the browser and nodeJS

lread 2021-05-01T17:28:51.335200Z

Ha! This was the exact cljfmt issue that sent me on my meandering trek. Now that rewrite-clj v1 is released, maybe I should get back to it, eh?

lread 2021-05-01T17:31:52.335400Z

Ya, https://github.com/clj-commons/rewrite-clj/issues/114.

ericdallo 2021-05-01T17:32:36.335800Z

it would be great to have this on cljfmt 😄

lread 2021-05-01T17:40:23.336Z

If I remember correctly, the last thing I was thinking about was how to enable/disable alignment formatting. I expect that you’d have a general preference, but then you might want to enable or disable it for certain forms? Would a clj-kondo style inline work? Something like #_{cljfmt/align ...}? Anyhoo probably wrong channel, if you want to discuss more we could start a thread in #rewrite-clj.

👍 1
borkdude 2021-05-01T18:22:58.337Z

@mike1452 @greg316 Now I'm confused. I'm finding several open issues about vertical alignment: https://github.com/greglook/cljstyle/issues/61 https://github.com/greglook/cljstyle/issues/47

borkdude 2021-05-01T18:45:19.337800Z

I believe I have cljstyle working now with babashka: https://gist.github.com/borkdude/d317308c66029452520e8bf4378be55e but it seems it just spits out the same source as it ingested all the time

borkdude 2021-05-01T18:46:26.338500Z

cljstyle with babashka: https://gist.github.com/borkdude/d317308c66029452520e8bf4378be55e But it doesn't seem to do anything useful yet. Maybe I'm using the lib wrong?

borkdude 2021-05-01T18:50:53.338900Z

Anyway, that was a rabbit hole to get vertical alignment formatting for bb.edn ;)

borkdude 2021-05-01T18:58:53.339300Z

Reasonable compromise: task name one one line, task on the next https://github.com/clj-kondo/clj-kondo.lsp/blob/master/bb.edn

mike_ananev 2021-05-01T19:48:38.341300Z

@borkdude found strange behavior (v0.3.7) If any task has name format then see this

mike@mbp02  lib02 bb format
----- Error --------------------------------------------------------------------
Type:     java.lang.IllegalStateException
Message:  Attempting to call unbound fn: #'user1/format
What it could be? if I rename task to formatt everything works fine.

borkdude 2021-05-01T19:55:56.341500Z

hmm, do you have a repro bb.edn for me?

borkdude 2021-05-01T19:57:23.341900Z

Can't repro it with this:

$ bb --version
babashka v0.3.7
$ cat bb.edn
{:tasks {format (+ 1 2 3)}}
$ bb run --prn format
6

borkdude 2021-05-01T20:05:19.342400Z

@mike1452 Perhaps you have a (def format ...) somewhere else in the task?

mike_ananev 2021-05-01T20:06:44.343200Z

hmm. Can't repro in a small file. I'll publish bigger file to gist

mike_ananev 2021-05-01T20:09:28.343600Z

clojure -X:new :template org.rssys.libtemplate :name com.example/lib02 :snapshot true

mike_ananev 2021-05-01T20:10:02.344400Z

this will download my template and create lib02 folder

mike_ananev 2021-05-01T20:10:29.345Z

bb.edn there contains format task

mike_ananev 2021-05-01T20:11:16.345700Z

it doesn't matter what :task body contains.

mike_ananev 2021-05-01T20:11:31.345900Z

if I rename task to `formatt` everything works fine.

borkdude 2021-05-01T20:11:52.346200Z

ok, can reproduce, I'll take a look

borkdude 2021-05-01T20:15:40.347800Z

@mike1452 The issue here is that your :enter expression uses format as well and the program bb creates from your task goes something like this:

(def format (do <enter> <task> <leave>))

borkdude 2021-05-01T20:16:22.348200Z

we could probably solve this by generating (let [format ...]) instead

borkdude 2021-05-01T20:16:41.348600Z

but you can resolve the ambiguity right now by using clojure.core/format

borkdude 2021-05-01T20:18:50.349200Z

or define a function in :init which uses format, :init always goes before everything else

mike_ananev 2021-05-01T20:23:24.349500Z

@borkdude thank you!

mike_ananev 2021-05-01T20:25:05.350200Z

clojure.core/format is more clojurish way. solved!

👍 1
mike_ananev 2021-05-01T20:25:34.350500Z

interesting feature - intersecting names of tasks and core functions

borkdude 2021-05-01T20:27:02.351100Z

yes, this could get confusing, but maybe also not that common?

borkdude 2021-05-01T20:28:18.352200Z

I could see two ways to solve this: 1) generate let instead of def, 2) fully qualify all symbols in the global :enter and :leave first. But perhaps it's better to wait for more "interesting" cases like this.

borkdude 2021-05-01T20:31:18.352400Z

Made an issue for it to track it: https://github.com/babashka/babashka/issues/814

borkdude 2021-05-01T20:36:07.353Z

I think the second solution is pretty straightforward to implement, like:

user=> `(format "%s" 5)
(clojure.core/format "%s" 5)
user=> (eval `(format "%s" 5))
"5"

borkdude 2021-05-01T20:41:01.353800Z

I wonder about the override in doit though:

{:tasks {:enter (load-string "`(prn (format \"%s\" 5))")
         format {:task (+ 1 2 3)}
         doit {:depends [format]
               :enter (prn (format "%s" 1))}}}
I think in the case of doit it would be reasonable to require people to use a fully qualified symbol for format, since it's pretty clear that this is conflicting. Although you might still have access to that symbol if you indirectly depend on it.

lread 2021-05-01T20:43:36.355400Z

Yeah @greg316 I was looking for inspiration from cljstyle for cljfmt on how to specify when/what forms should be vertically aligned, but did not find anything yet.

mike_ananev 2021-05-01T20:44:34.356300Z

fully qualified symbols are simple and straightforward. no complex behaviour under the hood.

👍 1