babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
Karol W贸jcik 2021-04-21T10:38:10.308400Z

We're talking with @viesti about holy-lambda support for babashka runtime. I would love to provide the same interface for babashka as I do for both Java and native runtime. My questions are: 1. Is it possible to pack some macros in babashka pod? If it's possible then on weekend I would release holy-lambda with babashka support 馃槃 2. Can babashka artifacts be packed in zip?

馃憤 2
borkdude 2021-04-21T10:40:01.309300Z

@karol.wojcik Yes, it is possible to define macros in pods. This is done using :code which defines "client side" code.

borkdude 2021-04-21T10:40:52.310100Z

> Can聽babashka聽artifacts be packed in zip? Not sure what you're asking here. I will go for a run but will be back later.

borkdude 2021-04-21T10:42:24.311500Z

@karol.wojcik https://github.com/babashka/pods#client-side-code

鉂わ笍 1
Karol W贸jcik 2021-04-21T10:45:43.312900Z

I want to provide holy-lambda.pod which exposes all the functions and macros to babashka. As I understand it babashka might be packed in the zip, but may I pack the dependencies in zip as well? If yes then in what format should I keep those dependencies?

borkdude 2021-04-21T11:25:51.313800Z

@karol.wojcik Let's back up a bit. What does unholy lambda do that it needs to be a pod instead of, let's say, a script?

viesti 2021-04-21T11:34:24.314400Z

might be that @karol.wojcik realised that on #holy-lambda lambda, but I'll let him explain (explaining out leaves mental tracks :))

Karol W贸jcik 2021-04-21T11:41:52.314700Z

I don't know much about babashka. I've used very basic functionality of it to speedup docker builds in my company. @viesti said that babashka can read namespaces from .jar file as well, so maybe it would work that way. Still though don't know how to provide .jar dependencies to babashka.

borkdude 2021-04-21T11:43:57.314900Z

@karol.wojcik It depends what kinds of dependencies. Not all Clojure dependencies are compatible with bb. So that's why I asked the above question.

borkdude 2021-04-21T11:44:20.315100Z

You can run jar files with bb -cp foo.jar -m foo for example

Karol W贸jcik 2021-04-21T11:47:29.315300Z

Thanks. I can see that clojure.lang.RT is not supported.

borkdude 2021-04-21T11:49:17.315500Z

That is correct, RT is an implementation detail of Clojure. https://ask.clojure.org/index.php/10303/interop-clojure-pattern-clojure-consider-adding-iter-clojure?show=10305#a10305

馃憤 1
Karol W贸jcik 2021-04-21T11:49:44.315800Z

I will create a following patch:

#?(:bb
   (defn- process-interceptors
     [mixin payload type]
     (if-let [interceptors (seq (:interceptors mixin))]
       (loop [interceptors interceptors
              result payload]
         (if-not (seq interceptors)
           result
           (recur (rest interceptors) (if-let [interceptor (type (first interceptors))] (interceptor result) result))))
       payload))
   :clj
   (defn- process-interceptors
     [?mixin ?payload ?type]
     (if-let [it (some-> ?mixin :interceptors clojure.lang.RT/iter)]
       (loop [result ?payload]
         (if (.hasNext it)
           (recur
            (if-let [interceptor (some-> (.next it) ?type)]
              (interceptor result)
              result))
           result))
       ?payload)))

borkdude 2021-04-21T11:50:47.316Z

yeah that makes sense

borkdude 2021-04-21T11:51:42.316200Z

You can suggest that you need RT for this iter method in that issue, it's pretty much the nr 1 reason why people depend on RT...

Karol W贸jcik 2021-04-21T11:51:52.316400Z

Ok. Babasha fails on including jsonista 馃槥

----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: jsonista.jackson.DateSerializer
Location: jsonista/core.clj:50:3

----- Context ------------------------------------------------------------------
46:   jsonista uses Jackson Databind while Cheshire uses Jackson Core. In our
47:   benchmarks, jsonista performs better than Cheshire (take look at
48:   json_perf_test.clj). On the other hand, Cheshire has a wider set of features
49:   and has been used in production much more."
50:   (:import
      ^--- Unable to resolve classname: jsonista.jackson.DateSerializer
51:     (jsonista.jackson
52:       DateSerializer
53:       FunctionalKeyDeserializer
54:       FunctionalSerializer
55:       KeywordSerializer

borkdude 2021-04-21T11:52:09.316600Z

babashka has cheshire.core, not jsonista

borkdude 2021-04-21T11:52:30.316800Z

currently

Karol W贸jcik 2021-04-21T11:52:42.317Z

Will it change in future?

Karol W贸jcik 2021-04-21T11:53:03.317200Z

Ok I will just use reader conditionals to use cheshire instead

馃憤 2
Karol W贸jcik 2021-04-21T11:53:04.317400Z

馃檪

borkdude 2021-04-21T11:53:09.317600Z

Well, I probably won't remove it since that will be breaking, but perhaps add more options later, not sure.

borkdude 2021-04-21T11:54:38.318Z

To save you some time, what other deps are you using?

borkdude 2021-04-21T11:54:49.318200Z

Then I can tell you if that will work or not

Karol W贸jcik 2021-04-21T11:55:43.318400Z

It's all I'm using.

Karol W贸jcik 2021-04-21T11:56:04.318600Z

Probably in 30 minutes I will have babashka example working.

borkdude 2021-04-21T11:56:41.318800Z

nice!

Karol W贸jcik 2021-04-21T12:41:50.319200Z

@borkdude May i ship babashka with holy-lambda?

borkdude 2021-04-21T12:42:31.319400Z

Sure

Karol W贸jcik 2021-04-21T12:55:30.319600Z

Got it working

Karol W贸jcik 2021-04-21T12:55:59.319800Z

@borkdude What is some babashka internal thing that I can prove it's running on babashka?

Karol W贸jcik 2021-04-21T13:00:48.320Z

Ok will use babashka.main.version 馃槃

Karol W贸jcik 2021-04-21T13:06:17.320200Z

Huh. babashka.main is not available in scripts? 馃槷

borkdude 2021-04-21T13:11:50.322700Z

You can do (System/getProperty babashka.version) (sorry typing on phone)

Karol W贸jcik 2021-04-21T13:14:09.323400Z

Not officially announcing yet, but holy-lambda with some minor tweaks can run on either java, native or babashka 馃檪 Thanks @borkdude @viesti

(ns babashka-example.core
  (:gen-class)
  (:require
   [fierycod.holy-lambda.retriever :as r]
   [fierycod.holy-lambda.interceptor :as i]
   [fierycod.holy-lambda.agent :as agent]
   [fierycod.holy-lambda.native-runtime :as native]
   [fierycod.holy-lambda.response :as hr]
   [fierycod.holy-lambda.core :as h]))

(i/definterceptor LogIncommingRequest
  {:enter (fn [request]
            (println "Log incomming request:" request)
            request)})

(h/deflambda HelloBabashka <
  {:interceptors [LogIncommingRequest]}
  [{:keys [ctx]}]
  #?(:bb
     (hr/text (str "Babashka is sweet friend of mine! Babashka version: " (System/getProperty "babashka.version")))
     :clj (hr/text "Why you didn't use babashka? ;/")))


(native/entrypoint [#'HelloBabashka])

(agent/in-context
 (println "In agent context"))
https://bdsa1uru44.execute-api.eu-central-1.amazonaws.com/Prod/

馃憤 3
Karol W贸jcik 2021-04-21T13:14:40.323500Z

Thank you! Got this working 馃檪 https://bdsa1uru44.execute-api.eu-central-1.amazonaws.com/Prod/

馃帀 1
borkdude 2021-04-21T13:53:16.324600Z

Nice!!! @karol.wojcik

Karol W贸jcik 2021-04-21T13:54:28.325600Z

Babashka is well implemented I must say. It was just easy to provide such runtime. You're doing great work @borkdude

Dig 2021-04-21T14:17:30.326200Z

https://github.com/FieryCod/holy-lambda/blob/master/Makefile another candidate for new tasks 馃檪

Karol W贸jcik 2021-04-21T14:19:05.326300Z

It's not so big 馃槃 But this is great candidate: https://github.com/FieryCod/holy-lambda/blob/master/modules/holy-lambda-template/resources/leiningen/new/holy_lambda/Makefile

Dig 2021-04-21T14:50:45.326600Z

Ah yes that is the one I was thinking about, reading tutorial.

Karol W贸jcik 2021-04-21T14:50:59.326800Z

There is not much yet in tutorial. Would love to work on it more, but my time is very limited 馃槥

Karol W贸jcik 2021-04-21T15:09:43.327300Z

May I please announce the new version here as well @borkdude? Just once to let people know about babashka runtime :)

borkdude 2021-04-21T15:11:34.327500Z

Of course!

Karol W贸jcik 2021-04-21T15:11:43.327700Z

Thank you so much 馃檪

Karol W贸jcik 2021-04-21T15:15:00.328100Z

As per @borkdude permission, I'm cross-posting this announcement here as well. If you interested in babashka layer then please put :babashka: in official announcement. Hope that #holy-lambda will make some new friends in #babashka community 馃檪

4
Karol W贸jcik 2021-04-21T15:54:02.330500Z

Just checked babashka tasks. @borkdude I would love to have them in the project. Is it possibile to provide tasks in jar then somehow automatically merge user and jar tasks?

borkdude 2021-04-21T15:56:05.330700Z

Right now bb tasks is only supports in bb.edn

borkdude 2021-04-21T16:00:24.332300Z

Did some more automation, this time around the clj-kondo LSP server: https://github.com/clj-kondo/clj-kondo.lsp/blob/master/bb.edn I can't believe I did many of these steps manually, it's all very tedious. And almost every step depends on a previous step so a perfect fit for tasks. Also used fs/modified-since again to not rebuild the jar if nothing changed.

馃憤 4
Karol W贸jcik 2021-04-21T16:01:52.333800Z

Ok got it. Will manualy copy bb.edn from one repository to another.

2021-04-21T16:56:05.336600Z

There's a babashka asdf plugin, but the 0.3.* releases don't work. Is this something that should be fixed in the asdf plugin? The code is here: https://github.com/fredZen/asdf-babashka/blob/master/lib/utils.bash#L34

$ asdf install babashka latest
* Downloading babashka release 0.3.5...
curl: (22) The requested URL returned error: 404
asdf-babashka: Could not download <https://github.com/borkdude/babashka/releases/download/v0.3.5/babashka-0.3.5-linux-amd64.zip>
asdf-babashka: An error ocurred while installing babashka 0.3.5.

$ asdf install babashka 0.2.1
* Downloading babashka release 0.2.1...
Archive:  /home/aleks/.asdf/installs/babashka/0.2.1/babashka-0.2.1.zip
  inflating: /home/aleks/.asdf/installs/babashka/0.2.1/bin/bb  
babashka 0.2.1 installation was successful!

borkdude 2021-04-21T17:28:14.337300Z

@madstap Might be related to a migration from .zip to .tar.gz

2021-04-21T17:44:50.339500Z

False alarm, someone fixed it (just an hour ago)

borkdude 2021-04-21T17:45:39.339700Z

Nice co-incidence

2021-04-21T17:49:17.340500Z

Might be worth mentioning asdf in the install section of the readme?

borkdude 2021-04-21T17:51:11.340800Z

Feel free to PR anything that's worth mentioning there

馃憤 2
russmatney 2021-04-21T21:13:03.342Z

Is it possible to exclude files from being included in a jar via the bb uberjar command?

russmatney 2021-04-21T21:13:18.342100Z

I'm moving from an uberscript to an uberjar to make use of pods in a bb-based tool. Building with:

bb uberjar clawe.jar -cp $(clojure -A:remove-clojure -Spath) -m clawe.core
The jar seems to include everything in the build directory, including .git history. I'm hopeful there won't be a performance hit, so want to reduce the jar size as much as possible, but this feels more like a bug. I did find this https://github.com/babashka/babashka/issues/780 which might be relevant.

russmatney 2021-04-21T21:14:05.342400Z

I can take a shot at a reproduction or a PR if it's helpful - not sure what the expected behavior is

borkdude 2021-04-21T21:14:39.342600Z

@russell.matney you should set the classpath before the uberjar command probably

borkdude 2021-04-21T21:15:05.342800Z

bb -cp $(clojure -A:remove-clojure -Spath) uberjar clawe.jar  -m clawe.core
can you try that?

russmatney 2021-04-21T21:15:31.343Z

----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  File does not exist: uberjar

russmatney 2021-04-21T21:15:41.343200Z

I tried that first to match the docs, but i get this error

borkdude 2021-04-21T21:16:46.343400Z

ok, try this:

bb --classpath server/src --uberjar foo.jar

borkdude 2021-04-21T21:16:51.343600Z

this is the old style

borkdude 2021-04-21T21:17:11.343800Z

clearly something is wrong, please add to the issue

馃憤 1
borkdude 2021-04-21T21:17:16.344Z

and PR is welcome to fix it

russmatney 2021-04-21T21:18:27.344300Z

that seems to build properly, and more reasonably sized - i'm seeing a number of warnings for clashing jar items, which is interesting

{:warning "clashing jar item", :path ".cpcache/1246900521.cp", :strategy :noop}
{:warning "clashing jar item", :path ".cpcache/0DF01609C7D30D4D8B3579B5256F3E83.libs", :strategy :noop}
{:warning "clashing jar item", :path ".cpcache/1246900521.basis", :strategy :noop}
...

borkdude 2021-04-21T21:22:46.344600Z

try removing the jar file before uberjaring again

馃憤 1
russmatney 2021-04-21T21:22:49.344800Z

It could also be a strange path being built on my part - when i run

bb -cp src/clawe --uberjar clawe.jar -m clawe.core
it builds almost instantly, and the result seems to work fine (and is fast!)

russmatney 2021-04-21T21:25:44.345100Z

this is great - the uberjar is at least as fast as the uberscript

bb clawe.jar hello  0.11s user 0.03s system 102% cpu 0.139 total
vs
bb clawe-script.clj hello  0.12s user 0.05s system 103% cpu 0.160 total
very happy to learn that this will work

russmatney 2021-04-21T21:25:52.345300Z

thanks for the debugging help @borkdude!

borkdude 2021-04-21T21:31:24.345600Z

ok. I see the command line parsing in the tests is different from the help

russmatney 2021-04-21T21:31:36.345800Z

I figured out why it was adding everything - my clojure -Spath had a few empty entries in it :: (`src::/home/russ/russmatney/ralphie/src:/etc` ), which seemed to add the entire current directory

borkdude 2021-04-21T21:31:38.346Z

in the tests it accepts --classpath as an argument to the uberjar task

borkdude 2021-04-21T21:32:05.346200Z

oh that's another bug then probably

borkdude 2021-04-21T21:32:22.346400Z

please comment all your problems to the issue

russmatney 2021-04-21T21:32:33.346600Z

will do!

russmatney 2021-04-21T22:05:41.346800Z

Issue updated - the new info is that it looks like the 'blanks' in the classpath are coming from the classpath-overrides

{:aliases
 {:remove-clojure
  {:classpath-overrides
   {org.clojure/clojure          nil
    org.clojure/spec.alpha       nil
    org.clojure/core.specs.alpha nil}}}
==&gt; resulting path:
src::/home/russ/russmatney/ralphie/src:::/home/russ/.m2/repository/cheshire/cheshire/5.10.0/cheshire-5.10.0.jar:/home/russ/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.10.2/jackson-core-2.10.2.jar:/home/russ/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-cbor/2.10.2/jackson-dataformat-cbor-2.10.2.jar:/home/russ/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-smile/2.10.2/jackson-dataformat-smile-2.10.2.jar:/home/russ/.m2/repository/tigris/tigris/0.1.2/tigris-0.1.2.jar

borkdude 2021-04-21T22:27:53.347100Z

@russell.matney Note that you can now also set the classpath in bb.edn under :paths

borkdude 2021-04-21T22:28:07.347300Z

but we should still fix this regardless

russmatney 2021-04-21T22:30:16.347500Z

gotcha - i'll move over to use that