babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
kokada 2021-05-31T01:27:08.312500Z

Huh... I may have a usage for the second one

Nicolas Estrada 2021-05-31T13:37:01.314500Z

Hi everyone, and thank you again @borkdude for such a great tool... I'm writing clojure again (in an elixir shop now)..

❤️ 1
Nicolas Estrada 2021-05-31T13:38:43.316300Z

Anyhow how can I check to see if https://github.com/grammarly/omniconf could be supported by babashka.. Many people don't like it since it stores all state in a global atom like integrant, but for scripting it's just fine and it does all of the property/env/cli merging magic in a very explicit way

Nicolas Estrada 2021-05-31T13:39:42.317100Z

It has some unfortunate dependencies on aws libs I'm afraid which would require a PR I think

Nicolas Estrada 2021-05-31T13:39:52.317400Z

since using s3 is completely optional IMHO

borkdude 2021-05-31T13:40:45.317900Z

@nicolas.estrada938 How I would test this is:

$ cat /tmp/omni.clj
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {com.grammarly/omniconf {:mvn/version "0.4.3"}}})
(require '[omniconf.core :as cfg])
This gives me:
$ bb /tmp/omni.clj
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Unable to resolve classname: StackTraceElement
Phase:    analysis

Nicolas Estrada 2021-05-31T13:41:44.318400Z

I'm opening an issue 😉 Or maybe I'll just fork it

borkdude 2021-05-31T13:43:22.318900Z

they could make this function optional for bb possibly using a reader conditional, #?(:bb ... :clj ...)

borkdude 2021-05-31T13:46:02.319200Z

@nicolas.estrada938 There is a temporary hack possible:

(ns omniconf.core)
(defrecord StackTraceElement [])

(require '[omniconf.core :as cfg] :reload)

borkdude 2021-05-31T13:46:25.319600Z

This loads to another issue:

Unsupported binding key: :forms
Not sure why this is. Perhaps a bug in babashka...

Nicolas Estrada 2021-05-31T13:47:33.320400Z

I'm actually suprised you were able to port so many libraries without the core ExceptionInfo class and the underlying java.lang classes

borkdude 2021-05-31T13:48:59.320700Z

ExceptionInfo is available:

$ bb -e 'clojure.lang.ExceptionInfo'
clojure.lang.ExceptionInfo

borkdude 2021-05-31T13:49:39.321Z

A lot of Java classes are available. Just not all, it's by choice

borkdude 2021-05-31T13:52:37.322700Z

Not sure what the issue is with :forms, this seems to work in bb:

(defn foo
  "docstring"
  {:forms '([& ks value] [ks-vec value])}
  [& args])

Nicolas Estrada 2021-05-31T13:52:39.322800Z

Of course, I understand, I'm just surprised that you were able to manage Throwables without importing all of the gunk that goes along with it 😅 No sweat

borkdude 2021-05-31T13:53:21.323500Z

Feel free to post an issue about it. So far we didn't include StackTraceElement but if the size doesn't grow too big it might make sense for compatibility.

Nicolas Estrada 2021-05-31T13:56:07.324700Z

I more curious how other compatible libraries are able to work, before opening an issue I'll look into other libs like cprop and docopt

Nicolas Estrada 2021-05-31T13:56:15.324900Z

But thanks! 🙏

borkdude 2021-05-31T13:57:03.325400Z

cprop and docopt should both work

borkdude 2021-05-31T13:57:26.326Z

I see the issue with :forms is:

(defn populate-from-env
  "Fill configuration from environment variables. This function must be called
  only after `define`. If `quit-on-error` is true, immediately quit when program
  occurs."
  ([quit-on-error]
   (@logging-fn "WARNING: quit-on-error arity is deprecated.")
   (populate-from-env))
  ([]
   (try-log
    (let [env (System/getenv)
          kvs (for [[env-name spec] (flatten-and-transpose-scheme :env @config-scheme)
                    :let [value (clj/get env env-name)]
                    :when value]
                [(:name spec) (parse spec value)])]
      (@logging-fn (format "Populating Omniconf from env: %s value(s)" (count kvs)))
      (doseq [[k v] kvs] (set k v)))))
  {:forms '([])})
This lib using a trailing metadata map which is not recognized by bb at the moment

borkdude 2021-05-31T13:58:15.326400Z

if I get rid of all of those and get rid of StackTraceElement, then the code does work

borkdude 2021-05-31T13:58:28.326700Z

so forking might make sense if you're really keen on this specific lib

borkdude 2021-05-31T13:59:00.327200Z

At work we are using this library: https://github.com/dunaj-project/crispin

borkdude 2021-05-31T13:59:08.327600Z

it was recently made compatible with bb

Nicolas Estrada 2021-05-31T13:59:17.327900Z

Ok I'll look into it 😉

borkdude 2021-05-31T13:59:46.328200Z

I'll make issues for the omniconfig things

borkdude 2021-05-31T14:00:56.328600Z

or perhaps this syntax should just die:

(defn foo
  ([])
  ([_ _])
  {:x true})
clj-kondo also doesn't recognize it

borkdude 2021-05-31T14:01:20.328900Z

Rather one should just write

(defn foo
  {:x true}
  ([])
  ([_ _]))

👌 1