babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
borkdude 2021-04-02T10:52:14.334Z

New Youtube video! bb 0.3.1 new features: - bb.edn - run any function as a main function https://youtu.be/_zr1dicJs-E

πŸš€ 3
2021-04-02T11:50:21.334200Z

Awesome, definitely want to use it for my build tasks. For small projects these cmdline invocations usually end up in my README. For larger projects I normally automate it in a build file (like MAKE indeed) ... In both cases I'd prefer to have the tasks as executable clojure code on my machine πŸ™‚

πŸŽ‰ 1
grazfather 2021-04-02T12:11:08.334600Z

You’re a machine

grazfather 2021-04-02T12:20:41.335100Z

What do you think about suppressing full stack traces for errors, with maybe -v to get around?

grazfather 2021-04-02T12:21:31.335700Z

bb doc ~/x spews a huge stack trace, for example

borkdude 2021-04-02T13:25:02.336500Z

@grazfather usually users should not see an entire stacktrace unless they use --verbose, so feel free to post an issue for doc, it should handle it better

grazfather 2021-04-02T13:27:27.336700Z

sure

grazfather 2021-04-02T13:30:09.336900Z

https://github.com/babashka/babashka/issues/770

borkdude 2021-04-02T13:30:52.337200Z

tnx

grazfather 2021-04-02T13:45:38.337400Z

np

ericdallo 2021-04-02T14:06:01.337600Z

Hey, really nice video! Does this version supports getting the classpath/deps via a bb command?

borkdude 2021-04-02T14:06:32.337800Z

no, not yet

ericdallo 2021-04-02T14:07:09.338Z

Exited for that πŸ˜„ bb is becoming a pretty mature clojure tool

mike_ananev 2021-04-02T14:37:13.338300Z

super!

mike_ananev 2021-04-02T15:30:23.338700Z

@borkdude is there any way to set default ns? Instead of bb -m tasks/foo I would like to write bb -m foo

borkdude 2021-04-02T15:35:29.339Z

Not yet, but I think this was also something that @lee suggested. Feel free to post an issue and we could maybe add an option to bb.edn

mike_ananev 2021-04-02T15:39:03.340300Z

@borkdude bb -h has a typo for nrepl-server locahost:1667 should be localhost:1667

borkdude 2021-04-02T15:39:48.340500Z

@mike1452 thanks, will fix

mike_ananev 2021-04-02T15:40:37.340600Z

babashka is very cool. experimenting with it to completely remove just utility from my templates.

borkdude 2021-04-02T16:34:03.341Z

Yeah, instead of an issue we might continue rambling there

2021-04-02T17:28:07.341200Z

Hey, turns out you can do a heck of a lot with 50 lines of Babashka. Here is Borkdudes birthday calculation fleshed out

2021-04-02T17:28:10.341300Z

https://github.com/heow/lifecalc

πŸ˜† 1
πŸ˜… 1
borkdude 2021-04-02T18:39:42.342100Z

If you are for, or fiercely against including rewrite-clj in babashka, make your opinion known here: https://github.com/babashka/babashka/issues/769

wilkerlucio 2021-04-02T19:07:08.342500Z

pretty cool stuff!! the only thing I miss from it is a way to list the available tasks (and maybe have a way to tab-complete them from the terminal?). I was thinking we could add some metadata to the fn name to flag it as a "task", a problem there is to figure which files to scan, maybe use a file name pattern (eg: *-tasks)

1
borkdude 2021-04-02T19:11:21.342700Z

@wilkerlucio good thoughts, this idea has come up before and I'm happy you bring it up again. there are a few ways to solve this: 1) add the tasks manually to the docstring of the ns using alter-meta! and then request the ns doc with bb doc tasks 2) implement a generic dir subcommand that lists all public vars of a namespace: bb dir tasks 3) implement a bespoke subcommand for this: bb list tasks which searches in the tasks ns for vars that have specific metadata 4) like 3 + set the namespaces to list in bb.edn

wilkerlucio 2021-04-02T19:13:34.343Z

I like the idea of flagging the tasks ns manually in bb.edn, this way we have good control, and just have to setup once per ns

borkdude 2021-04-02T19:13:55.343500Z

so 4?

grazfather 2021-04-02T19:14:00.343800Z

damn are you saying borkdude is half dead?

wilkerlucio 2021-04-02T19:14:06.343900Z

πŸ‘

borkdude 2021-04-02T19:16:47.344200Z

I created a sub-discussion for this idea here: https://github.com/babashka/babashka/discussions/771

πŸ‘ 1
borkdude 2021-04-02T19:17:30.344400Z

if we go with custom tasks designated with metadata we could also have bb run install and then bb knows in which namespaces to find install

borkdude 2021-04-02T19:19:01.344600Z

I think that ties into the thing that @mike1452 brought up: having a shorter way of invoking tasks by name

wilkerlucio 2021-04-02T19:25:26.344900Z

yeah, I posted on the discussion, I think if a task name is unique (no conflicts), babashka could accept just the name without the ns

borkdude 2021-04-02T19:27:17.345100Z

One other possibility could be to name the task in bb.edn:

{:tasks {install foo.bar.tasks/install}}
Less chance of conflicts

πŸ‘ 1
borkdude 2021-04-02T19:39:36.345400Z

@wilkerlucio The way I got to the DSL discussed in the video was as follows: start with {:tasks {install foo.bar.tasks/install}} but perhaps you want to add some options:

{:tasks {install {:main-fn foo.bar.tasks/install :description ...}}}
but always having to write a function for a small shell thing is maybe too much, so let's add :shell:
{:tasks {install {:shell "ls"}}}
but hiccup is less ambiguous here:
{:tasks {uberjar [main foo.bar/baz]
         install [shell "ls"]}}

borkdude 2021-04-02T19:40:41.345900Z

This is why I started with the most basic thing

borkdude 2021-04-02T19:41:19.346300Z

They also call @heow Heow The Reaper

wilkerlucio 2021-04-02T19:41:23.346400Z

kind feels like a snake eating itself (going back to the DSL idea)

wilkerlucio 2021-04-02T19:42:23.346700Z

but also makes me think about package.json scripts, they are a nice a way to alias simple things

borkdude 2021-04-02T19:42:31.346900Z

right

wilkerlucio 2021-04-02T19:42:33.347100Z

the question is how far should a dsl like this go

borkdude 2021-04-02T19:43:22.347300Z

in npm they chose: just shell invocation

borkdude 2021-04-02T19:43:39.347600Z

in gradle they chose: allow every magical thing (I think)

borkdude 2021-04-02T19:43:47.347800Z

in bb we choose: just functions?

wilkerlucio 2021-04-02T19:44:30.348Z

what about 2 options: - use a symbol to point to fn - use a string to shell

borkdude 2021-04-02T19:45:10.348200Z

the best of both worlds, convenience and extensibility via fns?

wilkerlucio 2021-04-02T19:45:18.348400Z

that's what I'm thinking

borkdude 2021-04-02T19:45:37.348600Z

{:tasks {clean "rm -rf target"
    install foo.bar.baz/install}

borkdude 2021-04-02T19:46:44.348800Z

yeah might make sense. we can always extend this with a config map as the third type if we must

borkdude 2021-04-02T19:48:36.349Z

and you can invoke bb itself for clojure invocations as well: ` {:tasks {repl "bb clojure -A:foo" install foo.bar.baz/install}

borkdude 2021-04-02T19:48:48.349200Z

or invoke the normal clojure of course

wilkerlucio 2021-04-02T19:49:04.349400Z

yup

wilkerlucio 2021-04-02T19:55:31.349600Z

now that tempting feeling for hiccup to give args to the fn XD

wilkerlucio 2021-04-02T19:55:57.349800Z

we can do via shell alias, but also giving data as EDN strait also sounds nice

wilkerlucio 2021-04-02T19:56:24.350Z

maybe, instead of hiccup, make it look like a fn call

wilkerlucio 2021-04-02T19:56:55.350200Z

{:tasks {install (foo.bar/install "with" :args)}}

wilkerlucio 2021-04-02T19:58:35.350400Z

not sure how much that sounds a stretch, but if we just allow generic clojuer to run there, is a full Clojure for free :thinking_face: altough detecting fns to auto-import may get too much

borkdude 2021-04-02T20:00:23.350800Z

@wilkerlucio getting close to https://github.com/juxt/mach ;) in the dsl I had that like [main foo.bar/install "with" :args] where main was one of main, clojure, shell

grazfather 2021-04-02T20:01:31.351300Z

πŸ˜‚

wilkerlucio 2021-04-02T20:01:36.351400Z

I like lists instead of hiccup in this case because it feels more natural (same as invoking in clojure), do you have a strong opinion on using hiccup style instead?

wilkerlucio 2021-04-02T20:02:31.351600Z

Mach looks interesting

borkdude 2021-04-02T20:03:11.351800Z

note that it is abandoned according to JUXT itself (reason was that nodejs wasn't a good fit for this kind of synchronous work)

wilkerlucio 2021-04-02T20:04:08.352Z

in my head is making a lot of sense to enable code snippets strait in the config, seems to solve the "custom DSL" problem (just relying on all clojure constructs instead), while giving a lot of power. this way the decision to make a or not it as a external fn defined in a file can become a refactor decision (when things get messy)

borkdude 2021-04-02T20:04:43.352200Z

true, but all requires are done implicitly?

borkdude 2021-04-02T20:05:20.352400Z

we could also expose a function (babashka.tasks/shell "rm -rf target")

borkdude 2021-04-02T20:06:00.352700Z

or (shell "rm -rf target") for convenience (but comes from that utils ns)

wilkerlucio 2021-04-02T20:06:06.352900Z

yeah, I wonder if there would be issues with all requires done implicitly, but I guess if the snippets are small it should be fine

wilkerlucio 2021-04-02T20:06:23.353100Z

yeah, I'm down to some extra includes for convience (on scripts running from "task snippets")

wilkerlucio 2021-04-02T20:06:51.353300Z

like the helpers you got in the video demo

borkdude 2021-04-02T20:06:59.353500Z

it would be pretty bb-esque to allow scripting there ;)

πŸ™‚ 1
borkdude 2021-04-02T20:09:02.353800Z

and calling another task by name, implicitly inlines the script?

{:tasks {clean (shell "rm -rf target")}
  uberjar (do (clean) (tasks/uberjar))
?

borkdude 2021-04-02T20:09:46.354100Z

maybe clean (shell "rm -rf target") defines a function in the background which you can call?

borkdude 2021-04-02T20:10:31.354300Z

(letfn [clean ([] (shell "rm -rf target")) ...

wilkerlucio 2021-04-02T20:11:45.354500Z

what about bb.task/clean? trying to think a way to reduce collisions

borkdude 2021-04-02T20:14:32.354900Z

why would you have collissions by having them as local fns?

wilkerlucio 2021-04-02T20:15:56.355100Z

I wonder for example, if I have a task called empty, that would shadow clojure.core/empty? maybe I'm being over-concerned here

wilkerlucio 2021-04-02T20:16:58.355300Z

I like the idea of being able to call other tasks, just wonder if there is a safer option

borkdude 2021-04-02T20:18:07.355500Z

yeah, that would just be a bad task name then :)

wilkerlucio 2021-04-02T20:18:38.355700Z

also, the user could still use clojure.core/empty skip the shadowing

borkdude 2021-04-02T20:18:51.355900Z

yeah

wilkerlucio 2021-04-02T20:18:52.356100Z

and given the task names are visible in place there, seems easy enough to track

nate 2021-04-02T22:23:02.356800Z

man, that readme ended darkly...

1
1
nate 2021-04-02T22:27:28.356900Z

@heow This is fantastic, I really like the trick of rotating though representations (date -> day -> percent -> date...)

nate 2021-04-02T22:28:18.357200Z

and interleave-with.clj? that looks like a neat standalone script

πŸ™‚ 1