does :init
still works on babashka tasks? Iโm trying to use but seems like itโs being ignored
@wilkerlucio sorry, it broke. I will fix and make a new release
(and write a test)
@wilkerlucio I guess one can also write a hidden -init
task and then :depends
on that :)
@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]}}}
More real life example: https://github.com/borkdude/mach/blob/bb-run/examples/app/bb.edn
Would .
also work instead of -
?
i.e., .target
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)}}}}
or:
{:tasks {:aux {target-dir "target"}
uberjar {:depends [target]
:task (fs/delete-tree target)}}}
or:
{:tasks {:private [target-dir]
target-dir "target"
uberjar {:depends [target]
:task (fs/delete-tree target)}}}
but so far -target-dir
doesn't seem like an unreasonable thing perhaps
It's more natural to think of .
as that means hidden in both unix (and funnily enough yml) land
so a hidden task, like a hidden file
yeah, but according to the reader docs that character is reserved by clojure for symbols, so I won't do that
booooo
๐
alternatives: _
or *
, but so far, -
is the best one imo
agreed, best of the bunch
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.(native Windows, not WSL)
no idea, but I will try
also with init I can have a more clean to read tasks (without having to make all of them maps with depends)
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
cannot reproduce this
ok. understood. :init is still supported :)
Wow, thatโs weird. With Measure-Command
it runs in 2-3ms, but just at the command prompt itโs clearly slower.
Maybe some virus scanner?
Is your system memory contrained?
How about cmd.exe?
and back in 0.3.4 btw
(it was lost by accident)
According to Task Manager Iโm only about 50% memory, and everything else seems pretty snappy. Running echo 'hi'
from Powershell is instantaneous.
again, are you using a virus scanner?
Getting the same slow response running under cmd
and also under Git bash.
Yeah, itโs a corporate machine so the virus scanner is omnipresent. Maybe Measure-Command
somehow avoids the virus scanner
maybe you can put bb in the allow list of the virus scanner or something?
Oh, thatโs a good idea. Iโll look into that.
Itโs not a showstopper for me. Just want to remove any possible objections to using Babashka ๐
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
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.
also -
in beginning is idiomatic for Clojure, so Iโll keep that ๐
At work I can deprecate some bb script perhaps, that I wrote to simultaneously load processes for development: <uploading screenshot below>
So I can just kick off bb dev
and start working
Looks very good! Thank you
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
hmm
ooooh
tasks is already an alias for babashka.tasks
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)}}}
Maybe a task should have a special :require
option for this
so those can be executed before the task code is executed
I think I'll remove the tasks alias perhaps because this can get confusing
Yeah I also tried with tasks2
but that didnโt help. Iโll try your init suggestion! Thanks!
It only works when you use resolve
as these names are only valid in the next top level expression, this is how clojure works :/
so adding explicit an :require
option should take care of this by moving the requires on top
ah yeah, resolve. Thanks! Forgot about that. I tried with eval, but that didnโt work. (eval '(tasks/midje))
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
Is the full namespace of clojure.spec.alpha provided in the feature/spec-alpha? Reason why I canโt resolve (s/keys)
?
You can also use (ns-unalias *ns* 'tasks)
perhaps
@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
But feel free to add stuff to it
ah ok.. tks
I want to add spec once it's out of alpha
if ever ๐
@garyberger Meanwhile you can possibly also use https://github.com/borkdude/spartan.spec
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 ]]
Makes sense! Thanks
@borkdude what was again that trick you told me the other day to prevent babashka from stopping? do you remember?
I remember was about deferring something at the end, but I canโt remember the details
@(promise)
was it @(promise)
?
oh heh ๐
yes! thanks ๐
@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.Also just {:doc "run midje" :task tasks/midje}
is supported
this will automatically call the function with *command-line-args*