babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
codeasone 2020-11-10T08:24:01.243700Z

Why would babashka barf on this: https://github.com/xsc/rewrite-clj/blob/master/src/rewrite_clj/node.clj#L1-L21? I'm seeing:

;; ----- Error --------------------------------------------------------------------
;; Type:     java.lang.IllegalArgumentException
;; Message:  No matching clause: coerce
;; Location: rewrite_clj/node.clj:1:1

;; ----- Context ------------------------------------------------------------------
;; 1: (ns
;;    ^--- No matching clause: coerce
;; 2:   ^{:added "0.4.0"}
;; 3:   rewrite-clj.node
;; 4:   (:require [rewrite-clj.node
;; 5:              coerce
;; 6:              comment
with babashka v0.2.2

codeasone 2020-11-11T11:38:23.268400Z

In case it's useful for others: https://gist.github.com/codeasone/06f23dc9f1849c85d0b82329a64d3481

borkdude 2020-11-11T12:51:02.269Z

Certainly useful. Maybe you could PR this as an example to the pod-babashka-parcera repo

borkdude 2020-11-11T12:51:31.269200Z

Replacing the previous example is ok with me

codeasone 2020-11-11T13:33:31.269800Z

:thumbsup:

borkdude 2020-11-11T13:33:38.270Z

I tweeted it ;)

borkdude 2020-11-10T08:31:17.243900Z

Because sci doesn't supported nested libspecs. I'm currently working on that.

codeasone 2020-11-10T08:33:18.244100Z

I see, thanks @borkdude

borkdude 2020-11-10T10:17:12.245200Z

I now have a nested-namespaces branch, binaries are coming into #babashka_circleci_builds. It would surprise me if bb could run rewrite-clj though, I don't think it can.

borkdude 2020-11-10T10:22:59.245400Z

At least not right now.

borkdude 2020-11-10T10:24:12.245600Z

I made an issue for the first obstacle at least here: https://github.com/borkdude/babashka/issues/635

codeasone 2020-11-10T11:12:18.246Z

:thumbsup: thank you for pursuing this

borkdude 2020-11-10T11:13:34.246200Z

Btw, if you want to do code analysis right now: this is one option: https://github.com/babashka/pod-babashka-parcera Maybe you can explain your use case / requirement and there might already be options.

codeasone 2020-11-10T11:30:37.246600Z

Of course, I'm want to setup a git hook to ensure namespace require forms remain ordered, so wanted to leverage nsorg off a pre-commit hook

#!/usr/bin/env bb
(require '[babashka.classpath :refer [add-classpath]]
         '[clojure.java.shell :refer [sh]]
         '[clojure.string :as str])

(def nsorg-dep '{:deps {nsorg/nsorg {:mvn/version "0.2.0"}}})

(def cp (-> (sh "clojure" "-Spath" "-Sdeps" (str nsorg-dep)) :out str/trim))

(add-classpath cp)

(require '[nsorg.core :as nsorg])

(defn format-file
  [filename]
  (let [code (slurp filename)
        processed (nsorg/rewrite-ns-form code)]
    (spit filename processed)
    ))

(when-let [[& files] *command-line-args*]
  (doseq [file files]
    (prn "Processing: " file)
    (format-file file)))
Was how I was hooking in nsorg and it depends on rewrite-clj

codeasone 2020-11-10T11:34:15.246900Z

The startup cost (1-2 seconds) of running clojure -M:nsorg --replace src test is mildly annoying for small commits involving changes to only one or two files say

borkdude 2020-11-10T11:34:18.247100Z

Right. Btw, clj-kondo has a linter for unsorted namespaces. So what you could do is use that linter output to then invoke nsorg on the JVM if there are unsorted namespaces.

borkdude 2020-11-10T11:34:47.247300Z

See: https://github.com/borkdude/clj-kondo/#babashka-pod

borkdude 2020-11-10T11:38:49.247500Z

I also have an example how to sort requires with pod-babashka-parcera: https://github.com/babashka/pod-babashka-parcera#sort-requires

codeasone 2020-11-10T11:43:27.247900Z

Cool, I'll check it out

Jakub Holý 2020-11-10T15:07:02.249300Z

Hello! I see bb supports some JDBC drivers. How difficult is it / what does it take to add another one? In particular, I would like to talk to Oracle. (Yes, I know. Sorry, I am forced to do that 😉.)

borkdude 2020-11-10T15:13:13.250200Z

@holyjak Driver support depends on how well it compiles with GraalVM. Since both Oracle DB and GraalVM are from Oracle, one would expect it to work maybe? ;)

borkdude 2020-11-10T15:14:17.251Z

@holyjak There are a bunch of feature flags here: https://github.com/borkdude/babashka/blob/master/doc/build.md#feature-flags One for postgres for example. You would need to make a PR for the Oracle driver that implements such a feature flag.

borkdude 2020-11-10T15:15:25.252500Z

I vaguely remember that @mbjarland also had interest in doing something with Oracle, but I could be mixing stuff up

Jakub Holý 2020-11-10T15:15:45.253Z

1. How do I test that the oracle driver compiles? 2. I would be happy to send a PR if I get it working. But I suspect oracle jdbc cannot be redistributed so the user would need to supply it herself?

borkdude 2020-11-10T15:17:10.254Z

1. Look for existing examples. Quarkus is a Java framework for GraalVM which has lots of plugins, I see they also have Oracle support (https://blogs.oracle.com/developers/configuring-the-oracle-jdbc-drivers-with-quarkus) 2) Yes

Jakub Holý 2020-11-10T15:18:50.254500Z

thanks a lot! Will have a look.

mbjarland 2020-11-11T10:04:11.265800Z

so back when I looked into this I was trying to make a standalone script to be run with a custom compiled babashka which included next.jdbc and which dynamically loaded the oracle jar

mbjarland 2020-11-11T10:04:21.266Z

how far I got:

#!/usr/bin/env bb

; when in a babashka execution context, add extra jars to the classpath.
(ns scripts.babashka-classpath
  (:import [<http://java.io|java.io> File]))
(when-let [bb-ns (find-ns 'babashka.classpath)]
  (let [shared (str (.getParentFile (File. ^String *file*)) "/shared")
        acp-fn (ns-resolve bb-ns (symbol "add-classpath"))
        add-cp (fn [&amp; r]
                 (let [path (clojure.string/join "/" r)]
                   (println "adding" path)
                   (acp-fn path)))]
    (add-cp shared "ojdbc6_g.jar")))

(ns scripts.jdbc-test
  (:require [next.jdbc :as jdbc])
  (:import [java.sql.Connection]))

(println "loading class")
(println "class:" (Class/forName "oracle.jdbc.driver.OracleDriver"))
(println "class loaded")

(def url "jdbc:oracle:thin:@172.20.0.80:1521:orcl")

(let [ds (jdbc/get-datasource {:jdbcUrl url :user "password" :password "password"})]
  (with-open [^java.sql.Connection c (jdbc/get-connection ds)]

mbjarland 2020-11-11T10:04:59.266400Z

and:

─➤ ./bb jdbc-test.clj
adding &lt;elided for brevity&gt;/babashka/matias/shared/ojdbc6_g.jar
loading class
class: oracle.jdbc.driver.OracleDriver
class loaded
clojure.lang.ExceptionInfo: IO Error: Message file 'oracle.net.mesg.Message' is missing. [at /home/mbjarland/projects/clojure/babashka/matias/jdbc-test.clj, line 27, column 38]

mbjarland 2020-11-11T10:05:14.266600Z

so not that far, let me know if you end up solving this

borkdude 2020-11-11T10:06:59.266800Z

Ah I see, you tried to run the Oracle driver from babashka source. Unfortunately that won't work. You will have to add it via a feature flag, like the postgres driver. You cannot load classes at runtime in babashka / graal

borkdude 2020-11-10T15:20:54.254600Z

I also found an issue about it here: https://github.com/quarkusio/quarkus/issues/1658

Jakub Holý 2020-11-10T16:02:47.255100Z

Awesome, thanks a lot! BTW do you recommend going the feature flag way or making a pod? I'm not up to speed..

borkdude 2020-11-10T16:03:46.255300Z

Making a feature flag might be easier to find out if it's going to work. If it works, with this knowledge you could proceed to make a pod.

👍 1
borkdude 2020-11-10T16:07:27.255500Z

Making a pod is an extra level of complexity, so for proof of concept feature flag is better

nate 2020-11-10T16:44:55.256200Z

might be in the TL;DR realm at this point

nate 2020-11-10T16:45:57.256400Z

a suggestion: make the repo README mostly about how to develop and contribute to babashka, and move all the (very rich) documentation somewhere else

nate 2020-11-10T16:46:39.256600Z

perhaps articles so they show up in https://cljdoc.org/d/borkdude/babashka/0.2.3/ and that can be the doc site?

borkdude 2020-11-10T16:46:49.256900Z

do you mean split up by topic and move to their own page?

borkdude 2020-11-10T16:47:18.257100Z

I'm partial to using cljdoc for primary docs since they don't have a good way to change docs after release

nate 2020-11-10T16:47:42.257300Z

yeah, if you split them up into separate pages by topic

nate 2020-11-10T16:47:55.257500Z

then the left column on cljdoc is like a table of contents for all doc

borkdude 2020-11-10T16:48:28.257700Z

ironically I already split the REPL docs up into its own page. Maybe that was the reason he couldn;'t find it ;)

nate 2020-11-10T16:48:39.257900Z

I like cljdoc too, because then the docs are versioned with the releases

holmdunc 2020-11-10T19:01:37.264600Z

I've seen long READMEs on github that simply put a table-of-contents at the top that links to the markdown headers, and it helps a lot

👍 3
mbjarland 2020-11-10T19:02:54.264800Z

And you are right @borkdude i did start looking into this, I'll dig tomorrow and see where I left it. Seem to remember there being some trickery involved with classloading and next-jdbc...or something, I'll see if I can dig it up