babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
wilkerlucio 2021-04-12T06:25:13.036Z

does :init still works on babashka tasks? Iโ€™m trying to use but seems like itโ€™s being ignored

borkdude 2021-04-12T07:43:39.036300Z

@wilkerlucio sorry, it broke. I will fix and make a new release

borkdude 2021-04-12T07:43:49.036500Z

(and write a test)

borkdude 2021-04-12T07:52:34.037Z

@wilkerlucio I guess one can also write a hidden -init task and then :depends on that :)

borkdude 2021-04-12T09:03:58.037900Z

@wilkerlucio I just released 0.3.4. I'm considering to deprecate :init because you can do it all with :depends and this also leads to better local reasoning about a task perhaps.

{:tasks {-target-dir "target"
         -target {:depends [-target-dir]
                  :task (fs/create-dirs -target-dir)}
         -jar-file {:depends [-target]
                    :task "target/foo.jar"}

         jar {:depends [-target -jar-file]
              :task (when (fs/modified-since -jar-file
                                             (fs/glob "src" "**.clj"))
                      (spit -jar-file "test")
                      (println "made jar!"))}
         uberjar {:depends [jar]
                  :task (println "creating uberjar!")}
         clean {:depends [-target-dir]
                :task (fs/delete-tree -target-dir)}
         uberjar:clean {:depends [clean uberjar]}}}

๐Ÿ‘ 1
borkdude 2021-04-12T12:22:43.038200Z

More real life example: https://github.com/borkdude/mach/blob/bb-run/examples/app/bb.edn

dharrigan 2021-04-12T12:50:29.039Z

Would . also work instead of -?

dharrigan 2021-04-12T12:50:35.039200Z

i.e., .target

borkdude 2021-04-12T12:54:56.041300Z

any other character would work, but I'm not sure if .foo is a valid name in clojure, since dot is interop-related: > Symbols beginning or ending with '.' are reserved by Clojure. https://clojure.org/reference/reader Open to other ideas/characters though. We could also do:

{:tasks {:private {target-dir "target"}
         :public {clean {:depends [target]
                         :task (fs/delete-tree target)}}}}

borkdude 2021-04-12T12:56:55.041700Z

or:

{:tasks {:aux {target-dir "target"}
         uberjar {:depends [target]
                  :task (fs/delete-tree target)}}}

borkdude 2021-04-12T13:06:51.042200Z

or:

{:tasks {:private [target-dir]
         target-dir "target"
         uberjar {:depends [target]
                  :task (fs/delete-tree target)}}}

borkdude 2021-04-12T13:07:34.042800Z

but so far -target-dir doesn't seem like an unreasonable thing perhaps

dharrigan 2021-04-12T13:16:05.043400Z

It's more natural to think of . as that means hidden in both unix (and funnily enough yml) land

dharrigan 2021-04-12T13:16:41.044200Z

so a hidden task, like a hidden file

borkdude 2021-04-12T13:16:46.044400Z

yeah, but according to the reader docs that character is reserved by clojure for symbols, so I won't do that

dharrigan 2021-04-12T13:16:53.044700Z

booooo

dharrigan 2021-04-12T13:16:55.045Z

๐Ÿ™‚

borkdude 2021-04-12T13:17:50.045400Z

alternatives: _ or *, but so far, - is the best one imo

dharrigan 2021-04-12T13:18:03.045600Z

agreed, best of the bunch

2021-04-12T14:00:11.048100Z

Any thoughts on why bb might be slow to start up on Windows? I have this little bb.edn script:

{:tasks {hello (println "hi!")}}
On my MacBook Pro it runs pretty consistently in about 30ms, but on Windows it usually takes about 2 seconds, sometimes up to 5s and sometimes as low as 800ms, but always much slower.

2021-04-12T14:00:36.048400Z

(native Windows, not WSL)

borkdude 2021-04-12T14:02:44.048700Z

no idea, but I will try

wilkerlucio 2021-04-12T14:07:16.053600Z

also with init I can have a more clean to read tasks (without having to make all of them maps with depends)

borkdude 2021-04-12T14:08:54.053900Z

@jkrasnay

PS C:\Temp> bb version
babashka v0.3.4
PS C:\Temp> bb tasks
The following tasks are available:

hello
PS C:\Temp> Measure-Command { 'bb hello' }


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 0
Ticks             : 9103
TotalDays         : 1.05358796296296E-08
TotalHours        : 2.52861111111111E-07
TotalMinutes      : 1.51716666666667E-05
TotalSeconds      : 0.0009103
TotalMilliseconds : 0.9103

borkdude 2021-04-12T14:09:20.054100Z

cannot reproduce this

borkdude 2021-04-12T14:09:45.054300Z

ok. understood. :init is still supported :)

๐Ÿ™‚ 2
2021-04-12T14:12:08.054500Z

Wow, thatโ€™s weird. With Measure-Command it runs in 2-3ms, but just at the command prompt itโ€™s clearly slower.

borkdude 2021-04-12T14:16:36.055800Z

Maybe some virus scanner?

borkdude 2021-04-12T14:16:45.056Z

Is your system memory contrained?

borkdude 2021-04-12T14:18:28.056200Z

How about cmd.exe?

borkdude 2021-04-12T14:19:34.056400Z

and back in 0.3.4 btw

borkdude 2021-04-12T14:19:39.056600Z

(it was lost by accident)

2021-04-12T14:34:35.056800Z

According to Task Manager Iโ€™m only about 50% memory, and everything else seems pretty snappy. Running echo 'hi' from Powershell is instantaneous.

borkdude 2021-04-12T14:36:00.057Z

again, are you using a virus scanner?

2021-04-12T14:36:02.057200Z

Getting the same slow response running under cmd and also under Git bash.

2021-04-12T14:36:30.057400Z

Yeah, itโ€™s a corporate machine so the virus scanner is omnipresent. Maybe Measure-Command somehow avoids the virus scanner

borkdude 2021-04-12T14:36:56.057600Z

maybe you can put bb in the allow list of the virus scanner or something?

2021-04-12T14:37:25.057800Z

Oh, thatโ€™s a good idea. Iโ€™ll look into that.

2021-04-12T14:37:54.058Z

Itโ€™s not a showstopper for me. Just want to remove any possible objections to using Babashka ๐Ÿ™‚

borkdude 2021-04-12T14:39:00.058200Z

And now that it even supports a shebang in .bat scripts, I can't see why the entire corporate Windows world isn't jumping on it

๐Ÿ˜‚ 1
2021-04-12T14:52:36.058600Z

I know, right? So far the fact that itโ€™s a single .exe that I can install without admin privileges makes it an easy sell.

wilkerlucio 2021-04-12T15:13:35.058800Z

also - in beginning is idiomatic for Clojure, so Iโ€™ll keep that ๐Ÿ‘

borkdude 2021-04-12T15:30:18.059500Z

At work I can deprecate some bb script perhaps, that I wrote to simultaneously load processes for development: <uploading screenshot below>

borkdude 2021-04-12T15:31:45.059900Z

So I can just kick off bb dev and start working

borkdude 2021-04-12T15:43:10.060100Z

๐Ÿ‘ 2
2021-04-13T07:49:01.077500Z

Looks very good! Thank you

2021-04-12T16:16:33.060600Z

Should it be possible to require a namespace in the tasks? I have a function that I can call directly (`bb -m tasks/midje`), but not from a task when I do

{:paths
 ["bb-scripts"]

 :tasks {clean {:doc "Clean target dir"
                :task (shell "rm -rf target")}
         midje {:doc "Run midje tests"
                :depends [clean]
                :task (do (require 'tasks)
                          (tasks/midje))}}
This gives me: Could not resolve symbol: tasks/midje

borkdude 2021-04-12T16:23:04.061Z

hmm

borkdude 2021-04-12T16:23:22.061200Z

ooooh

borkdude 2021-04-12T16:23:43.061400Z

tasks is already an alias for babashka.tasks

borkdude 2021-04-12T16:25:05.061600Z

This could work:

{:paths ["src"]
 :tasks {:init (ns my-tasks
                 (:require [babashka.tasks :refer [shell]]
                           [tasks :as t]))
         clean {:doc "Clean target dir"
                :task (shell "rm -rf target")}
         midje {:doc "Run midje tests"
                :depends [clean]
                :task (t/midje)}}}

borkdude 2021-04-12T16:26:51.061800Z

Maybe a task should have a special :require option for this

๐Ÿ‘ 1
borkdude 2021-04-12T16:27:28.062Z

so those can be executed before the task code is executed

borkdude 2021-04-12T16:28:58.062200Z

I think I'll remove the tasks alias perhaps because this can get confusing

๐Ÿ‘ 1
2021-04-12T16:32:40.062500Z

Yeah I also tried with tasks2 but that didnโ€™t help. Iโ€™ll try your init suggestion! Thanks!

borkdude 2021-04-12T16:33:21.062700Z

It only works when you use resolve as these names are only valid in the next top level expression, this is how clojure works :/

borkdude 2021-04-12T16:33:48.062900Z

so adding explicit an :require option should take care of this by moving the requires on top

๐Ÿ‘ 1
2021-04-12T16:36:05.063100Z

ah yeah, resolve. Thanks! Forgot about that. I tried with eval, but that didnโ€™t work. (eval '(tasks/midje))

2021-04-12T16:41:17.063400Z

Donโ€™t work

:task (do (require 'tasks)
          ((resolve 'tasks/midje)))
          
:task (do (require 'tasks)
          (eval '(tasks/midje)))}
Works
:task (do (require '[tasks :as t])
          ((resolve 't/midje)))
          
:task (do (require '[tasks :as t])
          (eval '(t/midje)))}
So you were right; it was not working because of the already existing alias tasks

Gary Berger 2021-04-12T16:44:15.064800Z

Is the full namespace of clojure.spec.alpha provided in the feature/spec-alpha? Reason why I canโ€™t resolve (s/keys)?

borkdude 2021-04-12T16:44:34.065Z

You can also use (ns-unalias *ns* 'tasks) perhaps

๐Ÿ‘ 1
borkdude 2021-04-12T16:45:42.065700Z

@garyberger Probably not the full namespace, it's more or less a proof of concept. I do have it included in grasp: https://github.com/borkdude/grasp/blob/master/src/grasp/native.clj

borkdude 2021-04-12T16:45:59.066100Z

But feel free to add stuff to it

Gary Berger 2021-04-12T16:46:05.066300Z

ah ok.. tks

borkdude 2021-04-12T16:47:01.066600Z

I want to add spec once it's out of alpha

Gary Berger 2021-04-12T16:47:14.066900Z

if ever ๐Ÿ™‚

borkdude 2021-04-12T16:49:06.067200Z

@garyberger Meanwhile you can possibly also use https://github.com/borkdude/spartan.spec

๐Ÿ‘€ 1
borkdude 2021-04-12T17:03:01.067700Z

Hmm, it seems ns-unalias isn't available in bb. A good reason to add it. Being explicit about requires will also help us prevent bb alias conflicts, because I can automatically unlias the existing ones and replace them with the user's ones.

{:doc ...
 :require [[foo :as fs] [:bar :as ]]

2021-04-12T17:04:24.067900Z

Makes sense! Thanks

wilkerlucio 2021-04-12T17:41:08.068700Z

@borkdude what was again that trick you told me the other day to prevent babashka from stopping? do you remember?

wilkerlucio 2021-04-12T17:41:45.068800Z

I remember was about deferring something at the end, but I canโ€™t remember the details

borkdude 2021-04-12T17:42:54.069Z

@(promise)

Darin Douglass 2021-04-12T17:42:58.069200Z

was it @(promise)?

Darin Douglass 2021-04-12T17:43:00.069400Z

oh heh ๐Ÿ˜›

wilkerlucio 2021-04-12T17:44:03.069600Z

yes! thanks ๐Ÿ™‚

borkdude 2021-04-12T21:06:32.069900Z

@jeroenvandijk In the next iteration of bb your task will become:

{:paths ["src"]
 :tasks {clean {:doc "Clean target dir"
                :task (shell "rm -rf target")}
         midje {:doc "Run midje tests"
                :depends [clean]
                :requires ([tasks])
                :task (tasks/midje)}}}
So :requires is a list of libspecs. Also supported on the top-level. There will be no more automatic aliases. clojure and shell will be there, but can be overridden by the user without errors.

borkdude 2021-04-12T21:14:39.070100Z

Also just {:doc "run midje" :task tasks/midje} is supported

borkdude 2021-04-12T21:14:51.070300Z

this will automatically call the function with *command-line-args*