Fork me on GitHub
#babashka
<
2021-03-01
>
viesti08:03:55

humdum, realising that asking this before doing any amount of study 😄, but does integrant work with babashka? 🙂

robertfw08:03:59

There is a list of projects that are known to work and integrant is not on it https://github.com/babashka/babashka/blob/master/doc/projects.md

borkdude08:03:41

you can try though. if it works, we can add it there

👍 3
viesti09:03:06

First obstacle:

user=> (require '[integrant.core :as ig])
java.lang.Exception: Could not find namespace: clojure.spec.alpha. [at integrant/core.cljc:3:3]

viesti09:03:47

ah, sorry too fast

viesti09:03:51

0% cat deps.edn
{:deps {integrant/integrant {:mvn/version "0.8.0"}}
 :paths ["resources"]}
kimmoko@paju ~/work/bb-integrant
0% export BABASHKA_CLASSPATH=$(clojure -Spath)
kimmoko@paju ~/work/bb-integrant
0% echo $BABASHKA_CLASSPATH
resources:/Users/kimmoko/.m2/repository/integrant/integrant/0.8.0/integrant-0.8.0.jar:/Users/kimmoko/.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1.jar:/Users/kimmoko/.m2/repository/weavejester/dependency/0.2.1/dependency-0.2.1.jar:/Users/kimmoko/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar:/Users/kimmoko/.m2/repository/org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar
kimmoko@paju ~/work/bb-integrant
0% bb
Babashka v0.2.10 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (require '[integrant.core :as ig])
clojure.lang.ExceptionInfo: Could not resolve symbol: clojure.lang.Compiler/demunge [at clojure/spec/alpha.clj:128:16]
the previous paste already had some hacks

borkdude09:03:06

@U06QSF3BK You can maybe use spartan.spec as a standin

borkdude09:03:00

Instead of clojure.lang.Compiler/demunge they should probably use demunge from:

(require '[clojure.main :refer [demunge]])
which works with bb

viesti09:03:07

yeah, I can try that, to see if it covers the specs in integrant

borkdude09:03:29

why does integrant need spec btw? can't this be made optional?

borkdude09:03:43

I want to include spec proper in babashka btw, but since it's alpha, not yet

borkdude09:03:16

It looks like stuartsierra/component works with babashka

viesti10:03:12

got integrant working with spartan.spec 🙂

viesti10:03:36

0% cat deps.edn
{:deps {integrant/integrant {:mvn/version "0.8.0"}
        borkdude/spartan.spec {:git/url ""
                               :sha "e5c9f40ebcc64b27b3e3e83ad2a285ccc0997097"}}
 :paths ["resources"]
 :aliases {:remove-clojure {:classpath-overrides {org.clojure/clojure nil
                                                  org.clojure/spec.alpha nil
                                                  org.clojure/core.specs.alpha nil}}}}
kimmoko@paju ~/work/bb-integrant
0% cat 
(require 'spartan.spec)
(require '[integrant.core :as ig]
         '[org.httpkit.server :as server]
         '[ :as io])

(defn app [_req]
  {:status 200
   :body "Hello from Babashka!"})

(defmethod ig/init-key :system/handler [_ _]
  app)

(defmethod ig/init-key :system/http-server [_ {:keys [port ip]}]
  {:stop-fn (server/run-server app
                               {:port port
                                :ip ip})})

(defmethod ig/halt-key! :system/http-server [_ {:keys [stop-fn]}]
  (stop-fn))

(let [config (ig/read-string (slurp (io/resource "config.edn")))
      system (ig/init config)]
  (println "System started, press enter to exit")
  (.read System/in)
  (ig/halt! system)
  (println "System stopped"))
kimmoko@paju ~/work/bb-integrant
0% cat resources/config.edn
{:system/http-server {:port 1234
                      :ip "127.0.0.1"
                      :handler #ig/ref :system/handler}
 :system/handler {}}

borkdude10:03:41

worth documenting this example in the same fashion as #742

borkdude10:03:51

I will add it to the CI tests and projects.md page

viesti11:03:52

right, I can open an issue and put the example there for now

borkdude11:03:58

yes, please

viesti11:03:32

wrote https://github.com/babashka/babashka/issues/743, and while writing, realised that I used that remove-clojure alias

borkdude11:03:21

I think it should also work without it

borkdude11:03:35

but it doesn't hurt

viesti11:03:29

yeah, nvm, not actually needed with spartan spec

viesti08:03:00

another blatant without-study question, does babashka compile on arm architecture?

borkdude11:03:21

@adam.james btw, the remove-clojure alias is also a solution to your uberscript problem with spartan.spec:

:aliases {:remove-clojure {:classpath-overrides {org.clojure/clojure nil
                                                  org.clojure/spec.alpha nil
                                                  org.clojure/core.specs.alpha nil}}

borkdude11:03:59

but I've adapted the README to how to best load spartan.spec to make it compatible with uberscript

adam-james13:03:11

Oh, thanks for the tip! I'll have to try this soon :)

avi14:03:21

👋 I’m trying to create a Web app with Babashka and I’m running into a problem inserting into a PostgreSQL array column with the PostgreSQL pod. I’m having trouble debugging this problem and I don’t have a lot of time so I’m considering dropping the pod, adding a JVM to my server environment, and switching to using babashka.deps to download and utilize the full-blown jdbc.next and standard PostgreSQL JDBC driver. (I was already considering doing so, in order to use Compojure and Ring.) Before I take the time to do that, I thought I’d ask if anyone has any suggestions? Links: https://gist.github.com/aviflax/f804c40e1ae823e7ce9e2c3766f75f53, https://github.com/aviflax/availability.help/blob/95caba1e7f3e1b9282e0cdb0ed8f2ae1daf89939/web/server.bb#L242 Thanks!

borkdude15:03:30

@aviflax Hey hey! The current workaround for this (and json and jsonb) is to convert it to ::text and then convert it to something else in Clojure.

borkdude15:03:46

@aviflax There is an issue here: https://github.com/babashka/babashka-sql-pods/issues/7 What would be the sane thing to do here? Convert to a vector automatically? Same for json/jsonb -> Clojure?

borkdude15:03:58

The issue is that we can't serialize PGObjects over the wire (I think)

avi15:03:59

Thanks! Taking a look 👀

borkdude15:03:33

Maybe we can provide this automatic behavior as opt-in behavior via options

avi15:03:03

I get the select as ::text part, but that doesn’t (seem to) address how to insert. That said, now that I’m thinking about this with a fresher mind (rather than at midnight last night) I think I’m being perfectionist here, in my very specific use case right now. I can just change this column to text, store a comma-delimited string value, and get on with it. It’ll suffice. I think I’ll proceed with that, unless there is some quick workaround for inserting into a Postgres array column.

avi15:03:07

BTW am I missing something, or do I indeed need a JVM and need to use babashka.deps if I want to use Ring and Compojure in a bb script?

borkdude15:03:05

ah, inserting a vector you mean? yeah we could also automatically convert that into a pg array on the pod side, feel free to comment in the same issue

borkdude15:03:12

about ring and compojure: if there is ring middleware that happens to work from source, you can add this as a dep. compojure doesn't work from source right now I believe (since it has a dependency on instaparse?)

borkdude15:03:33

You can build a small router from core.match, that might help: https://gist.github.com/borkdude/1627f39d072ea05557a324faf5054cf3

👍 3
avi15:03:46

All makes sense, thanks very much!!!

borkdude15:03:14

@aviflax I think the insert problem will solve itself if we switch the pod format to transit which can cope with serializing arrays

avi15:03:46

Makes sense, sounds promising. I’d love to help test if/when the time comes!

borkdude15:03:08

That's only a once line change in the code :)

borkdude15:03:24

well no a few more, instead of EDN we need to use transit, but should be relatively small change

borkdude15:03:46

I have a pod using transit already here: https://github.com/babashka/pod-babashka-buddy

😎 3
Jakub Holý (HolyJak)17:03:33

What do you think, will it be possible to run #reveal (using JavaFX) via bb? Though at that point I can perhaps just start clj because it will not be that fast anyway...

djblue18:03:19

You could try https://github.com/djblue/portal if you wanted to inspect data from bb

❤️ 3
borkdude19:03:03

Yeah, building a small web-app on top of httpkit is probably a better approach for bb than javafx :)

borkdude19:03:17

I might make a small pgadmin-like tool, now that I think of it

💯 3
😻 3
borkdude17:03:12

I don't think we are going to add JavaFX to bb, since this is probably out of scope for scripting. Probably better to GraalVM-compile your own JVM project

borkdude19:03:35

^ @adam.james is streaming again

🙏 3
borkdude20:03:35

Does anyone here know how to produce HTML from markdown with the bootleg pod from babashka?