Fork me on GitHub
#babashka
<
2021-12-18
>
Cnly02:12:25

A short question: Does/Can bb uberscript package pods into the output? I didn’t find the info in the docs…

borkdude09:12:37

Pods are binary files and uberscripts are just text. Pods aren't packaged within the scripts.

Cnly11:12:16

Makes sense. Thanks!

ericdallo14:12:09

I'm reading https://github.com/babashka/pods docs and having trouble understanding how it works the pod process 🧵

ericdallo14:12:32

I see that the readme mention about pod client sending a bencode encoded message {"op" "describe"}

ericdallo14:12:06

but testing with clj-kondo pod how can I test that locally? I tried:

echo 'd2:op8:describee' | clj-kondo

ericdallo14:12:37

how the communication works? because just running clj-kondo prints the help and quit

ericdallo14:12:40

My question is more like, how the proccess is kept open to receive and send bencode if running clj -M:clj-kondo/dev just print the help and quit

ericdallo14:12:05

what magic pods/load-poddoes that makes that work?

ericdallo14:12:54

hummmm, I think I got it

ericdallo14:12:16

the pods spawn the process with BABASHKA_POD as true , now that makes sense

ericdallo15:12:12

problem solved :)

borkdude15:12:37

Feel free to add doc improvements

👍 1
ericdallo15:12:11

I'm implementing clojure-lsp babashka pod 🚀 , some questions 🧵

🎉 2
🚀 1
babashka 2
ericdallo15:12:39

all clojure-lsp api functions receive a arg project-root which is a http://Java.io.File

ericdallo15:12:57

it seems, edn/transit/json doesn't support passing that right?

borkdude15:12:38

true, but! you can make a transit handler for this

borkdude15:12:55

but you might as well use a string I guess

ericdallo15:12:11

hum, and just convert to io file when receiving right?

borkdude15:12:44

yes, but if you want, we can make it work with files via transit. let me look up how this worked

ericdallo15:12:46

I get this when using edn:

ericdallo15:12:53

is it possible to add a reader for that on edn?

borkdude15:12:33

I recommend using transit, it's much easier in that case

borkdude15:12:11

or were you trying to avoid the transit dependency?

borkdude15:12:20

well clj-kondo already uses transit so you already have it I guess

ericdallo15:12:52

I already have that because of datalevin :)

ericdallo15:12:14

will change to transit

borkdude15:12:14

and also a couple of lines below

borkdude15:12:26

so both babashka and the pod will be able to exchange that type

borkdude15:12:39

and you can do this for files as well

borkdude15:12:17

pods are supposed to support it, it's not considered a hack

ericdallo15:12:21

thanks, I'll try to create that

borkdude15:12:38

I mean, babashka.pods support it and pods can use it

ericdallo15:12:02

shouldn't babashka.pods support that by default?

ericdallo15:12:19

like, if other pods need to send File, would be needed to do the same, right?

borkdude15:12:52

yes, but each pod registers the handler under their own key, so they don't conflict

ericdallo15:12:40

maybe having a common handler, a babashka built-in one or something

ericdallo15:12:58

besides that File issue, everything seems to be working :)

ericdallo15:12:03

really cool!

ericdallo15:12:06

Someone at nubank asked this week if there was a way to run clojure-lsp from babashka and I remembered this pod issue 😅

borkdude15:12:31

Perhaps we can just expose the ns as clojure-lsp.api

borkdude15:12:39

so the code will be the same in the JVM as in babashka

ericdallo15:12:52

sounds better indeed

ericdallo15:12:08

I was just following the pattern from <user-id>.<project>

ericdallo15:12:13

but that looks better

borkdude15:12:22

I know I recommended pod.x.x. but I changed my mind on that. We also do it in tools.bbuild: we use the tools.deps.alpha pod which just exposes those namespaces

ericdallo15:12:32

good to know!

borkdude15:12:39

and then tools.bbuild which is a minor fork of tools.build can run with almost no changes

ericdallo15:12:58

makes sense!

borkdude15:12:10

the builds are really fast using that thing

ericdallo15:12:32

I can imagine that haha

ericdallo15:12:38

babashka rocks!

borkdude15:12:52

clojure-lsp does too! :)

borkdude15:12:00

and the combination... 🤯

borkdude15:12:24

What you can also do if you don't want to do the file transformation via transit, is create a client side wrapper function via "code"

ericdallo15:12:14

I saw clj-kondo doing that, but user UX would not be as good right?

borkdude15:12:16

e.g.

"code": "(defn api-fn [x] (-api-fn (str x)))
and then also expose -api-fn which takes a string, converts it to a file and then call your API function for realz

ericdallo15:12:52

I'll leave that as a fallback if I can't make the transit handler work

borkdude15:12:53

the UX would be the same: you accept a file and the user doesn't notice that you convert it to a string and send that string to the pod

ericdallo16:12:30

but how the pod would receive a string and covert automatically to a file?

ericdallo16:12:36

if the api accepts only a file

borkdude16:12:49

it would not go automatically. you would also write the -api-fn on the pod side and do the conversion there

ericdallo16:12:12

So I think it sounds better

ericdallo16:12:30

Oh, I hope he don't mind if If ctrl-c/ctrl-v 😛

borkdude16:12:43

you can imagine that automatic file coercion is quite handy with tools-deps

ericdallo16:12:52

yeah, for sure

ericdallo16:12:06

for that case a transit handler makes more sense

ericdallo16:12:09

than the -api-fn

borkdude16:12:58

both are possible. some languages do not have transit (e.g. Rust does not)

borkdude16:12:07

so then the wrapping function technique is still a way out

ericdallo16:12:00

Let's make a Rust lib to write/read transit 😛

borkdude16:12:09

I've also written pods in Golang. There transit does work

borkdude16:12:26

Golang is a fantastic pod language btw, it's much easier than Rust ;)

ericdallo16:12:48

yeah, I saw on pod registry, sounds cool

ericdallo16:12:09

Hum, I think I can't call it clojure-lsp.api because the pod-test will try to require the clojure-lsp.api instead the dynamically created by babashka.pods 😅

borkdude16:12:52

Then make an alias to exclude clojure-lsp itself when running the tests

borkdude16:12:00

:replace-deps ...

ericdallo16:12:32

Does transit handle well edn maps as well? or do I need to do something special?

borkdude16:12:48

edn maps should go well

👍 1
ericdallo16:12:04

I just saw babashka.pods latest release https://github.com/babashka/pods/blob/v0.0.1/src/babashka/pods.clj add-transit-read-handler! function, only on master, is it possible to do a release of it later?

borkdude16:12:29

yes, of course, but you can test with master or not?

ericdallo16:12:49

yes I can, it's already working!

borkdude16:12:51

oh you need lein to deploy?

ericdallo16:12:13

is just that I'd like to use a release on clojure-lsp deps.edn instead of a git sha 😅

ericdallo16:12:17

but it works already

ericdallo16:12:41

clojure-lsp doesn't use lein anymore

borkdude16:12:42

yeah makes sense. can you give me a heads up if you're going to release? I'm gonna do a new clj-kondo just before

borkdude16:12:50

since we have a couple of fixes since the last release

ericdallo16:12:07

yes, I found another bug, will work on this this afternoon/night

borkdude16:12:06

btw datalevin is also available as pod

borkdude16:12:19

so you can query the clojure-lsp db with it from bb I guess ;)

Karol Wójcik18:12:32

Hmm would be cool to have a transit in Rust.

😄 1
Mno18:12:17

bb-lsp coming soon? 😮

borkdude18:12:14

I guess it depends on your expectation of what that is :)

Mno20:12:27

whatever eric is making clearly 😄

😂 1