Does babashka work on the new macbooks with M1 chips?
yes
@plexus Next bb will have better error msg:
1: (defrecord Foo [] Comparable (compareTo [x y] -1))
^--- Records currently only support protocol implementations, found: Comparable
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 consoleIn this case you should not use :inherit true
but provide :out *out*
Aaaaa
or :out :string
would also do the job
Hmm.. Without inherit set to true docker spits to stderr the following error: the input device is not a TTY
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}))
yeah, that's the way to do it.
Is it possible to set throw error
option in p/process opts?
there is p/check
which composes with p/process
Hmm ok I will take a look into the source code! Thanks 🙂
this is documented,you don't need to go look in the sources for this
but of course you can
@ 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"
@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?so with Make typically you just j
for jobs, it’s how many threads you allow, but the implication is that everything is parallelizable
yeah, I think we could do that too
and you could opt out of it using :parallel false
basically the idea again is the dependency graph: The topological sort should let you find independent branches tnat can safely run in parallel
BUT in this case b runs c explicitly
i get what you’re asking
yeah
is run
a new function to bb?
make can also invoke ${make}
itself, it's similar to that
yep exactly what I am getting to
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
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)
in make the parallel option is passed implicitly to ${make}
oh is it?
but in tasks you can request this using (:parallel (current-task))
(as of 0.4.0 which isn't out yet)
so I would say that the default should be to implicitly pass parallel, but allow it to be serialized explicitly
ok
I can see people having issues with that (secret arguments)
but it seems to make more sense to me
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
(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))))
nice
is :or
a destructuring feature?
yes
cool, TIL
Looks like a lot of effort is going into the tasks feature 🙂 is it pretty popular?
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"
@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
That’s beautiful. Unfortunately I haven’t been able to play with BB in a while
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.
The tasks stuff looks fabulous btw!