Fork me on GitHub
#babashka
<
2022-08-23
>
borkdude06:08:04

@corasaurus-hex Yes, working on it. There is a prototype here in user space that you can use today: https://github.com/rads/bbin

borkdude12:08:02

Maybe use vega lite or shell out to some tool

Cora (she/her)12:08:45

i think this reply is in the wrong thread

borkdude12:08:23

Can you fix this for me? I'm in the mountains

⛰️ 1
Cora (she/her)12:08:26

enjoy those views, dang

sheluchin13:08:48

Sweet views indeed. Enjoy! Thank you @borkdude and @corasaurus-hex.

1
sheluchin12:08:17

I'd like to use Babashka in a GitHub Action to create some data visualisations and publish them to GH Pages. Any pointers on getting this done? Is there some library that works with Babashka to handle server-side chart generation?

Cora (she/her)12:08:58

it was posted in the wrong thread but that's the gist of it.

Cora (she/her)19:08:16

nbb is super powerful and worth a shot

Yehonathan Sharvit12:08:55

What’s the fastest (in terms of load time)) nrepl client out there? I run babashka with an nrepl server. It loads super fast. Now, I want to connect to it from the command line. lein repl :connect is a bit slow for me.

Yehonathan Sharvit13:08:34

I need a REPL client with a shell loop. grench is only for one shot evaluation. I tried parle from https://nrepl.org/nrepl/usage/clients.html#command-line-clients but it didn’t work. The others are written in clojure, and suffer from a long load time

Cora (she/her)13:08:48

trenchman might fit your requirements, give it a shot

Yehonathan Sharvit13:08:53

@borkdude what would it take to compile repl-y to a native image?

borkdude13:08:21

I will reply in two hours

Yehonathan Sharvit13:08:58

OK. Timer set:smile:

borkdude15:08:11

I have a native build of repl-y in a private repo. I didn't publish it because I hacked it together quickly

borkdude15:08:50

if you want, I can add you to the repo

borkdude15:08:34

but you could also just use rebel readline perhaps? It uses a JVM but if you have a longer running process, maybe that's not too bad?

borkdude15:08:38

There is also a small library here for doing one-off stuff again an nREPL server: https://github.com/babashka/nrepl-client

Yehonathan Sharvit15:08:44

The best for me is the native build of repl-y. Can you add me to the repo?

borkdude15:08:46

what's your github handle again?

borkdude15:08:53

got it: viebel

Nicolas Estrada13:08:09

Hi 🙂 I just created an issue, if you need any more details please let me know 😉 Thanks! https://github.com/babashka/babashka/issues/1343

borkdude15:08:08

@U0230KNPHDM Can you try with the master version?

Nicolas Estrada17:08:14

Sûre no problème 👌

Nicolas Estrada18:08:08

Works! Thanks 🙂

Nicolas Estrada18:08:25

Well it compiles at least, I should probably execute some sql

borkdude18:08:53

yeah, better test. There's also pod-babashka-postgresql, you're probably aware of this right?

Nicolas Estrada18:08:12

Yeah but the pod is missing some critial apis like jdbc/plan for streaming result sets

Nicolas Estrada18:08:26

I knew how to build a pod I would make an MR

borkdude18:08:00

alright, I'm fine with maintaining the feature flag of course

Nicolas Estrada18:08:45

Ok works thanks 🙂

Nicolas Estrada18:08:26

(for some reason though I can't use (with-open [conn (jdbc/get-connection ds ...)

Nicolas Estrada18:08:53

But this was a limitation before, just different behaviors between bb and clj

borkdude18:08:06

@U0230KNPHDM What's the issue with that?

Nicolas Estrada18:08:47

: Method close on class org.postgresql.jdbc.PgConnection not allowed! user 
clojure.lang.ExceptionInfo: Method close on class org.postgresql.jdbc.PgConnection not allowed! {:type :sci/error, :line nil, :column nil, :file nil}
	at sci.impl.utils$throw_error_with_location.invokeStatic(utils.cljc:37)
	at sci.impl.utils$throw_error_with_location.invoke(utils.cljc:34)
	at sci.impl.utils$throw_error_with_location.invokeStatic(utils.cljc:35)
	at sci.impl.evaluator$eval_instance_method_invocation.invokeStatic(evaluator.cljc:189)
	at sci.impl.analyzer$analyze_dot$reify__4993.eval(analyzer.cljc:856)
	at sci.impl.evaluator$eval_try.invokeStatic(evaluator.cljc:144)
	at sci.impl.analyzer$analyze_try$reify__4960.eval(analyzer.cljc:774)
	at sci.impl.evaluator$eval_let.invokeStatic(evaluator.cljc:71)
	at sci.impl.analyzer$analyze_let_STAR_$reify__4875.eval(analyzer.cljc:507)
	at sci.impl.analyzer$return_do$reify__4237.eval(analyzer.cljc:139)
	at sci.impl.fns$fun$arity_0__3517.invoke(fns.cljc:105)
	at sci.lang.Var.invoke(lang.cljc:174)
	at sci.impl.analyzer$return_call$reify__5204.eval(analyzer.cljc:1205)
	at sci.impl.analyzer$return_call$reify__5208.eval(analyzer.cljc:1205)
	at sci.impl.analyzer$return_call$reify__5212.eval(analyzer.cljc:1205)
	at sci.impl.analyzer$return_call$reify__5216.eval(analyzer.cljc:1205)
	at sci.impl.analyzer$return_call$reify__5208.eval(analyzer.cljc:1205)
	at sci.impl.analyzer$return_call$reify__5212.eval(analyzer.cljc:1205)
	at sci.impl.interpreter$eval_form.invokeStatic(interpreter.cljc:39)
	at sci.core$eval_form.invokeStatic(core.cljc:307)
	at babashka.nrepl.impl.server$eval_msg$fn__28061$fn__28062.invoke(server.clj:110)
	at babashka.nrepl.impl.server$eval_msg$fn__28061.invoke(server.clj:106)
	at babashka.nrepl.impl.server$eval_msg.invokeStatic(server.clj:96)
	at babashka.nrepl.impl.server$fn__28165.invokeStatic(server.clj:365)
	at babashka.nrepl.impl.server$fn__28165.invoke(server.clj:365)
	at clojure.lang.MultiFn.invoke(MultiFn.java:239)
	at babashka.nrepl.server.middleware$default_process_msg.invokeStatic(middleware.clj:13)
	at babashka.nrepl.server.middleware$wrap_process_message$fn__28215.invoke(middleware.clj:31)
	at clojure.core$completing$fn__8528.invoke(core.clj:6931)
	at clojure.core$map$fn__5931$fn__5932.invoke(core.clj:2759)
	at babashka.nrepl.impl.server$session_loop.invokeStatic(server.clj:418)
	at babashka.nrepl.impl.server$listen$fn__28201.invoke(server.clj:438)
	at sci.impl.vars$binding_conveyor_fn$fn__424.invoke(vars.cljc:133)
	at clojure.core$binding_conveyor_fn$fn__5823.invoke(core.clj:2047)
	at clojure.lang.AFn.call(AFn.java:18)
	at java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.lang.Thread.run(Thread.java:829)
	at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:705)
	at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202) 

Nicolas Estrada18:08:08

This is the code

(defn fetch-intra-campuses
  []
  (reset-cfg! {:host (env "INTRA_HOST") :port 5432 :dbname (env "INTRA_DB")})
  (with-open [conn (jdbc/get-connection (mk-datasource)
                                        {:user        (env "INTRA_USER")
                                         :password    (env "INTRA_PASSWORD")
                                         :auto-commit false
                                         :read-only   true})]
    (->> ["SELECT id, name, active, slug FROM campus order by id"]
         (jdbc/execute! conn)
         (map (fn [{:keys [campus/id campus/name campus/slug campus/active]}]
                {:id id :name (s/trim name) :slug slug :active? active})))))

borkdude18:08:16

OK, this can be fixed as well.

borkdude18:08:38

It's a bit more work, please make an issue for that

Nicolas Estrada19:08:40

Sûre thanks anyways … most of my scripts use only one connection and don't close them anyway 😅 it's only in the REPL where I clean up resources

👍 1
Nicolas Estrada19:08:17

Still very usable and not a big issue

Yehonathan Sharvit14:08:02

How do we run unit tests in babahska?

Yehonathan Sharvit15:08:39

Do Calva test-related commands know how to handle it?

borkdude15:08:31

I assume (but don't know for sure) that Calva-related test commands just assume clojure.test. If that is true, then it should work

borkdude15:08:45

Better ask in #calva

Yehonathan Sharvit11:08:13

I cannot use https://github.com/cognitect-labs/test-runner. Here’s what I get

bb "(require 'cognitect.test-runner)"
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: java.net.URLClassLoader
Location: clojure/java/classpath.clj:21:3

----- Context ------------------------------------------------------------------
17:   ^{:author "Stuart Sierra"
18:      :doc "Utilities for dealing with the JVM's classpath"}
19:   clojure.java.classpath
20:   (:require [ :as io])
21:   (:import ( File)
      ^--- Unable to resolve classname: java.net.URLClassLoader
22:            (java.util.jar JarFile JarEntry)
23:            ( URL URLClassLoader)))
24: 
25: (defprotocol URLClasspath
26:   (urls [loader]

----- Stack trace --------------------------------------------------------------
clojure.java.classpath       - clojure/java/classpath.clj:21:3
clojure.tools.namespace.find - clojure/tools/namespace/find.clj:13:3
cognitect.test-runner        - /Users/viebel/.gitlibs/libs/io.github.cognitect-labs/test-runner/dfb30dd6605cb6c0efc275e1df1736f6e90d4d73/src/cognitect/test_runner.clj:2:3
user                         - <expr>:1:1

borkdude11:08:03

^ you need to include the babashka fork of tools.namespace

Yehonathan Sharvit11:08:43

I was confused because I copy pasted blindy the deps coordinates from here https://github.com/babashka/tools.namespace#releases-and-dependency-information

borkdude11:08:18

Ah, understandable

Yehonathan Sharvit13:08:37

When I run in Calva the “Run current test” command it says:

; Running test: dummy…
; The server does not recognize or cannot perform the 'undefined' operation

Yehonathan Sharvit13:08:38

I asked on #calva and they said that babashka cider-nrepl needs to provide test-var-query and retest. https://clojurians.slack.com/archives/CBE668G4R/p1661326366720939?thread_ts=1661268149.551749&amp;cid=CBE668G4R @borkdude Do you understand what they mean?

borkdude15:08:55

I'll get back to you soon. I'm traveling so I have only short intervals I can look into things

borkdude15:08:22

If you want to look into the code check out babashka.nrepl

lispyclouds15:08:35

From my very limited nREPL understanding I think those ops need to be implemented in https://github.com/babashka/babashka.nrepl/blob/master/src/babashka/nrepl/impl/server.clj#L350-L410 which i imagine could be some significant work? scanning namespaces for tests i assume?

borkdude15:08:49

You could also just execute tests in the REPL yourself, using just cljs.test code

borkdude15:08:55

eh wait, clojure.test even

borkdude21:08:14

@U0L91U7A8 I'm not familiar with these nREPL ops, they're not part of the nREPL spec but something custom which CIDER adds on top of it. I think to enable such custom things, we need to have a way to let users write middleware for the babashka nREPL implementation.

borkdude21:08:31

There is already a concept of middleware in the bb nREPL implementation: https://github.com/babashka/babashka.nrepl/blob/master/src/babashka/nrepl/server/middleware.clj but it's currently not exposed to bb scripts, only to people who use bb.nrepl as a library in their bb-like projects

borkdude21:08:16

Perhaps @U7RJTCH6J who implemented most of that has a good idea how this could be exposed to bb scripts that implement some middleware

phronmophobic21:08:01

👋 trying to catch up on the thread. > but it's currently not exposed to bb scripts, only to people who use bb.nrepl as a library in their bb-like projects If I remember correctly, that's a build-time config option to expose that namespace when building babashka?

borkdude21:08:29

This is all there is right now:

👍 1
borkdude21:08:01

This namespace is also exposed within babashka. If those functions had a way to add middleware, extra ops could be implemented in user space

👍 1
borkdude21:08:02

o wait, the opts argument: perhaps it is already possible...?

phronmophobic21:08:32

how is the nrepl started?

borkdude21:08:41

You can start it from the CLI: bb nrepl-server but you can also start it programmatically

borkdude21:08:04

I don't think the middleware ns is exposed though

phronmophobic22:08:20

If I'm following, you would have to: 1. expose the middleware namespace 2. implement the required ops 3. start the nrepl programmatically and provide the middleware I guess at that point, it would make sense to just implement those ops directly into babashka.nrepl?

borkdude22:08:34

Perhaps yes

borkdude22:08:37

I guess I'm not an advanced enough CIDER user to make the proper judgement here, I usually just call clojure.test myself from the REPL without relying on some tool doing that for me

Yehonathan Sharvit08:08:49

One of the benefits of running the tests vi Calva is that it highlights the failures in the buffer that contains the tests that fail.

erwinrooijakkers19:08:35

Hi, I want to convert an SVG to various size PNGs, is Babaskha in combination with ImageMagick’s convert a good choice?

lread20:08:20

Good news @borkdude, https://github.com/clj-commons/clj-http-lite full test suite is now run with bb. Found minor things you might (or might not) be interested in. 🧵

👏 1
lread20:08:29

Notes from the https://github.com/clj-commons/clj-http-lite/commit/6c128fdee7f773335c799ab4298cf072442610e4:

Some tests initially failed under bb:
- Tests were checking specifically for thrown
`java.net.ssl.SSLException` and `java.net.SocketTimeoutException`.
Neither of these classes are currently available in bb.
I switched to checking the message only.
- Encoding tests were testing against "windows-1252" charset.
Bb does include this charset, but on Windows only.
I switched the test to use "iso-8859-1" which is available on bb on
all platforms.

lread20:08:09

Not suggesting any action should be taken, just sharing what I learned.

borkdude20:08:03

Exception types are usually cheap to add, PR welcome

👍 1
borkdude20:08:26

The latter: good to know, thanks