babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
onetom 2021-02-25T02:28:21.076400Z

Is there a recommended way to provide auto-completion in inf-clojure, when using babashka? I see the default config currently doesn't define the completion feature: https://github.com/clojure-emacs/inf-clojure/blob/master/inf-clojure.el#L131-L141 but after seeing https://www.youtube.com/watch?v=TvBmtGS0KJE i have the suspicion that nowdays it's possible to do define it in some reasonable way, even if it involves pulling in the clj-kondo pod.

dharrigan 2021-02-25T09:07:25.078400Z

Having malli to be bb compatible would be very nice, imho. Even a subset of that, which allows for validation and value transformations. I could see that very useful for command line validation or API validation.

borkdude 2021-02-25T10:30:42.081Z

@ikitommi @steveb8n I have a feature-malli branch pushed to babashka repo.

$ ./bb -e "(require '[malli.core :as m]) (m/validate [:and int? [:> 6]] 7)"
true
$ ./bb -e "(require (quote [malli.core :as m])) (m/validate [:and [:fn '(fn [x] (int? x))] [:> 6]] 7)"
true

borkdude 2021-02-25T10:34:13.081200Z

@ikitommi It seems the borkdude.dynaload setting really helps, it shaves almost 40mb of the binary size

borkdude 2021-02-25T10:34:38.081400Z

You can try the binary from the #babashka-circleci-builds channel :)

borkdude 2021-02-25T10:35:12.081600Z

I guess if malli would end up in bb, then we would need some kind of cli-matic like library which is not based on spec, but on malli ;)

borkdude 2021-02-25T10:40:30.082200Z

Dear bb community. Consider leaving feedback in this issue about adding malli: https://github.com/babashka/babashka/issues/737

borkdude 2021-02-25T11:06:05.083Z

$ ./bb -e "(malli.error/humanize (malli.core/explain [:map [:x string?] [:y int?]] {}))"
{:x ["missing required key"], :y ["missing required key"]}

ikitommi 2021-02-25T11:37:33.083200Z

wooot. PR coming? ;)

borkdude 2021-02-25T11:43:09.083400Z

(ns foo
  (:require [clojure.tools.cli :as cli]
            [malli.core :as m]
            [malli.transform :as mt]))

(def cli-options
  [["-n" "--number NUM" "A number"
    :parse-fn (m/decoder int? mt/string-transformer)
    :validate [(m/validator [:< 100])]]])

(prn (cli/parse-opts ["-n" "99"] cli-options))
;; =>
;; {:options {:number 99}, :arguments [], :summary "  -n, --number NUM  A number", :errors nil}

(prn (cli/parse-opts ["-n" "100"] cli-options))
;; =>
;; {:options {}, :arguments [], :summary "  -n, --number NUM  A number", :errors ["Failed to validate \"-n 100\""]}

borkdude 2021-02-25T11:43:34.083600Z

This doesn't require a PR

borkdude 2021-02-25T11:44:32.083800Z

@ikitommi Is it possible to get the humanized error for [:< 100]? tools.cli expects a hard-coded string that is not dependent on the input :/

borkdude 2021-02-25T11:44:45.084Z

if this was a function, then we could plug in humanize there

borkdude 2021-02-25T11:44:50.084200Z

maybe they will accept a PR

borkdude 2021-02-25T11:45:43.084400Z

I will ask. This would also helpful for clojure.spec

borkdude 2021-02-25T11:56:37.084600Z

@ikitommi To clarify: If a lib works in Clojure and with GraalVM, it will also work with bb if it's included as a built-in library. But it's another story when you try to run this lib from source with bb itself

wilkerlucio 2021-02-25T13:41:39.085500Z

does babaksha supports transients? got bitten by missing dissoc!:

wilkerlucio@Wilkers-MacBook-Pro-2 babashka-experiments % bb <http://pathom.bb|pathom.bb>
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Could not resolve symbol: dissoc!
Location: com/fulcrologic/guardrails/utils.cljc:85:89
Phase:    analysis

----- Context ------------------------------------------------------------------
81:
82: (defn map-vals [f m] (if (nil? m) {} (reduce-kv (fn [m k v] (assoc m k (f v))) m m)))
83: (defn map-keys [f m] (if (nil? m) {} (reduce-kv (fn [m k v] (assoc m (f k) v)) {} m)))
84: (let [p! persistent!, t transient]                          ; Note `mapv`-like nil-&gt;{} semantics
85:   (defn filter-vals [pred m] (if (nil? m) {} (p! (reduce-kv (fn [m k v] (if (pred v) m (dissoc! m k))) (t m) m)))))
                                                                                            ^--- Could not resolve symbol: dissoc!

borkdude 2021-02-25T13:42:24.085800Z

it should, but it could be missing :/

wilkerlucio 2021-02-25T13:45:00.086300Z

you pointed to dissoc, the missing one is dissoc!

wilkerlucio 2021-02-25T13:45:12.086500Z

(with exclamation mark)

borkdude 2021-02-25T13:45:15.086700Z

yes, that one is missing, but should be added there

wilkerlucio 2021-02-25T13:45:25.086900Z

ah, ok, so a simple add there will fix it?

borkdude 2021-02-25T13:45:29.087100Z

yes

wilkerlucio 2021-02-25T13:45:54.087300Z

I can send a PR for that if you want

borkdude 2021-02-25T13:46:10.087500Z

please :)

wilkerlucio 2021-02-25T13:48:06.087700Z

https://github.com/borkdude/sci/pull/536/files

wilkerlucio 2021-02-25T13:49:23.087900Z

I'm excited to maybe see Pathom running inside Babashka, that will be awesome 😄

wilkerlucio 2021-02-25T13:49:54.088100Z

was just trying that spartan spec hack to get though spec (that was the blocker)

borkdude 2021-02-25T13:50:09.088300Z

why does pathom need spec?

wilkerlucio 2021-02-25T13:50:33.088500Z

macros, I use the spec regex to parse custom macro syntax

borkdude 2021-02-25T13:51:23.088700Z

Merged, and I pushed the new sci to bb master. Binary will appear in #babashka-circleci-builds soon

wilkerlucio 2021-02-25T13:52:00.088900Z

awesome! 🎉

wilkerlucio 2021-02-25T14:01:21.089300Z

is there a proper way to make this portable with Babashka?

wilkerlucio@Wilkers-MacBook-Pro-2 babashka-experiments % ~/Local\ Files/bb <http://pathom.bb|pathom.bb>
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Could not resolve symbol: clojure.lang.Atom
Location: com/fulcrologic/guardrails/utils.cljc:88:31
Phase:    analysis

----- Context ------------------------------------------------------------------
84: (let [p! persistent!, t transient]                          ; Note `mapv`-like nil-&gt;{} semantics
85:   (defn filter-vals [pred m] (if (nil? m) {} (p! (reduce-kv (fn [m k v] (if (pred v) m (dissoc! m k))) (t m) m)))))
86:
87: #?(:clj
88:    (defn atom? [x] (instance? clojure.lang.Atom x))
                                  ^--- Could not resolve symbol: clojure.lang.Atom
89:    :cljs
90:    (defn ^boolean atom? [x] (instance? Atom x)))

borkdude 2021-02-25T14:02:53.089700Z

@wilkerlucio I think clojure.lang.IAtom works

borkdude 2021-02-25T14:04:12.089900Z

$ bb -e '(instance? clojure.lang.IAtom (atom nil))'
true

wilkerlucio 2021-02-25T14:04:56.090Z

this seems to say true for everything:

wilkerlucio@Wilkers-MacBook-Pro-2 babashka-experiments % ~/Local\ Files/bb -e "(satisfies? clojure.lang.IAtom {})"
true
wilkerlucio@Wilkers-MacBook-Pro-2 babashka-experiments % ~/Local\ Files/bb -e "(instance? clojure.lang.IAtom {})"
true
wilkerlucio@Wilkers-MacBook-Pro-2 babashka-experiments % ~/Local\ Files/bb -e "(instance? clojure.lang.IAtom (atom {}))"
true
wilkerlucio@Wilkers-MacBook-Pro-2 babashka-experiments % ~/Local\ Files/bb -e "(satisfies? clojure.lang.IAtom (atom {}))"
true

borkdude 2021-02-25T14:05:17.090200Z

omg..

borkdude 2021-02-25T14:05:48.090400Z

This is probably a bug

borkdude 2021-02-25T14:06:13.090600Z

I will file an issue

borkdude 2021-02-25T14:07:14.090800Z

For now you can use this workaround:

$ bb -e '(= "clojure.lang.Atom" (.getName (class (atom nil))))'
true
Note that you can use reader conditionals, :bb should go before :clj

wilkerlucio 2021-02-25T14:08:12.091Z

gotcha, thanks, about making (instance? clojure.lang.Atom x) works, its out of scope for babashka?

wilkerlucio 2021-02-25T14:08:29.091200Z

I found interesting that the class type is correct, but I dont understand why the instance check doesn't work

wilkerlucio 2021-02-25T14:08:50.091400Z

(or why it can't find a class by name, but can by inspecting the atom)

borkdude 2021-02-25T14:28:42.091600Z

@wilkerlucio This has to do with how sci works. You have to explicitly add classes by name in order for them to get resolved.

borkdude 2021-02-25T14:29:28.091800Z

But IAtom is basically a hack to make it work with defrecord and defprotocol and this is probably related to the instance? bug, I'll check

borkdude 2021-02-25T14:51:26.092100Z

I see. In bb/sci IAtom is implemented as a protocol and this protocol has a default dispatch and this is why satisfies? returns true for all object. This is the root cause of this bug.

borkdude 2021-02-25T14:59:50.092300Z

This needs a deeper look. Sorry for the inconvenience here.

👍 1
wilkerlucio 2021-02-25T15:59:45.092600Z

no worries, just experimenting at this point, no impact 😉

borkdude 2021-02-25T16:00:30.092800Z

The root cause is that IAtom is implemented using multimethods under the hood and we have a default, so basically everything returns true for this particular hack ;)

borkdude 2021-02-25T16:00:52.093Z

This was done so people could reify IAtom

borkdude 2021-02-25T16:01:20.093200Z

I am trying to implement this now without a default multimethod, but this doesn't work in CLJS :/

borkdude 2021-02-25T19:21:01.093500Z

@wilkerlucio The bug should be fixed on master now

wilkerlucio 2021-02-25T20:32:50.094Z

you are awesome man! 🎉

borkdude 2021-02-25T20:46:32.094200Z

I am awaiting your next issue :)

👍 1
steveb8n 2021-02-25T22:00:54.094500Z

damn, you are a fast worker. being locked inside by winter must be good for productivity 🙂

borkdude 2021-02-25T22:04:23.094700Z

The weather is getting better now...

isak 2021-02-25T22:08:08.097Z

This might be a little niche, but I just released a pod that can format T-SQL using the vendor library (on .NET): https://github.com/xledger/pod_tsql_scriptdom

🎉 2
borkdude 2021-02-25T22:11:23.097300Z

I love niche projects!

🙂 1
borkdude 2021-02-25T22:13:22.098Z

@isak Are you aware that there is now also a native mssql pod? You can talk directly to mssql from a pod, from the pod registry

borkdude 2021-02-25T22:13:40.098400Z

I haven't tested it myself, since I don't have a ms sql db to connect to

isak 2021-02-25T22:14:48.099200Z

This one? https://github.com/xledger/pod_sql_server yea I use it for scripting

borkdude 2021-02-25T22:15:33.099900Z

@isak no this one:

(require '[babashka.pods :as pods])
(pods/load-pod 'org.babashka/mssql "0.0.1")
https://github.com/babashka/babashka-sql-pods/

borkdude 2021-02-25T22:16:02.100200Z

this one doesn't need a .NET install and downloads automatically

borkdude 2021-02-25T22:16:20.100600Z

some testing would be nice

isak 2021-02-25T22:16:54.101400Z

oh sweet, I'll give it a shot. Usually the problem is integrated security, but maybe they figured it out.

borkdude 2021-02-25T22:18:25.102200Z

ah hm, not sure. @jvtrigueros is the guy who did the work on that, he might know

borkdude 2021-02-25T22:19:28.102700Z

I guess it's not much different from connecting from a regular Clojure program via JDBC

isak 2021-02-25T22:20:59.104Z

For normal JDBC, it is a little tedious, because you need a special dll for that to work, and it doesn't seem to come packaged properly with the rest of the driver deps

borkdude 2021-02-25T22:21:21.104200Z

Right.

borkdude 2021-02-25T22:22:10.104900Z

I think it would be good to add a link to your pod in section with related sql pods. Feel free to PR with some details (I don't know enough about mssql)

1
borkdude 2021-02-25T22:23:02.105300Z

You can also add a link to your sql formatting pod

1
isak 2021-02-25T22:24:50.105600Z

Hmm, I'm getting this error:

Type:     java.lang.IllegalArgumentException
Message:  No executable found for pod org.babashka/mssql (0.0.2) and OS Windows Server 2016/x86_64
from this:
(require '[babashka.pods :as pods])
(pods/load-pod 'org.babashka/mssql "0.0.2")

2021-03-02T19:05:42.230400Z

Sorry I didn't try on Windows!

1
borkdude 2021-02-25T22:27:11.106100Z

aah that's right, sorry about that. There is no Windows version (yet)

borkdude 2021-02-25T22:27:28.106400Z

You could try from WSL(2) perhaps, some time. No worries.

isak 2021-02-25T22:42:03.107800Z

Ok just tested it. Unfortunately I get this error when adding :integratedSecurity true to the db spec:

----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  This driver is not configured for integrated authentication. ClientConnectionId:889ad681-4fdf-409c-b12c-9eef93129023

borkdude 2021-02-25T22:43:36.108200Z

Nice, another thing to add to the troubleshooting section then. Along with a link to your pod

borkdude 2021-02-25T22:43:54.108400Z

Thanks a lot for trying

isak 2021-02-25T22:44:17.108600Z

np