babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
tobias 2021-05-08T05:15:01.059Z

Does babashka work on the new macbooks with M1 chips?

dharrigan 2021-05-08T05:20:48.059200Z

yes

borkdude 2021-05-08T09:51:07.060400Z

@plexus Next bb will have better error msg:

1: (defrecord Foo [] Comparable (compareTo [x y] -1))
                     ^--- Records currently only support protocol implementations, found: Comparable

👍 1
💯 1
1
Karol Wójcik 2021-05-08T12:54:07.062100Z

How can I get the output of the script with p/process ?

(with-out-str @(p/process ["docker" "run" "--rm"
                             "-v" (str (.getAbsolutePath (io/file "")) ":/project")
                             "--user" USER_GID
                             "-it" IMAGE_CORDS
                             "/bin/bash" "-c" "clojure -Spath"
                             ]
                           {:inherit true}))
I'm trying to take clojure path as a string, but automatically prints the output to the console

borkdude 2021-05-08T12:55:37.062500Z

In this case you should not use :inherit true but provide :out *out*

Karol Wójcik 2021-05-08T12:55:44.062700Z

Aaaaa

borkdude 2021-05-08T12:55:57.062900Z

or :out :string would also do the job

Karol Wójcik 2021-05-08T12:57:03.063500Z

Hmm.. Without inherit set to true docker spits to stderr the following error: the input device is not a TTY

Karol Wójcik 2021-05-08T12:58:29.063700Z

Ok this works! Thanks @borkdude

(:out @(p/process ["docker" "run" "--rm"
                     "-v" (str (.getAbsolutePath (io/file "")) ":/project")
                     "--user" USER_GID
                     "-it" IMAGE_CORDS
                     "/bin/bash" "-c" "clojure -Spath"
                     ]
                    {:out :string
                     :inherit true
                     :err :string}))

borkdude 2021-05-08T12:58:52.064100Z

yeah, that's the way to do it.

Karol Wójcik 2021-05-08T12:59:31.064900Z

Is it possible to set throw error option in p/process opts?

borkdude 2021-05-08T13:00:00.065300Z

there is p/check which composes with p/process

Karol Wójcik 2021-05-08T13:00:18.065700Z

Hmm ok I will take a look into the source code! Thanks 🙂

borkdude 2021-05-08T13:00:33.066Z

this is documented,you don't need to go look in the sources for this

borkdude 2021-05-08T13:00:45.066200Z

but of course you can

borkdude 2021-05-08T13:01:36.067Z

@ everyone: I have written tasks docs: https://book.babashka.org/master.html#tasks Please read through them before I publish 0.4.0 where tasks will be "official"

borkdude 2021-05-08T14:04:32.068300Z

@grazfather I have the following issue with parallel. Was running into this when writing the docs:

{:tasks {:init (def log (Object.))
         :enter (locking log (println (java.util.Date.)))
         a (Thread/sleep 5000)
         b (Thread/sleep 5000)
         c {:enter (println "R")
            :depends [a b]}
         d {:enter nil
            :task (do
                    (let [parallel (:parallel (current-task))]
                      ;; if d runs in parallel, we invoke c in parallel too
                      (time (run 'c {:parallel parallel}))))}}}
If we invoke bb run --parallel d and d invokes (run 'c) should c run automatically run in parallel too, or should this be the choice of who invokes run explicitly?

grazfather 2021-05-08T14:06:50.069200Z

so with Make typically you just j for jobs, it’s how many threads you allow, but the implication is that everything is parallelizable

borkdude 2021-05-08T14:07:16.069600Z

yeah, I think we could do that too

borkdude 2021-05-08T14:07:32.070300Z

and you could opt out of it using :parallel false

grazfather 2021-05-08T14:07:33.070400Z

basically the idea again is the dependency graph: The topological sort should let you find independent branches tnat can safely run in parallel

grazfather 2021-05-08T14:07:47.070600Z

BUT in this case b runs c explicitly

grazfather 2021-05-08T14:07:50.070800Z

i get what you’re asking

borkdude 2021-05-08T14:07:52.071Z

yeah

grazfather 2021-05-08T14:08:04.071400Z

is run a new function to bb?

borkdude 2021-05-08T14:08:14.071600Z

make can also invoke ${make} itself, it's similar to that

grazfather 2021-05-08T14:08:24.071900Z

yep exactly what I am getting to

borkdude 2021-05-08T14:09:02.073Z

yes, run can be used to force things in a certain succession, so you can withstand them being run in parallel. with make you can do this too

grazfather 2021-05-08T14:09:08.073200Z

I think that invoking make manually sucks in general, but in that case it’s up to the invoker to choose whether to paralellize… I am not even sure if a task ‘knows’ if it is running in parallel (for it to pass to its child invokation)

borkdude 2021-05-08T14:09:32.073600Z

in make the parallel option is passed implicitly to ${make}

grazfather 2021-05-08T14:09:43.074Z

oh is it?

borkdude 2021-05-08T14:09:50.074200Z

but in tasks you can request this using (:parallel (current-task))

borkdude 2021-05-08T14:10:11.074500Z

(as of 0.4.0 which isn't out yet)

grazfather 2021-05-08T14:10:37.075100Z

so I would say that the default should be to implicitly pass parallel, but allow it to be serialized explicitly

borkdude 2021-05-08T14:10:52.075300Z

ok

grazfather 2021-05-08T14:11:02.075600Z

I can see people having issues with that (secret arguments)

grazfather 2021-05-08T14:11:08.075800Z

but it seems to make more sense to me

grazfather 2021-05-08T14:11:35.076400Z

people who use parallel will be confused if it’s dropped magically, people who don’t use parallel won’t notice anything either way so it doesn’t matter

borkdude 2021-05-08T14:11:42.076600Z

(defn run
  ([task] (run task nil))
  ([task {:keys [:parallel]
          :or {parallel (:parallel (current-task))}}]
   (let [[[expr]] (assemble-task task parallel)]
     (sci/eval-string* @ctx expr))))

grazfather 2021-05-08T14:11:52.076800Z

nice

grazfather 2021-05-08T14:12:14.077100Z

is :or a destructuring feature?

borkdude 2021-05-08T14:12:17.077300Z

yes

grazfather 2021-05-08T14:12:22.077500Z

cool, TIL

grazfather 2021-05-08T14:14:57.078Z

Looks like a lot of effort is going into the tasks feature 🙂 is it pretty popular?

borkdude 2021-05-08T14:15:32.078300Z

ok, so:

{:tasks {:init (def log (Object.))
         :enter (locking log (println (str (:name (current-task))
                                           ":")
                                      (java.util.Date.)))
         a (Thread/sleep 5000)
         b (Thread/sleep 5000)
         c {:depends [a b]}
         d {:task (time (run 'c))}}}
$ clojure -M:babashka/dev run --parallel d
d: #inst "2021-05-08T14:14:56.322-00:00"
a: #inst "2021-05-08T14:14:56.357-00:00"
b: #inst "2021-05-08T14:14:56.360-00:00"
c: #inst "2021-05-08T14:15:01.366-00:00"
"Elapsed time: 5023.894512 msecs"

borkdude 2021-05-08T14:16:52.079Z

@grazfather So far tasks is being used by several people already: https://book.babashka.org/master.html#_real_world_examples I'm going to announce 0.4.0 this weekend with tasks as an "official" feature

grazfather 2021-05-08T14:17:33.079500Z

That’s beautiful. Unfortunately I haven’t been able to play with BB in a while

borkdude 2021-05-08T16:52:05.079900Z

martinklepsch 2021-05-08T22:38:22.092600Z

Something that could be nice as a babashka built-in: a typo-checker that can detect and show typos in a given string based on some accepted values. Those values could be read from the file system (via glob), git, a raw set of strings etc.

martinklepsch 2021-05-08T23:17:05.093300Z

The tasks stuff looks fabulous btw!