Fork me on GitHub
#babashka
<
2021-05-31
>
Nicolas Estrada13:05:01

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

❤️ 1
Nicolas Estrada13:05:43

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 Estrada13:05:42

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

Nicolas Estrada13:05:52

since using s3 is completely optional IMHO

borkdude13:05:45

@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 Estrada13:05:44

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

borkdude13:05:22

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

borkdude13:05:02

@nicolas.estrada938 There is a temporary hack possible:

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

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

borkdude13:05:25

This loads to another issue:

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

Nicolas Estrada13:05:33

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

borkdude13:05:59

ExceptionInfo is available:

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

borkdude13:05:39

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

borkdude13:05:37

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 Estrada13:05:39

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

borkdude13:05:21

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 Estrada13:05:07

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 Estrada13:05:15

But thanks! 🙏

borkdude13:05:03

cprop and docopt should both work

borkdude13:05:26

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

borkdude13:05:15

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

borkdude13:05:28

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

borkdude13:05:08

it was recently made compatible with bb

Nicolas Estrada13:05:17

Ok I'll look into it 😉

borkdude13:05:46

I'll make issues for the omniconfig things

borkdude14:05:56

or perhaps this syntax should just die:

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

borkdude14:05:20

Rather one should just write

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

👌 1