Fork me on GitHub
#babashka
<
2021-05-08
>
tobias05:05:01

Does babashka work on the new macbooks with M1 chips?

borkdude09:05:07

@plexus Next bb will have better error msg:

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

👍 3
3
💯 3
Karol Wójcik12:05:07

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

borkdude12:05:37

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

borkdude12:05:57

or :out :string would also do the job

Karol Wójcik12:05:03

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

Karol Wójcik12:05:29

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}))

borkdude12:05:52

yeah, that's the way to do it.

Karol Wójcik12:05:31

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

borkdude13:05:00

there is p/check which composes with p/process

Karol Wójcik13:05:18

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

borkdude13:05:33

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

borkdude13:05:45

but of course you can

borkdude13:05:36

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

borkdude14:05:32

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

grazfather14:05:50

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

borkdude14:05:16

yeah, I think we could do that too

borkdude14:05:32

and you could opt out of it using :parallel false

grazfather14:05:33

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

grazfather14:05:47

BUT in this case b runs c explicitly

grazfather14:05:50

i get what you’re asking

grazfather14:05:04

is run a new function to bb?

borkdude14:05:14

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

grazfather14:05:24

yep exactly what I am getting to

borkdude14:05:02

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

grazfather14:05:08

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)

borkdude14:05:32

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

borkdude14:05:50

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

borkdude14:05:11

(as of 0.4.0 which isn't out yet)

grazfather14:05:37

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

grazfather14:05:02

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

grazfather14:05:08

but it seems to make more sense to me

grazfather14:05:35

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

borkdude14:05:42

(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))))

grazfather14:05:14

is :or a destructuring feature?

grazfather14:05:57

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

borkdude14:05:32

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"

borkdude14:05:52

@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

grazfather14:05:33

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

martinklepsch22:05:22

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.

martinklepsch23:05:05

The tasks stuff looks fabulous btw!