@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?
BTW, :private
is not available in current-task
(bb v0.3.7)
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.
Thank you.
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 old version https://github.com/redstarssystems/rssyslib/blob/develop/resources/clj/new/rssyslib/bb.edn new version https://gist.github.com/mikeananev/c87c1596aed50b7bb095a816f6921737
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
it is Idea + Cursive + format code in Cursive
@ericdallo Can LSP do it that neatly, aligning the values on the same column?
I see that clojure-align
does this somewhat for local maps, but not globally
@borkdude you can achieve the same format using cljstyle
tool. But you need to rename file extension edn
to clj
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
@greg316 Since babashka now comes with rewrite-clj, is it possible to support (a subset of) clj-style as a bb script?
or just add to .cljstyle
:extensions #{"clj" "cljs" "edn"}
in :files section
Good question; what’s the use-case for that? (cljstyle in bb)
eh, formatting? :)
well yeah that’s what it does 😛 - more asking, why do that instead of the standalone binary?
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)
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
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?
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
diff is for cljstyle check
printing out the diff of corrections it expects / would make with fix
it seems you are not actually using tools.reader directly
so if your formatting namespaces can be isolated from the rest, without bumping into these unsupported deps, it should already work
@borkdude what is correct dependency coordinates for cljstyle to include into bb.edn?
@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?
I would love to have a better way to satisfy the string?
predicate it’s used in, referring directly to that class felt gross
I have a couple of those predicates in clj-kondo, lemme check
and there's also an issue in rewrite-clj for this \cc @lee
Yeah, to make something generic I'd prefer doing that on cljfmt as there are already issues requesting that
but it'd be a cool feature indeed
I am looking into some other stuff to get cljstyle working, hopefully
Great. 🙂 I’ll be on the road for a couple weeks, but happy to look at the changes when I get back!
I can make a temporary fork to run meanwhile :)
have fun!
Now that rewrite-clj also supports CLJS I guess we could also have a cljstyle that works in the browser and nodeJS
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?
it would be great to have this on cljfmt 😄
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.
@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
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
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?
Anyway, that was a rabbit hole to get vertical alignment formatting for bb.edn ;)
Reasonable compromise: task name one one line, task on the next https://github.com/clj-kondo/clj-kondo.lsp/blob/master/bb.edn
@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.hmm, do you have a repro bb.edn for me?
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
@mike1452 Perhaps you have a (def format ...)
somewhere else in the task?
hmm. Can't repro in a small file. I'll publish bigger file to gist
clojure -X:new :template org.rssys.libtemplate :name com.example/lib02 :snapshot true
this will download my template and create lib02
folder
bb.edn
there contains format
task
it doesn't matter what :task body contains.
if I rename task to `formatt` everything works fine.
ok, can reproduce, I'll take a look
@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>))
we could probably solve this by generating (let [format ...])
instead
but you can resolve the ambiguity right now by using clojure.core/format
or define a function in :init
which uses format
, :init
always goes before everything else
@borkdude thank you!
clojure.core/format
is more clojurish way. solved!
interesting feature - intersecting names of tasks and core functions
yes, this could get confusing, but maybe also not that common?
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.
Made an issue for it to track it: https://github.com/babashka/babashka/issues/814
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"
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.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.
fully qualified symbols are simple and straightforward. no complex behaviour under the hood.