Fork me on GitHub
#babashka
<
2021-04-02
>
borkdude10:04:14

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

πŸš€ 3
mmz11:04:21

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
ericdallo14:04:01

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

borkdude14:04:32

no, not yet

ericdallo14:04:09

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

mike_ananev15:04:23

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

borkdude15:04:29

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

mike_ananev15:04:37

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

borkdude16:04:03

Yeah, instead of an issue we might continue rambling there

wilkerlucio19:04:08

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
borkdude19:04:21

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

wilkerlucio19:04:34

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

borkdude19:04:47

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

πŸ‘ 1
borkdude19:04:30

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

borkdude19:04:01

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

wilkerlucio19:04:26

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

borkdude19:04:17

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

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

πŸ‘ 1
borkdude19:04:36

@U066U8JQJ 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"]}}

borkdude19:04:41

This is why I started with the most basic thing

wilkerlucio19:04:23

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

wilkerlucio19:04:23

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

wilkerlucio19:04:33

the question is how far should a dsl like this go

borkdude19:04:22

in npm they chose: just shell invocation

borkdude19:04:39

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

borkdude19:04:47

in bb we choose: just functions?

wilkerlucio19:04:30

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

borkdude19:04:10

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

wilkerlucio19:04:18

that's what I'm thinking

borkdude19:04:37

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

borkdude19:04:44

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

borkdude19:04:36

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

borkdude19:04:48

or invoke the normal clojure of course

wilkerlucio19:04:31

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

wilkerlucio19:04:57

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

wilkerlucio19:04:24

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

wilkerlucio19:04:55

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

wilkerlucio19:04:35

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

borkdude20:04:23

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

wilkerlucio20:04:36

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?

wilkerlucio20:04:31

Mach looks interesting

borkdude20:04:11

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

wilkerlucio20:04:08

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)

borkdude20:04:43

true, but all requires are done implicitly?

borkdude20:04:20

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

borkdude20:04:00

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

wilkerlucio20:04:06

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

wilkerlucio20:04:23

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

wilkerlucio20:04:51

like the helpers you got in the video demo

borkdude20:04:59

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

πŸ™‚ 1
borkdude20:04:02

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

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

borkdude20:04:46

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

borkdude20:04:31

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

wilkerlucio20:04:45

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

borkdude20:04:32

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

wilkerlucio20:04:56

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

wilkerlucio20:04:58

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

borkdude20:04:07

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

wilkerlucio20:04:38

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

wilkerlucio20:04:52

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

grazfather12:04:08

You’re a machine

grazfather12:04:41

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

grazfather12:04:31

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

borkdude13:04:02

@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

mike_ananev15:04:03

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

borkdude15:04:48

@mike1452 thanks, will fix

heow17:04:07

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

nate22:04:28

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

nate22:04:18

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

πŸ™‚ 1
borkdude18:04:42

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

grazfather19:04:00

damn are you saying borkdude is half dead?

borkdude19:04:19

They also call @heow Heow The Reaper

nate22:04:02

man, that readme ended darkly...

truestory 1
1