Fork me on GitHub
#babashka
<
2022-10-03
>
Benjamin14:10:16

what is the easiest way to pass an options map in bb script (should not be a one liner so not (slurp *input*) . Do I say (read-string read-line )

lispyclouds14:10:06

Maybe using https://github.com/babashka/cli here is nicer? can do it like cli command :opt1 v1 :opt2 v2 which is technically a map 😛

borkdude14:10:00

You can use bb -x ns/func --foo 1 --bar 2 now (you may need to upgrade your bb)

borkdude14:10:32

But maybe I'm not understanding your problem right

Benjamin15:10:23

ah that is nice

richiardiandrea20:10:19

Hi babashka folks, I am following the Book on how to https://book.babashka.org/#_running_tests I was wondering if there is a way to explore the loaded namespaces and required them dynamically instead of listing all of them there one by one?

borkdude20:10:08

@richiardiandrea In the README of https://github.com/babashka/tools.namespace you can see how to run cognitect test runner with bb which does auto-discovery of namespaces

richiardiandrea20:10:24

cool let me check that, thank you!

richiardiandrea20:10:51

@U04V15CAJ I get an error but it might be on me, can I enable more verbosity for:

Running tests in #{"test"}
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: clojure.lang.Var
It seems to try and run the tests

richiardiandrea20:10:58

or what would be the best course of action for debugging here?

borkdude20:10:41

@richiardiandrea which version of bb is this?

richiardiandrea20:10:55

$ bb --version
babashka v0.8.156

borkdude20:10:20

Can you try to upgrade? The errors have gotten a lot better recently

richiardiandrea20:10:34

ok sounds good will do

richiardiandrea20:10:09

oh that's better, I think I might have a problem with spec-tools

Running tests in #{"test"}
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  defrecord/deftypecurrently only support protocol implementations, found: IFn
Data:     {:type :sci/error, :line nil, :column nil, :file "spec_tools/core.cljc"}
Location: spec_tools/core.cljc:396:1
Phase:    macroexpand

----- Context ------------------------------------------------------------------
392:     (if (sequential? type)
393:       (update spec :type (comp first second))
394:       spec)))
395: 
396: (defrecord Spec [spec form type]
     ^--- defrecord/deftypecurrently only support protocol implementations, found: IFn
397:   #?@(:clj [s/Specize
398:             (specize* [s] s)
399:             (specize* [s _] s)])
400: 
401:   Coercion

----- Stack trace --------------------------------------------------------------
clojure.core/defrecord                                                    - <built-in>
spec-tools.core/dorun                                                     - spec_tools/core.cljc:396:1
spec-tools.core                                                           - spec_tools/core.cljc:396:1
spec-tools.data-spec                                                      - spec_tools/data_spec.cljc:4:3
acuity.core3.models.clinical-configuration.contrast-agent-definition      - /home/cokap/git/cohesic/acuity/domain/src/acuity/core3/models/clinical_configuration/contrast_agent_definition.clj:2:3
... (run with --debug to see elided elements)
cognitect.test-runner/test                                                - /home/cokap/.gitlibs/libs/io.github.cognitect-labs/test-runner/dfb30dd6605cb6c0efc275e1df1736f6e90d4d73/src/cognitect/test_runner.clj:71:5
cognitect.test-runner/test                                                - /home/cokap/.gitlibs/libs/io.github.cognitect-labs/test-runner/dfb30dd6605cb6c0efc275e1df1736f6e90d4d73/src/cognitect/test_runner.clj:62:1
cognitect.test-runner                                                     - /home/cokap/.gitlibs/libs/io.github.cognitect-labs/test-runner/dfb30dd6605cb6c0efc275e1df1736f6e90d4d73/src/cognitect/test_runner.clj:127:38
clojure.core/apply                                                        - <built-in>
user-b15184f8-c0ef-401d-bbb1-7af7bd7ef751                                 - <expr>:26:1

borkdude20:10:57

yeah, that's a limitation in bb :(

👍 1
borkdude20:10:09

although IFn on a record seems to common, perhaps SCI could make a special case for that or so

richiardiandrea20:10:08

ok yeah if that is something you'd consider adding - it's nice, I could even look into that. Or I'll port those data specs to malli , these are my two options

richiardiandrea20:10:09

uhm...then I'd need a malli to spec converted...uhm...

borkdude20:10:11

What I would try if I were you is fork spec-tools and try if it runs in bb without the IFn: https://github.com/metosin/spec-tools/blob/d15ec93049c3c1e843aff171295c8e47253afa0a/src/spec_tools/core.cljc#L482 Because there might be more after that

❤️ 1
borkdude20:10:03

If it runs without the IFn, we could also PR a bb reader conditional to spec-tools

richiardiandrea20:10:52

Oh found another one in

Type:     java.lang.Exception
Message:  Unable to resolve classname: java.lang.ref.SoftReference
Location: clojure/core/cache.clj:13:3

----- Context ------------------------------------------------------------------
 9: (ns ^{:doc "A caching library for Clojure."
10:       :author "Fogus"}
11:   clojure.core.cache
12:   (:require clojure.data.priority-map)
13:   (:import (java.lang.ref ReferenceQueue SoftReference)
      ^--- Unable to resolve classname: java.lang.ref.SoftReference
14:            (java.util.concurrent ConcurrentHashMap)))
15: 
16: (set! *warn-on-reflection* true)
17: 
18: ;; # Protocols and Types

richiardiandrea20:10:05

seems like a too deep of a rabbit hole 😄

borkdude20:10:07

Ah, core cache.... hm

borkdude20:10:24

Maybe core cache needs to be built into bb some day ;)

❤️ 2
richiardiandrea20:10:04

I got rid of the call to core.memoize and things seem good

richiardiandrea20:10:12

not yet working but closer

richiardiandrea20:10:44

oh, another one, just for the fun of it

(throw (UnsupportedOperationException. (format "Unknown merge-type \"%s\"." merge-type)))))
                 ^--- Unable to resolve classname: UnsupportedOperationException

richiardiandrea20:10:30

it is just missing an import there 😄

richiardiandrea20:10:43

probably in the JVM it happens automatically

borkdude21:10:26

ah right, automatic imports, that's an easy fix in src/babashka/impl/classes

borkdude21:10:29

PR welcome

❤️ 1
richiardiandrea21:10:23

also another one, sorry, will open issues for it - just using this as place holder No matching field found: randomUUID for class java.util.UUID

borkdude21:10:46

might need to add this to reflection config, also in classes.clj - thanks, yeah, issues would be good

richiardiandrea21:10:58

I think remove IFn from spec-tools did not work, I get the following:

"babashka.impl.reify2$reify_fn$reify__27572 cannot be cast to clojure.lang.IFn"
which seems to come from:
{:column 34
 :file
   "/home/cokap/.gitlibs/libs/org.babashka/spec.alpha/8df0712896f596680da7a32ae44bb000b7e45e68/src/main/clojure/clojure/spec/alpha.clj"
 :line 950
 :message
   "babashka.impl.reify2$reify_fn$reify__27572 cannot be cast to clojure.lang.IFn"
Not 100% sure they are related though

borkdude21:10:46

Perhaps this comes from spec tools trying to call the spec as a function?

richiardiandrea21:10:40

ah yeah maybe it is trying that I localized the failure, it is triggering it on (s/assert* ::helpers.legacy-api.messages/tree-node-descriptor-changed message)

richiardiandrea21:10:04

and the offending spec indeed looks like

(def tree-node-descriptor-changed
  {:type (s/spec #{type-tree-node-descriptor-changed})
   :ref (s/or :measurement-ref ::legacy-api.tree/measurement-tree-ref
              :report-finding-ref ::legacy-api.tree/report-finding-tree-ref)
   :field string?
   ;; Mirroring api's JsValue, which literally means any JSON value, including arrays and objects
   :value (s/nilable (s/or :number number?
                           :string string?
                           :vector vector?
                           :object map?))})

richiardiandrea21:10:29

so I guess that IFn is kind of necessary?

borkdude21:10:46

I don't know why exactly, but if you can make a smaller repro using only clojure.spec, that could be helpful

richiardiandrea21:10:34

I will do it, but I am not sure anymore this route is worth it...`spec-tools` is kind of falling into deprecation mode from what I have understood...so probably better to spend the time migrating to spec1 or malli

👍 1
richiardiandrea16:10:17

@U04V15CAJ apologies for writing here again, I have introduced merr to the tests and it's got a MerrError in it Now I get No reader function for tag merr.core.MerrError Is there a way to tell the test runner to load reader tags that you know of?

borkdude17:10:21

yes, I'll be back in half an hour

❤️ 1
borkdude17:10:07

can you make a repro for me using merr? when do you need to read a record?

richiardiandrea17:10:20

right, that's the thing I am fixing now...probably we don't need this and use the constructor

richiardiandrea17:10:49

the question probably still stands around records though, but maybe not worth spending too much time on it 😄

borkdude17:10:20

yes, I'm just wondering how you would end up in that situation since I don't see any mention of that in the README

👍 1
borkdude17:10:23

it can be fixed though

borkdude17:10:06

bb just doesn't scan the classpath for these data_readers files because of the startup penalty

richiardiandrea17:10:11

man I totally missed that!