babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
viesti 2021-03-01T08:08:55.179700Z

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

viesti 2021-03-01T08:11:00.180300Z

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

viesti 2021-03-01T08:12:03.180400Z

ah, that's tracked on https://github.com/babashka/babashka/issues/241

robertfw 2021-03-01T08:29:59.180700Z

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

borkdude 2021-03-01T08:30:41.181Z

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

👍 1
viesti 2021-03-01T09:18:06.181300Z

First obstacle:

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

viesti 2021-03-01T09:18:47.181500Z

ah, sorry too fast

viesti 2021-03-01T09:19:51.181700Z

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

viesti 2021-03-01T09:22:22.181900Z

ah, spec is tracked on https://github.com/babashka/babashka/issues/558

borkdude 2021-03-01T09:33:06.182300Z

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

borkdude 2021-03-01T09:34:00.182500Z

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

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

viesti 2021-03-01T09:35:07.182800Z

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

borkdude 2021-03-01T09:35:29.183Z

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

borkdude 2021-03-01T09:35:43.183200Z

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

borkdude 2021-03-01T09:43:46.183800Z

https://github.com/babashka/babashka/issues/742

borkdude 2021-03-01T09:45:40.184100Z

https://github.com/babashka/babashka/issues/742

viesti 2021-03-01T10:57:12.184400Z

got integrant working with spartan.spec 🙂

viesti 2021-03-01T10:57:36.184800Z

0% cat deps.edn
{:deps {integrant/integrant {:mvn/version "0.8.0"}
        borkdude/spartan.spec {:git/url "<https://github.com/borkdude/spartan.spec>"
                               :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 <http://bb_integrant.bb|bb_integrant.bb>
(require 'spartan.spec)
(require '[integrant.core :as ig]
         '[org.httpkit.server :as server]
         '[<http://clojure.java.io|clojure.java.io> :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 {}}

borkdude 2021-03-01T10:58:22.185Z

ah cool!

borkdude 2021-03-01T10:58:41.185200Z

worth documenting this example in the same fashion as #742

borkdude 2021-03-01T10:58:51.185400Z

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

viesti 2021-03-01T11:00:52.185600Z

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

borkdude 2021-03-01T11:00:58.185800Z

yes, please

viesti 2021-03-01T11:06:32.186Z

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

borkdude 2021-03-01T11:07:21.186400Z

I think it should also work without it

borkdude 2021-03-01T11:07:35.186600Z

but it doesn't hurt

viesti 2021-03-01T11:08:29.186800Z

yeah, nvm, not actually needed with spartan spec

borkdude 2021-03-01T11:51:21.187300Z

@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}}

borkdude 2021-03-01T11:51:59.187500Z

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

adam-james 2021-03-01T13:26:11.188Z

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

avi 2021-03-01T14:48:21.189700Z

👋 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!

borkdude 2021-03-01T15:02:30.190700Z

@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.

borkdude 2021-03-01T15:03:46.191300Z

@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?

borkdude 2021-03-01T15:04:58.192100Z

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

avi 2021-03-01T15:04:59.192300Z

Thanks! Taking a look 👀

borkdude 2021-03-01T15:05:33.192700Z

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

avi 2021-03-01T15:16:03.195100Z

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.

avi 2021-03-01T15:24:07.196100Z

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?

borkdude 2021-03-01T15:27:05.196600Z

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

borkdude 2021-03-01T15:28:12.197600Z

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?)

borkdude 2021-03-01T15:28:33.197900Z

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

👍 1
avi 2021-03-01T15:32:46.198100Z

All makes sense, thanks very much!!!

borkdude 2021-03-01T15:46:14.199200Z

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

avi 2021-03-01T15:46:46.200100Z

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

borkdude 2021-03-01T15:46:49.200200Z

For retrieving array we still need to do something, as described here: https://github.com/seancorfield/next-jdbc/blob/develop/doc/tips-and-tricks.md#working-with-arrays

borkdude 2021-03-01T15:50:08.200600Z

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

borkdude 2021-03-01T15:50:24.201Z

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

borkdude 2021-03-01T15:50:46.201200Z

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

😎 1
Jakub Holý 2021-03-01T17:40:33.202500Z

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...

borkdude 2021-03-01T17:43:12.203600Z

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

djblue 2021-03-01T18:12:19.203700Z

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

❤️ 1
Jakub Holý 2021-03-01T18:29:37.204Z

Ah, thanks!

borkdude 2021-03-01T19:08:03.204300Z

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

borkdude 2021-03-01T19:08:17.204500Z

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

💯 1
😻 1
borkdude 2021-03-01T19:47:35.205500Z

^ @adam.james is streaming again

🙏 1
borkdude 2021-03-01T20:14:35.206Z

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