Fork me on GitHub
#babashka
<
2021-05-01
>
mike_ananev14:05:48

@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_ananev14:05:12

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

borkdude14:05:57

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.

borkdude14:05:47

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.

borkdude14:05:15

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_ananev14:05:58

it is Idea + Cursive + format code in Cursive

borkdude14:05:46

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

ericdallo15:05:20

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

ericdallo15:05:26

but it'd be a cool feature indeed

lread17:05:51

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?

ericdallo17:05:36

it would be great to have this on cljfmt 😄

lread17:05:23

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.

👍 3
borkdude14:05:11

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

mike_ananev15:05:34

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

greglook15:05:17

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

borkdude15:05:29

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

mike_ananev15:05:14

or just add to .cljstyle

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

mike_ananev15:05:32

in :files section

greglook15:05:32

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

borkdude15:05:46

eh, formatting? :)

greglook15:05:15

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

borkdude15:05:28

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)

greglook15:05:39

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

borkdude15:05:14

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?

greglook15:05:29

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

greglook15:05:49

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

borkdude15:05:21

it seems you are not actually using tools.reader directly

borkdude15:05:39

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

mike_ananev15:05:45

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

borkdude15:05:35

@U8XJ15DTK 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?

greglook15:05:32

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

borkdude15:05:52

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

borkdude15:05:09

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

borkdude16:05:15

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

greglook16:05:11

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

borkdude16:05:05

I can make a temporary fork to run meanwhile :)

borkdude16:05:38

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

borkdude18:05:19

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

lread20:05:36

Yeah @U8XJ15DTK 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.

borkdude18:05:26

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?

borkdude18:05:53

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

borkdude18:05:53

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

mike_ananev19:05:38

@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.

borkdude19:05:56

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

borkdude19:05:23

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

borkdude20:05:19

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

mike_ananev20:05:44

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

mike_ananev20:05:28

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

mike_ananev20:05:02

this will download my template and create lib02 folder

mike_ananev20:05:29

bb.edn there contains format task

mike_ananev20:05:16

it doesn't matter what :task body contains.

mike_ananev20:05:31

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

borkdude20:05:52

ok, can reproduce, I'll take a look

borkdude20:05:40

@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>))

borkdude20:05:22

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

borkdude20:05:41

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

borkdude20:05:50

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

mike_ananev20:05:05

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

👍 3
mike_ananev20:05:34

interesting feature - intersecting names of tasks and core functions

borkdude20:05:02

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

borkdude20:05:18

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.

borkdude20:05:07

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"

borkdude20:05:01

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.

mike_ananev20:05:34

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

👍 3