Fork me on GitHub
#babashka
<
2021-02-25
>
onetom02:02:21

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.

dharrigan09:02:25

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.

borkdude10:02:42

@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

borkdude10:02:13

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

borkdude10:02:38

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

borkdude10:02:12

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

borkdude11:02:05

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

ikitommi11:02:33

wooot. PR coming? ;)

borkdude11:02:09

(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\""]}

borkdude11:02:34

This doesn't require a PR

borkdude11:02:32

@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 :/

borkdude11:02:45

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

borkdude11:02:50

maybe they will accept a PR

borkdude11:02:43

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

borkdude11:02:37

@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

steveb8n22:02:54

damn, you are a fast worker. being locked inside by winter must be good for productivity πŸ™‚

borkdude22:02:23

The weather is getting better now...

borkdude10:02:30

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

wilkerlucio13:02:39

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

[email protected] babashka-experiments % 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->{} 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!

borkdude13:02:24

it should, but it could be missing :/

wilkerlucio13:02:00

you pointed to dissoc, the missing one is dissoc!

wilkerlucio13:02:12

(with exclamation mark)

borkdude13:02:15

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

wilkerlucio13:02:25

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

wilkerlucio13:02:54

I can send a PR for that if you want

wilkerlucio13:02:23

I'm excited to maybe see Pathom running inside Babashka, that will be awesome πŸ˜„

wilkerlucio13:02:54

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

borkdude13:02:09

why does pathom need spec?

wilkerlucio13:02:33

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

borkdude13:02:23

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

wilkerlucio13:02:00

awesome! πŸŽ‰

wilkerlucio14:02:21

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

[email protected] babashka-experiments % ~/Local\ Files/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->{} 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)))

borkdude14:02:53

@wilkerlucio I think clojure.lang.IAtom works

borkdude14:02:12

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

wilkerlucio14:02:56

this seems to say true for everything:

[email protected] babashka-experiments % ~/Local\ Files/bb -e "(satisfies? clojure.lang.IAtom {})"
true
[email protected] babashka-experiments % ~/Local\ Files/bb -e "(instance? clojure.lang.IAtom {})"
true
[email protected] babashka-experiments % ~/Local\ Files/bb -e "(instance? clojure.lang.IAtom (atom {}))"
true
[email protected] babashka-experiments % ~/Local\ Files/bb -e "(satisfies? clojure.lang.IAtom (atom {}))"
true

borkdude14:02:48

This is probably a bug

borkdude14:02:13

I will file an issue

borkdude14:02:14

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

wilkerlucio14:02:12

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

wilkerlucio14:02:29

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

wilkerlucio14:02:50

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

borkdude14:02:42

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

borkdude14:02:28

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

borkdude14:02:26

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.

borkdude14:02:50

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

πŸ‘ 1
wilkerlucio15:02:45

no worries, just experimenting at this point, no impact πŸ˜‰

borkdude16:02:30

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

borkdude16:02:52

This was done so people could reify IAtom

borkdude16:02:20

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

borkdude19:02:01

@wilkerlucio The bug should be fixed on master now

wilkerlucio20:02:50

you are awesome man! πŸŽ‰

borkdude20:02:32

I am awaiting your next issue :)

πŸ‘ 1
isak22:02:08

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
borkdude22:02:23

I love niche projects!

πŸ™‚ 1
borkdude22:02:22

@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

borkdude22:02:40

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

isak22:02:48

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

borkdude22:02:33

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

borkdude22:02:02

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

borkdude22:02:20

some testing would be nice

isak22:02:54

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

borkdude22:02:25

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

borkdude22:02:28

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

isak22:02:59

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

borkdude22:02:10

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
borkdude22:02:02

You can also add a link to your sql formatting pod

1
isak22:02:50

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

jvtrigueros19:03:42

Sorry I didn't try on Windows!

1
borkdude22:02:11

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

borkdude22:02:28

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

isak22:02:03

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

borkdude22:02:36

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

borkdude22:02:54

Thanks a lot for trying