Fork me on GitHub
#babashka
<
2021-10-15
>
viesti05:10:55

wondering if writing nrepl-port file under say .bb/ or . nbb/ for nbb, would be a thing, to avoid clobbering jvm/clojure nrepl server written port file, kinda like .shadow-cljs/nrepl-port etc.

borkdude12:10:46

This could work if Calva and CIDER would support this. @U0ETXRFEW @U051BLM8F

pez12:10:19

Currently Calva by default will look for the files in the project root, as [".bb-nrepl.port"] and [".nbb-nrepl.port"] . I am totally ready to change the defaults to harmonize/standardize. The user also can create a Custom REPL connect sequence and specify the port file there. https://calva.io/connect-sequences/ in case they don’t fancy whatever defaults we go with.

borkdude12:10:43

I didn't even know this

borkdude12:10:47

is this some kind of standard?

pez12:10:23

What would be a standard?

borkdude12:10:59

dunno, but what use is it to attempt read this file if the tool doesn't know it should produce this file :)

😄 2
borkdude12:10:40

but it's good that Calva has something for this. now it's just a matter of coming up with the right dir + name

borkdude12:10:50

and then we could change the Calva default

borkdude12:10:17

I'm inclined to something like .babashka/.nrepl-port

borkdude12:10:24

and .nbb/.nrepl-port

borkdude12:10:05

<dot-toolname/.nrepl-port> basically

borkdude12:10:33

the default file name for lein repl is:

user=> (slurp ".nrepl-port")
"59553"

pez12:10:45

Yeah, so before you didn’t like the idea of bb creating this file. So then the user (or Calva) would need to do it. You gave me a nice snippet of code:

(import [ ServerSocket]
        [java.lang ProcessBuilder$Redirect])
(require '[babashka.wait :as wait])
(let [nrepl-port (with-open [sock (ServerSocket. 0)] (.getLocalPort sock))
      pb (doto (ProcessBuilder. ["bb" "--nrepl-server" (str nrepl-port)])
           (.redirectOutput ProcessBuilder$Redirect/INHERIT))
      proc (.start pb)]
  (wait/wait-for-port "localhost" nrepl-port)
  (spit ".nrepl-port" nrepl-port)
  (println "Press enter to kill the nREPL server.")
  (read-line)
  (.destroy proc))
I adapted that some (can’t find it now, but anyway) and planned for Calva to help with both creating the file and looking for it at connect time. Then I decided to make Calva Jack-in watch stdout instead for when bb writes the port it uses there… Yeah, not sure I am making sense, but there it is. 😃

borkdude12:10:10

Well, I do like the convenience, but I don't like bb overwriting the clj REPL's file

borkdude12:10:34

so stuffing that in another dir would be a OK solution I guess

borkdude12:10:08

I'll make an issue for this

pez12:10:43

I hope to be able to support babashka’s and nbb’s REPLs while connected to clj or lein REPLs some day, so I totally agree about not overwriting the file.

borkdude12:10:27

One major issue: should the directory be .bb or .babashka :-s

borkdude12:10:57

In the beginning of bb I was overthinking this, considering the situation that there can also be multiple nREPL servers for the same tool

borkdude12:10:03

but perhaps this is not so important

borkdude12:10:59

I'll go with .bb since there is also bb.edn

borkdude12:10:45

Or what about bb , then we can also put scripts in there and it could be on the classpath by default

pez12:10:58

Both lein and clojure get by with using just one file for this, but babashka and nbb are different animals of course.

pez12:10:40

bb sounds good to me. Especially if it’s on the default classpath! Sounds lovely.

borkdude12:10:25

cool. perhaps bb.edn could also live inside of that directory then

borkdude12:10:41

not sure about that one

pez12:10:46

Totally recognize the threshing. 😃.

borkdude12:10:19

bb.edn bb/script.clj bb/.nrepl-port yeah I can live with this

pez12:10:41

We all can! ❤️

viesti18:10:01

looking back after 13 hours at replies to a spontaneous idea, nice :D

😂 1
pez18:10:14

Being highly receptive to spontaneous ideas, his own and other's, is part of what explains the @U04V15CAJ phenomenon, I think.

❤️ 1
viesti18:10:15

well said 🙂

viesti11:10:24

Wondering babashka scripts would use .bb suffix and be stored in src , but maybe a bad idea 🙂 (just realised that I've been using .bb suffix for maybe no reason :D)

borkdude12:10:23

That’s also a option. This is already supported btw on the classpath, .bb has priority.

viesti12:10:18

ahh nice, didn't know :)

deas07:10:24

Trying out a "pure" bb project (just bb.edn, no deps.ednso far) with calva. Calva testing support does not work at all for me. What would be the trick to get a smoother test experience? Introducing deps.edn ?

borkdude07:10:13

Not sure about #calva, perhaps @U0ETXRFEW has an idea here?

pez07:10:42

Do you mean Calva’s test runner commands, @U06FLL69W? They rely on cider-nrepl, so unless babashka has a shim for that, it won’t work. What you can do is create some custom commands/snippets that run the tests for you. See https://calva.io/custom-commands/ for how those works. And please reach out if you need help with it. When connected to babashka the repl session clj is used.

👍 1
borkdude07:10:40

I usually call (clojure.test/run-tests 'namespace) or just the test as a function

👍 1
pez07:10:02

Yes, so on that page there is an example snippet conf for the latter:

{
            "name": "CLJ Test Top Level Defined Symbol",
            "repl": "clj",
            "snippet": "(clojure.test/test-var #'$top-level-defined-symbol)"
        },

👍 1
pez07:10:25

And something like this would run namespace tests and bind it to the keyboard shortcut ctrl+alt+space n

{
            "name": "Run namespace testsl",
            "repl": "clj",
            "snippet": "(clojure.test/run-tests '$ns)",
            "key": "n",
        },

pez07:10:23

This feature request is somewhat related too, I think: https://github.com/BetterThanTomorrow/calva/issues/1305

deas08:10:49

Guys, you are amazing!

❤️ 1
deas07:10:00

One more: I want to ship an oci image with an uberscript. Building this thing requires a jvm and bb. Is there a publically avaiable bb builder image or efforts on the way to provide one?

borkdude07:10:09

Not aware of one

lispyclouds07:10:01

@U06FLL69W Could you elaborate a bit more on builder image? you want to build an uberscript and have another image as a multistage? So the final image needs jvm and bb in it?

borkdude07:10:49

I think he means that the builder image needs a jvm (to resolve dependencies) but the final one doesn't

👍 1
lispyclouds07:10:56

got it. yeah we dont have one that has both now. probably a clojure/jdk image + installing bb could be the easiest

deas08:10:05

This is what I am doing. However, most java/clojure images had issues and it took a while to find one that works for this usecase. If we want this, I'd volunteer to build such a thing. However, I think is should live under the babashka umbrella at github.

borkdude08:10:05

@U06FLL69W Yes, I can give you a repo to work on if you want

borkdude08:10:19

Just let me know the name of the repo and your github id

lispyclouds08:10:58

@U04V15CAJ can we do it as adding a PR to the circleci setup that we have?

borkdude08:10:58

What does this have to do with a CircleCI setup?

lispyclouds08:10:51

as far as i understand we just need to build a docker image with the jvm and install bb in it right? can be done as another pipeline step?

lispyclouds08:10:09

build and push it

borkdude08:10:02

yes that would work

borkdude08:10:35

ok, @U06FLL69W perhaps you can share your Docker image and we can make something similar to that and push it to Dockerhub

borkdude08:10:45

and provide some docs around it

deas08:10:15

I can also start this thing under my deasgh account. However, it would be helpful to understand its final home context. Such as ci.

borkdude08:10:55

ok, start under deas and then we will take the next step from there

👍 1
mkvlr07:10:13

@U06FLL69W I think the Clojure docker images could be a good place for this, too. Issue: https://github.com/Quantisan/docker-clojure/issues/129

👍 1
deas07:10:07

There are a lot of clojure/java images. Most I tried had "issues" out of the box. I was aiming at minimalism. Currently ended up with:

# Most other images are missing git, curl or whatnot
FROM openjdk:11 as build
COPY . /build
WORKDIR /build
RUN curl -s  -o install && \
    chmod 755 install && \
    ./install && \
    ./test-runner.clj && \
    bb uberscript foo.clj -f src/foo.clj

FROM babashka/babashka:latest
# COPY --from=build ...

mkvlr08:10:51

the one above is the one & only clojure image

Michael W23:10:20

I got holy-lambda babashka runtime working with the aws pod to do some nifty stuff today. I really like babashka.

👍 3
Karol Wójcik06:10:06

Babashka runtime soon will land a support for arm64. Which means even lower cold start and better performance.

Karol Wójcik11:10:14

What challenges have you come across when using holy-lambda? @UAB2NMK25

Michael W13:10:31

I think the hardest thing was figuring out how to look at the event and ctx objects to see how I could use it. You might want to document the keys/values for both event and ctx to make it easier for someone to get started. I used an api gateway and (hr/json) to "export" the objects to inspect them.

Michael W13:10:55

Once I knew what was available in those, it was smooth sailing, and it's really a great framework for getting something going fast. I replaced a python lambda that was taking 500ms per run with bb that is under 100ms per run doing the same thing.

Karol Wójcik14:10:02

Oh! Thanks for sharing. It would be probably easier to inspect the event shape using sam invoke. If you were following the tutorial this is a way to know the shape of the object. You can also check generate-event command :D Anyway, it's hard to document every single event option since HL does not transform the event much. Thanks for your thoughts.

Michael W14:10:59

I used sam local at the beginning, but because I was using aws apis and needed a valid keyid/secret I had to do my looking from the live lambda up in aws.

Michael W14:10:24

Even just a few pointers in the docs about how to get vars from the url would have saved me a bunch of time. I got past it doing (hr/json {:event event}) and using my browser to explore the json output with formatters.

Michael W15:10:44

I like holy-lambda quite a bit, it's brilliant!

cap10morgan20:10:45

@UAB2NMK25 I'm trying to do something similar. do you have a link to your code?

Karol Wójcik05:10:07

@U06FS3DLH have you tried following HL tutorial?