babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
Karol Wójcik 2021-04-25T08:11:36.022500Z

@borkdude how can I point to remote scripts? This is what I have now:

{:paths ["<https://github.com/FieryCod/holy-lambda/tree/master/modules/holy-lambda-babashka-tasks/script/>"]

 :holy-lambda/options {:build-tool    :lein ;; or :deps
                       :runtime       {:name :babashka} ;; Possible runtime :babashka, :native, :java
                       }

 :infrastructure {:bucket-prefix  "prefix"
                  :bucket-name    "bucket"
                  :region         "region"}

 :tasks {:requires                ([holy-lambda.tasks])

         docker:build:ee          holy-lambda.tasks/docker-build-ee
         sync:update              holy-lambda.tasks/sync:update
         version                  holy-lambda.tasks/version
         doctor                   holy-lambda.tasks/doctor
         purge                    holy-lambda.tasks/purge}}
When running the task the script is not found.

borkdude 2021-04-25T08:37:00.023Z

@karol.wojcik Where did you get the idea that "remote scripts" were supported :-D?

borkdude 2021-04-25T08:37:20.023400Z

You can make a git library from it and point to it in :deps same as with deps.edn

Karol Wójcik 2021-04-25T08:37:39.023500Z

Karol Wójcik 2021-04-25T08:37:55.024Z

😄

borkdude 2021-04-25T08:38:13.024500Z

Oh, I misinterpreted that. I thought you meant: is it ok if I share the link to a library on github in this channel :)

Karol Wójcik 2021-04-25T08:38:36.024900Z

Will try the deps.edn approach then 😄

borkdude 2021-04-25T08:39:05.025100Z

@karol.wojcik What was the other bug you found?

Karol Wójcik 2021-04-25T08:40:55.026Z

{:paths ["script"
         ;; "<https://github.com/FieryCod/holy-lambda/tree/master/modules/holy-lambda-babashka-tasks/script/>"
         ]

 :holy-lambda/options {:build-tool    :lein ;; or :deps
                       :runtime       {:name :babashka} ;; Possible runtime :babashka, :native, :java
                       }

 :infrastructure {:bucket-prefix  "prefix"
                  :bucket-name    "bucket"
                  :region         "region"}

 :tasks {:requires                ([holy-lambda.tasks :as tasks])

         docker:build:ee          tasks/docker-build-ee &lt;-- needs fully qualified symbol otherwise it does not work.
         sync:update              tasks/sync:update
         version                  tasks/version
         doctor                   tasks/doctor
         purge                    tasks/purge
         }}

Karol Wójcik 2021-04-25T08:41:40.026900Z

Using :as does not work in :requires when script is from :paths

borkdude 2021-04-25T08:42:33.027200Z

oh cool, I'll fix that

borkdude 2021-04-25T09:27:54.027400Z

Fixed on master

borkdude 2021-04-25T09:28:41.027900Z

@karol.wojcik Was this bug only related to bb tasks docstrings or also to execution of these tasks?

borkdude 2021-04-25T09:29:20.028100Z

I guess also to execution, will also fix that

borkdude 2021-04-25T09:42:17.028300Z

Fixed on master

Karol Wójcik 2021-04-25T09:54:11.028700Z

Both AFAIK

borkdude 2021-04-25T09:56:40.029500Z

I am contemplating letting tasks not print the return value by default (like scripts always have done so far which might have been a mistake, but accidentally happened) But still it is convenient to view the result of a (helper) task to debug.

borkdude 2021-04-25T09:57:07.030100Z

So maybe bb run --prn foo could be used to explicitly print and bb foo doesn't print

borkdude 2021-04-25T10:01:41.030600Z

Or maybe it should be a property of a task if it will print or not?

borkdude 2021-04-25T10:02:15.031300Z

{:tasks {foo {:print true :task (System/getenv "FOOBAR")}}}

borkdude 2021-04-25T12:20:19.031700Z

babashka 0.3.6 released See CHANGELOG.md: https://github.com/babashka/babashka/blob/master/CHANGELOG.md

borkdude 2021-04-25T12:23:04.032500Z

@mike1452 shell now supports :continue true to ignore the exit code (so it won't exit bb in that case)

borkdude 2021-04-25T12:24:01.033Z

Also tasks do not print their return value anymore (unless explicitly done or using the run --prn command line opts)

borkdude 2021-04-25T12:25:05.033400Z

It's also possible to use the return value of shell and clojure now

borkdude 2021-04-25T12:25:37.033900Z

And there is some logging around task names and shell/clojure arguments when setting :log-level :info in the task(s)

borkdude 2021-04-25T12:26:01.034400Z

There is also a :min-bb-version to print a warning in case people use an older one (top level in bb.edn)

borkdude 2021-04-25T12:26:36.034700Z

It's all documented here: https://book.babashka.org/#_bb_edn and here: https://github.com/babashka/babashka/issues/778

borkdude 2021-04-25T13:03:10.036100Z

Please do try out your bb with {:tasks {:log-level :info ...}} to see if it's useful

mike_ananev 2021-04-25T13:29:37.037700Z

@borkdude cool! I'll check new version and change my templates. You are doing awesome work!

Karol Wójcik 2021-04-25T15:48:53.038700Z

@borkdude can I pass my own decoration fn for log-level?

borkdude 2021-04-25T15:52:24.039100Z

no not yet. I think I might revise the entire log thing based on some feedback

borkdude 2021-04-25T15:53:25.040100Z

to experiment: there is babashka.tasks/*-task-name* , babashka.tasks/-log-info and babashka.tasks/-log-error and you can probably roll your own thing with this

👍 1
borkdude 2021-04-25T15:53:46.040600Z

all implementation details which will change, but feel free to play around and provide feedback

Karol Wójcik 2021-04-25T16:08:04.041400Z

Did I ask how to run babashka tasks like in makefile? make clean pack deploy? 😄

Karol Wójcik 2021-04-25T16:08:13.041700Z

Will experiment with it

borkdude 2021-04-25T16:09:07.042500Z

@karol.wojcik bb doesn't yet have a way to do this, other than bb clean &amp;&amp; bb pack &amp;&amp; bb deploy or do that in a task using three shell calls

borkdude 2021-04-25T16:09:51.043100Z

I am considering doing something like bb run clean, pack, deploy like comma separated values like lein do has

borkdude 2021-04-25T16:10:06.043400Z

so you can still pass args to the tasks

Karol Wójcik 2021-04-25T16:10:33.044Z

Exactly that would work, since I'm parsing the arguments for holy-lambda.

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

Made an issue: https://github.com/babashka/babashka/issues/804 But still I'm not yet certain how much needed this is, since it's not much more typing than just using &amp;&amp; and like @jeroenvandijk has said: lein do is also about startup time of the JVM, a problem that bb doesn't have.

👍 1
2021-04-26T07:35:48.085100Z

There is one thing that might be interesting at some point. When I have nested babashka calls for simple tasks I noticed some extra delay (every bb call is 30ms). So it might be handy to be able to call babashka in process. I’m guessing this would easily beat the 30ms penalty and could have the same isolation (starting with empty context, copy env vars etc)

2021-04-26T07:37:38.085300Z

I’m also wondering if you can do multiple clojure calls in one. This would be interesting for commands that shell out to clojure multiple times (i see some examples here https://clojurians.slack.com/archives/CLX41ASCS/p1619387075084200)

borkdude 2021-04-26T07:45:56.085800Z

For bb this is certainly possible. Another possibility is to have an explicity run function that runs another task within another task. I'm guessing this is what you are doing in your task? For clojure this is not possible, since that lives in a different process and different calls are going to have different classpaths, etc.

2021-04-26T07:48:17.086Z

Yeah run sounds interesting. Another thing I ran into was that i wanted to have my own uberjar command, but using the bb uberjar task. Not sure if this is smart, but I noticed that I couldn’t call the overrided task. Not sure if run would solve this as well

2021-04-26T07:50:31.086200Z

I’m also experimenting with creating a module system. I’m loading babashka files dynamically based on the command that’s given. I’m not sure yet where this is going, but it’s an example of where I’m calling babashka from babashka.

borkdude 2021-04-26T08:24:44.086400Z

@jeroenvandijk Could you share your bb.edn perhaps (in secret?) so I can see that is needed with respect to this run function?

borkdude 2021-04-26T08:25:28.086600Z

The priority in which things are run is file > task > subcommand. So if you have a file or task named uberjar this will hide the uberjar subcommand.

👍 1
2021-04-26T08:29:09.086800Z

I don’t really have one proper bb.edn . I’m working on multiple projects and I’m still figuring things out mostly. (maybe i missed something, but one central bb.edn is not a thing yet, right?)

borkdude 2021-04-26T08:29:50.087300Z

bb.edn is supported in the current working directory (of a project)

2021-04-26T08:30:27.087800Z

ah ok indeed. Yeah i was trying to figure out how to reuse the same tasks over different projects.

2021-04-26T08:32:21.088100Z

I’m trying to move away from leiningen and boot, but I miss some standards. Hence my idea for some kind of universal module system

2021-04-26T08:34:26.088300Z

E.g. I think this is nice https://github.com/practicalli/clojure-deps-edn But I don’t want to lookup all the commands I need to use. I was thinking of wrapping (some of) these commands in babashka tasks. I would like to do things like bb help -> list everything, bb help &lt;cmd&gt; -> list all sub commands. A bit like the cli tool of AWS

borkdude 2021-04-26T08:40:26.089100Z

We've already moved away from boot to deps.edn at work now. The benefit of lein is that it has a standard way of doing things indeed. bb.edn is more like Make / npm scripts: it contains project-specific things. But perhaps some standards will evolve...

2021-04-26T08:42:31.089300Z

Nice 🙂

borkdude 2021-04-26T09:01:57.089600Z

Btw maybe there is a nice workaround for file / task / subcommand conflicts. As of now, each bb subcommand is also accessible by --uberjar instead of uberjar. A local file is also accessible by bb ./uberjar And a task is also accessible by bb run uberjar. So if we maintain the --uberjar CLI option in the future, there's always a way out...

2021-04-26T09:08:05.089800Z

Sounds good!

borkdude 2021-04-25T16:15:13.045700Z

This might also conflict with passing JSON or EDN values on the command line. Not sure how well lein do copes with that.

Karol Wójcik 2021-04-25T16:22:29.046100Z

Does it look cool?

👍 2
Karol Wójcik 2021-04-25T16:26:06.046900Z

There is one thing I would love to see. Ordering of bb tasks

Karol Wójcik 2021-04-25T16:26:43.047600Z

:tasks {:requires                ([holy-lambda.tasks])
         :log-level               :info

         docker:build:ee          holy-lambda.tasks/docker-build-ee
         bucket:create            holy-lambda.tasks/create-bucket
         bucket:remove            holy-lambda.tasks/remove-bucket
         stack:destroy            holy-lambda.tasks/stack-destroy
         stack:deploy             holy-lambda.tasks/stack-deploy
         version                  holy-lambda.tasks/version
         doctor                   holy-lambda.tasks/doctor
         purge                    holy-lambda.tasks/purge
         logs                     holy-lambda.tasks/logs}}
Here is the preferred order

Karol Wójcik 2021-04-25T16:30:37.048500Z

Maybe it could be taken from the metadata of the function

borkdude 2021-04-25T16:31:17.049400Z

Hmm, we could support sorting if we supported the notation:

{:tasks
  [[:requires ...]
   [:log-level ...]
   [docker-build foobar]]
}

👍 1
borkdude 2021-04-25T16:31:44.049800Z

but because it's a map, we cannot preserve the order

👍 1
Karol Wójcik 2021-04-25T16:32:11.050100Z

Are you interested in preserving the order or you just don't care?

borkdude 2021-04-25T16:33:53.051500Z

I think it would be nice, we could support a vector notation like this:

{:tasks [
  :requires ...
  :log-level ...
   docker-build foobar
]
}
so same as a map but within a vector to indicate the sort order

👍 1
Karol Wójcik 2021-04-25T16:35:25.052Z

Yep. Btw how can I overwrite babashka.tasks/log-info? I'm not familiar with sci.

borkdude 2021-04-25T16:38:06.052700Z

Same as in clojure, just use def. The name is -log-info (indicating that it is an impl detail)

borkdude 2021-04-25T16:38:41.053100Z

oh you want to intern it into the babashka.tasks namespace

Karol Wójcik 2021-04-25T16:39:13.053600Z

Yep. tried to use alter-var-root but it doesn't work.

borkdude 2021-04-25T16:39:31.053900Z

it should

borkdude 2021-04-25T16:39:35.054100Z

show me what you did then

Karol Wójcik 2021-04-25T16:42:08.054400Z

(alter-var-root #'babashka.tasks/-log-info
                  (fn [&amp; strs]
                    (println "xx" strs)))

Karol Wójcik 2021-04-25T16:42:31.054700Z

~/Workspace/Work/holy-lambda/modules/holy-lambda-babashka-tasks master*
❯ bb doctor
xx (#object[babashka.impl.tasks$log_info 0x38037185 babashka.impl.tasks$log_info@38037185])
----- Error --------------------------------------------------------------------
Type:     java.lang.NullPointerException

borkdude 2021-04-25T16:46:09.055100Z

you need to pass a function which returns a function to alter-var-root, same as in clojure ;)

borkdude 2021-04-25T16:50:50.055500Z

@karol.wojcik Use constantly around the function, for example

borkdude 2021-04-25T16:50:54.055700Z

afk for dinner now

Karol Wójcik 2021-04-25T16:51:04.055900Z

Ahh you're right. Thanks!

pithyless 2021-04-25T18:04:21.058800Z

Any chance we could add https://github.com/clj-commons/ordered to babashka? Then perhaps we could use the #ordered/map literal when defining tasks in bb.edn ? Having the ordered literal around could be useful in a couple of places when working with bb in general :]

👍 1
borkdude 2021-04-25T18:06:02.059700Z

@pithyless afaik that is already available:

bb -e "(use 'flatland.ordered.map)"
(but not the .set namespace I noticed)

borkdude 2021-04-25T18:06:33.059900Z

but you're right, that could be a nice solution

borkdude 2021-04-25T18:11:47.061600Z

@dharrigan btw your suggestion of having the argument order (copy-into dir f1) has been suggested by other people as well + the suggestion of making it varargs:

(copy-into dir f1 f2 f3)
If this comes up more often, I'll re-consider it. For now copy just accepts the unix semantics as well

👍 1
borkdude 2021-04-25T18:13:51.063Z

(one of the difficulties in that case is: where to put the options)

pithyless 2021-04-25T18:14:37.063700Z

oh, I didn't realize the literal syntax is #ordered/map ([:a 1] [:d 4] [:b 7]) ; I was hoping it still looked mostly like a map

borkdude 2021-04-25T18:15:07.064300Z

ah crap, yeah, I guess it can't be a map literal because by the time the lib sees it the order has already been messed up

☝️ 1
borkdude 2021-04-25T18:15:38.065Z

so we might as well go with [:a 1 :b 2 :c 3] as the alternative notation?

borkdude 2021-04-25T18:16:16.065900Z

and then use apply hash-map for map semantics, but use the order for printing

pithyless 2021-04-25T18:17:22.067Z

uhh, I'd vote for [[:a 1] [:b 2]] (I guess that's the compromise malli ordered-maps also settled on)

👍 1
borkdude 2021-04-25T18:19:09.067500Z

{:tasks [[:requires ([babashka.fs :as fs])]
         [ls (shell "ls")]
         [clear {:doc "blabla"
                 :task (shell "rm -rf targt")}]]}
vs
{:tasks [:requires ([babashka.fs :as fs])
         ls (shell "ls")
         clear {:doc "blabla"
                :task (shell "rm -rf targt")}]}

borkdude 2021-04-25T18:20:01.069100Z

yeah ok, the first one might be more "idiomatic", although (require '[foo :as x :refer [1 2 3]) is similar to the first one

borkdude 2021-04-25T18:20:22.069800Z

as in, it squashes basically a map in a vector

pithyless 2021-04-25T18:21:02.070900Z

I'm still wondering if it's worth it; the map syntax is nice and perhaps the order of task printing is a separate concern? i.e. it can be a separate thing in bb.edn (either a vector or even a function that sorts -- or even groups -- tasks by some logic)?

borkdude 2021-04-25T18:21:08.071100Z

alternatively, we could support something like a :print-order function or literal, but this might be duplication of names

borkdude 2021-04-25T18:21:32.071500Z

hah

borkdude 2021-04-25T18:22:05.072700Z

yeah, you are right, I was also thinking a function which can sort the tasks topologically, so you get the "main" tasks first for example

👍 1
pithyless 2021-04-25T18:22:51.073800Z

having a :print-order function or literal sounds like the better approach; I'm wondering if the default implementation couldn't even be something crazy like slurping in bb.edn and generating the list of tasks by parsing the edn "by hand"?

Karol Wójcik 2021-04-25T18:24:54.075500Z

I would like to hide as much of tasks implementation from the user as it is possible. If I could hook to some kind of babashka.tasks/print-order function from tasks impl I would be most satisfied.

borkdude 2021-04-25T18:24:55.075700Z

I think babashka could cheat

borkdude 2021-04-25T18:25:17.076200Z

by determining the position of the first key in the map and then read the tokens one by one until it encounters }

👍 2
Karol Wójcik 2021-04-25T18:25:37.076600Z

Seems like a hack, but I like it

pithyless 2021-04-25T18:25:59.076800Z

that's kind of what I had in mind

borkdude 2021-04-25T18:27:39.078100Z

it's actually pretty easy since edamame can read the begin and end position of the tasks map, then just strip all of that stuff away, read it as a vector (by wrapping) and done

pithyless 2021-04-25T18:28:55.078900Z

I forgot you had the power of edamame to wield freely

borkdude 2021-04-25T18:31:10.079900Z

I don't use it currently to read the edn (I want to make sure the .edn is compatible with the regular EDN reader) but for the printing of the tasks, I will 👿

borkdude 2021-04-25T18:44:49.081200Z

Maybe two blank lines means one empty line will be printed in the output as well, for some grouping?

borkdude 2021-04-25T18:47:09.082100Z

Heck, I could even use rewrite-clj for this since it’s bundled with bb now

borkdude 2021-04-25T21:21:15.084Z

The printing of namespaces conform their occurrence should work now on master (binary available in #babashka-circleci-builds)

borkdude 2021-04-25T21:44:35.084200Z

👍 5