Fork me on GitHub
#babashka
<
2021-11-11
>
hugod04:11:21

Can a pod expose a dynamic var and allow it to be rebound? clojure.tools.deps.alpha.util.dir/*the-dir* gets used like this.

borkdude09:11:28

This is possible by wrapping functions in client side functions (using :code ) and defining the dynamic var also client side. The wrapper function then sends the value of the dynamic var as an explicit argument to the pod. Inside the pod the explicit argument then is bound to the dynamic var on the pod side.

borkdude09:11:35

As far as I can see tools.build doesn't use that var right?

borkdude10:11:07

If you can explain why you need this, I'm happy to help.

hugod13:11:05

I have the code in place, but am getting clojure.lang.PersistentVector cannot be cast to byte[] Is this likely to be a transit issue. Do byte arrays need explicit handling?

hugod13:11:22

(a simple example pod using transit+json would be very useful)

borkdude13:11:21

@U0HFRSY0M byte arrays are supported by transit out of the box. the postgres sql pod uses transit+json. https://github.com/babashka/babashka-sql-pods/blob/master/src/pod/babashka/sql.clj

borkdude13:11:59

there are also tests with byte arrays there I think

hugod13:11:59

I was looking at that - is the explicit json handling required in general?

borkdude13:11:15

explicit json handling?

hugod13:11:48

set-default-transit-write-handler!, json-str, json-read-handler, jsonb-read-handler, ā€¦

borkdude13:11:35

that is to support non-byte arrays

borkdude13:11:10

the json thing is about serializing a string to json or jsonb

borkdude13:11:14

which is postgres specific

hugod13:11:58

so the transit handling already in place should be sufficient, iiuc

borkdude13:11:01

for byte arrays you shouldn't have to do anything

borkdude13:11:18

yes

šŸ‘ 1
borkdude13:11:51

I'm also using transit in a pod written in go:

;; This pod also supports storing blobs, so lets store a picture.
(def png (java.nio.file.Files/readAllBytes (.toPath (io/file "resources/babashka.png"))))

(sqlite/execute! "/tmp/foo.db"
  ["insert into foo (the_text, the_int, the_real, the_blob) values (?,?,?,?)" "foo" 1 3.14 png])
;;=> {:rows-affected 1, :last-inserted-id 1}

borkdude13:11:12

mostly because of this byte array support

hugod13:11:12

The pattern Iā€™m using is

{:name -pod-root-deps}
{:name root-deps,
 :code
     (clojure.core/defn
      root-deps
      [& args__11819__auto__]
      (-pod-root-deps
clojure.tools.deps.alpha.util.dir/*the-dir*
       args__11819__auto__))}

borkdude13:11:58

so root-deps is a wrapper for -pod-root-deps which it calls with *the-dir* as the first arg. yeah that works

hugod14:11:24

all tools.build tests now pass when running the tests with babashka! Still need to push some things to my fork.

borkdude14:11:45

are you using the cognitect test runner? ;)

hugod15:11:47

No, not yet šŸ™‚

borkdude15:11:03

a nice side effect of this exercise ;)

Mno11:11:03

Cognitest :rolling_on_the_floor_laughing:

šŸ˜‚ 2
Ian Fernandez20:11:01

there's a way to pre-fetch the pod?

Ian Fernandez20:11:02

how can I load pod inside a docker container that runs a babashka script?

borkdude20:11:33

@d.ian.b The recommended approach is to load the pod during the image build

Ian Fernandez20:11:23

there's a way to declare the pod in bb.edn or something?

borkdude20:11:39

RUN bb -e "(load-pod ...)" Not yet, currently in the hammock phase

clojure-spin 1
Darin Douglass20:11:39

something like {:deps {my/pod {:pod/version "1.1.1"}}}?

borkdude20:11:01

something like that, but probably not in deps but in :pods

Ian Fernandez20:11:48

ok šŸ˜„ thanks

borkdude20:11:38

You can also download the pod manually from the github releases and then load it by the filename. (load-pod "/Downloads/pod-foo")

Ian Fernandez20:11:14

=> No executable found for pod borkdude/clj-kondo (2021.06.18) and OS Linux/aarch64 it means that there are no executables for this pod found for my computer?

Ian Fernandez20:11:49

it's running inside a docker :thinking_face:

borkdude20:11:17

we can add aarch64 though

borkdude20:11:13

oh hmm, we don't have an aarch64 release of clj-kondo yet

borkdude20:11:42

are you able to use amd64?

Ian Fernandez20:11:11

I'm bound to M1 Macbook šŸ˜…

Ian Fernandez20:11:18

then no šŸ˜ž

borkdude20:11:25

and m1 docker can only run aarch64 linux?

Ian Fernandez20:11:52

--platform=linux/amd64 

Ian Fernandez20:11:57

there's a flag

Ian Fernandez20:11:29

didn't worked šŸ˜ž

borkdude20:11:22

What did it say?

borkdude20:11:44

There is an issue for clj-kondo here: https://github.com/clj-kondo/clj-kondo/issues/1238 Feel free to upvote it to give higher priority

clojure-spin 1
borkdude20:11:50

@U7ERLH6JX might also have something to say about this

Ian Fernandez20:11:57

docker build --platform,,,, worked

Ian Fernandez20:11:06

after docker rmi

Ian Fernandez20:11:27

thanks as always @borkdude šŸ˜„

šŸ‘ 1