babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
onetom 2021-06-25T05:06:52.181100Z

I've just noticed that the namespace alias recommendations in https://github.com/bbatsov/clojure-style-guide#use-idiomatic-namespace-aliases are inconsistent with babashka's choices: https://book.babashka.org/#built-in-namespaces for example pp is pprint in bb, which would result in pprint/pprint (which is a bit unnecessarily long) and sh is shell in bb, which results in shell/sh. same issue; unnecessarily long for such a core operation. the other convention leads to sh/sh though, which is short, but weird because of the repetition. i wonder how has this divergence happened? were there any discussions anywhere about these choices with @bozhidar? would it be possible still to achieve a higher degree of consistency, now that babashka is already pretty mature? would it make sense to amend the clojure style guide somehow?

borkdude 2021-06-25T07:12:06.181800Z

> were there any discussions anywhere about these choices withΒ @bozhidar? I don't think we have to discuss all of our choices with bozhidar, that would take the poor man his entire week. The choices of aliases here are intented to be used on the command line and I like them to be more explicit for this reason, also not to conflict with shorter ones if you are introducing them yourself.

borkdude 2021-06-25T07:13:04.182Z

Initially babashka was used as a command line tool only (for a few weeks probably). Later on scripts were introduced. If this was there from the start, I perhaps woudln't have introduced built-in aliases at all.

onetom 2021-06-25T10:58:32.182200Z

thanks for the background! i was just asking, because this kind of differences cause tension within teams, where certain members are trying to look for some authoritative source for answers (usually outside of the team). now they can find even 2 conventions πŸ™‚ currently we only have 1 file, which runs under both clojure and babashka, so it's not a big issue yet. im starting to realize that i might have OCD and that's why such things bug me πŸ™‚

borkdude 2021-06-25T10:59:53.182400Z

when creating scripts it might be better to create your own namespace so you can decide on your own aliases and not rely on the user namespace so much

borkdude 2021-06-25T11:01:09.182600Z

which is also written here: https://book.babashka.org/#style

πŸ‘ 1
borkdude 2021-06-25T11:01:58.182900Z

it's a fair criticism but not something we can change at this point

πŸ‘ 1
borkdude 2021-06-25T21:11:00.205200Z

Btw, pprint isn't aliased at all, I see now

pithyless 2021-06-28T09:08:26.230500Z

> i was just asking, because this kind of differences cause tension within teams, where certain members are trying to look for some authoritative source for answers (usually outside of the team). now they can find even 2 conventions Slightly OT, but just as a datapoint @onetom - we internally use Nikita's "long namespace convention" in our team (and his other Readable Clojure recommendations) even though they deviate from the linked Clojure Style Guide. The longer (and consistent and codebase unique) namespace is something I have particularly learned to appreciate when reading code. Just wanted to point out that there may already be more than one source of convention. :) https://tonsky.me/blog/readable-clojure/#use-long-namespace-aliases

πŸ‘ 2
onetom 2021-06-28T09:14:55.231Z

thanks @pithyless, i was not aware of this article. I watched this presentation from tonsky, where he talks about related things: https://youtu.be/l1b7Da2DnPo and tried his alabaster theme too πŸ™‚

onetom 2021-06-25T05:09:40.181400Z

i don't have any good ideas in this regard, but i've just seen recently that some another project is following babashka's conventions. https://youtu.be/-MC0P4rj3e8?t=1002

onetom 2021-06-25T05:12:53.181600Z

it's a question of convenience mostly of course, since it's possible to have 2 aliases to the same namespace:

user=>  (require '[clojure.java.shell :as sh])
nil

user=> sh/sh
#object[babashka.impl.clojure.java.shell$sh 0x11d24ea2 "babashka.impl.clojure.java.shell$sh@11d24ea2"]

user=> shell/sh
#object[babashka.impl.clojure.java.shell$sh 0x11d24ea2 "babashka.impl.clojure.java.shell$sh@11d24ea2"]

2021-06-25T14:28:56.189300Z

Anyone running babashka from Emacs Orgmode? I was trying to find some ob-babashka, but I haven't found one. What do I want: to be able to use #+BEGIN_SRC babashka, rather than #+BEGIN_SRC clojure. It would simply use CJ syntax, but would work with the bb executable, rather than with clojure. The use-case is direct code execution (`C-c C-c`) from literate programming documents, rather than tangling. Has anyone done it already? If not, I'll probably tweak one of the existing packages, like ob-clojure.el.

borkdude 2021-06-25T14:41:40.189600Z

I think @adam.james uses something like this, you can maybe watch one of his streams

borkdude 2021-06-25T14:42:00.189800Z

or search his github profile to see if he has some public dotfiles

2021-06-25T15:11:25.190500Z

Cheers @borkdude, I will check search on his GH then!

2021-06-25T15:20:36.191700Z

Found the Emacs config https://gist.github.com/adam-james-v/7a61612ce0649afc78513f54b337d8c9, but it doesn't deal with babashka as far as I see.

borkdude 2021-06-25T15:22:25.191900Z

I'm not sure if he does bb specific stuff but he does use literate programming in org mode and clojure / babashka. He shows this on his stream. You could try to approach him on Twitter for more info.

borkdude 2021-06-25T15:23:10.192100Z

I think he's just connected to a babashka nREPL server and from that perspective it doesn't matter which version of clojure you use

πŸ‘ 1
2021-06-25T16:01:20.193700Z

you need ob_babashka. Just use ob_clojure as a starting-point

2021-06-25T16:01:38.193900Z

it’s not that much work

2021-06-25T17:47:42.195900Z

@borkdude yeah I'd guess that's what he's probably doing. Still, given the nature of babashka, I'm more interested in running one-off things, glue code, not really something that I'd bother with REPL for (unlike in a larger project of course).

2021-06-25T17:48:11.196900Z

@hkjels yeah I think so. I already checked the code for other languages, looks pretty straighforward.

adam-james 2021-06-25T18:19:30.197100Z

Haha, everyone called my shots πŸ˜‰ I don't often do code eval inline and basically send s-exprs to the REPL. but, I did try this just now:

adam-james 2021-06-25T18:19:45.197300Z

https://gist.github.com/adam-james-v/f4d2b75a70b095d14a351a1eff96b4b0

πŸ‘ 1
adam-james 2021-06-25T18:20:15.197500Z

It's a very basic modification of ob-clojurescript. Though, at the moment I have only tested a few basic evals.

2021-06-25T19:25:37.197900Z

Awesome, thaks @adam.james!

hairfire 2021-06-25T20:47:31.201600Z

Is there a clever way to create help from the ":doc" data in the ":tasks" map in a bb.edn file?

Vishal Sachdev 2021-06-25T20:47:52.201800Z

Hi, hope this is the right place to ask.. but I can't seem to access pprint in expression mode, but I can access it when using the repl. Like here -> https://asciinema.org/a/422396

Vishal Sachdev 2021-06-25T20:49:28.202500Z

I just installed babashka, so I'm not sure if I'm missing some setup? I'm using arch linux and installed the official package

2021-06-25T20:51:36.202600Z

I create a separate :usage key and then use that to check required arguments are given for a task - https://github.com/cldwalker/bb-clis/blob/9ba19aa9beee9c85ed1ac2eb98e24cad992afc9a/bb.edn#L9-L23

βœ… 1
borkdude 2021-06-25T21:09:19.203600Z

@vishalsachdev199 in the REPL, some vars are automatically referred, like in the normal clojure REPL

borkdude 2021-06-25T21:09:43.204200Z

In "expression" mode you can use clojure.pprint/pprint fully

Vishal Sachdev 2021-06-25T21:10:55.205Z

Ah... got it.

Vishal Sachdev 2021-06-25T21:11:09.205500Z

Thanks for the help

borkdude 2021-06-25T21:11:40.205900Z

When writing scripts it's recommended to use require explicitly (you'll get better linting from clj-kondo for example)

Vishal Sachdev 2021-06-25T21:16:51.208Z

Yeah, the namespace and function having the same name tripped me over. clojure.pprint is available as pprint so I should've used pprint/pprint in the expression mode, but I kinda missed the namespace part. Funny because I was using json/parse-string fine in the same expression.

borkdude 2021-06-25T21:18:48.208400Z

clojure.pprint isn't aliased as pprint by default

borkdude 2021-06-25T21:19:35.209Z

there are some pre-defined aliases like json but it's not done for every available namespace in bb

hairfire 2021-06-25T21:46:51.209700Z

Here's what I came up with for a babashka "help" task:

help               {:task (let [docs (->> (slurp "bb.edn")
                                         edn/read-string
                                         :tasks
                                         vals
                                         (filter map?)
                                         (map :doc)
                                         (filter identity))]
                              (doseq [doc docs]
                                (println (str "\n" doc)))
                              (println))}

hairfire 2021-06-25T21:47:27.210100Z

Here's an example non-help task:

run-lein           {:doc  "run-lien: Executes 'lien run'"
                      :task (apply shell "lein" "run" *command-line-args*)}

borkdude 2021-06-25T21:48:19.210900Z

@hairfire Any reason to not just use bb tasks for this? It does almost the same as your help task

hairfire 2021-06-25T21:51:10.211600Z

I'll give it a try. Can you point me to the docs for "bb tasks"? I looked around, but did not run across this.

borkdude 2021-06-25T21:51:54.212100Z

Just run it on the command line and you'll see what happens

hairfire 2021-06-25T21:52:12.212600Z

bb tasks will be just fine. Anyway to alias it to "help", just because my users are more likely to try help

borkdude 2021-06-25T21:53:01.213400Z

If you type bb --help you see the docs for it:

Tasks:

  tasks       Print list of available tasks.
(it prints it with the docstrings)

hairfire 2021-06-25T21:53:31.214100Z

is "bb tasks" documented in http://book.babashka.org? I didn't see it while looking around for it.

borkdude 2021-06-25T21:53:34.214300Z

aliasing it as help will override bb's own help :) -- although you can always get to the built-in options using double dashes as well

borkdude 2021-06-25T21:54:06.214500Z

yes, it's documented here: https://book.babashka.org/#_discoverability

hairfire 2021-06-25T21:57:06.215500Z

Thanks for gracefully tolerating my ignorance :face_with_rolling_eyes:

borkdude 2021-06-25T21:58:26.215700Z

oh no problem at all, I hope you had fun :)

😬 1
borkdude 2021-06-25T22:04:34.216500Z

@hairfire if you want to disable some tasks showing up in the bb tasks output, you can make a task "private" by starting the name with a dash

borkdude 2021-06-25T22:04:48.216800Z

e.g -helper-task ...

hairfire 2021-06-25T22:05:57.217Z

Cool!

adam-james 2021-06-25T23:39:40.217300Z

Last ping here. I have updated the gist to properly provide 'babashka-mode'. It is just a derived mode using clojure-mode as the base. This is necessary to get font-locking in babashka blocks. Font locking is syntax highlighting and indentation, in case you didn't know (I didn't know myself until I looked it up). edit: adding link https://gist.github.com/adam-james-v/f4d2b75a70b095d14a351a1eff96b4b0