Fork me on GitHub
#babashka
<
2024-04-18
>
Dan11:04:25

I have a very simple script that uses tablecloth. foo.clj looks like this:

(require '[tablecloth.api :as tc])

(prn (tc/dataset {:A [1 2 3]}))
and bb.edn looks like this:
{:deps {scicloj/tablecloth {:mvn/version "7.029.1"}}}
I've tried running this with Clojure (copying bb.edn over as deps.edn) and it seems to run okay. But when using Babashka I get the following error message:
quote
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: java.util.concurrent.locks.ReentrantLock
Location: tech/v3/datatype/export_symbols.clj:4:3

----- Context ------------------------------------------------------------------
1: (ns tech.v3.datatype.export-symbols
2:   (:require [ :as io]
3:             [clojure.tools.logging :as log])
4:   (:import [ Writer]
     ^--- Unable to resolve classname: java.util.concurrent.locks.ReentrantLock
5:            [java.util.concurrent.locks ReentrantLock]))
6: 
7: (def ^ReentrantLock load-lib-lock (ReentrantLock.))
8: 
9: 

----- Stack trace --------------------------------------------------------------
tech.v3.datatype.export-symbols - tech/v3/datatype/export_symbols.clj:4:3
tablecloth.api.api-template     - tablecloth/api/api_template.clj:4:3
tablecloth.api                  - tablecloth/api.clj:4:3
user                            - /Users/username/Desktop/babashka-test/foo.clj:1:1
I am new to Babashka, so it may well be a PEBKAC issue. Am I doing something daft here?

borkdude11:04:11

The number of supported classes in bb is a hardcoded list. This class is currently not in it. I can look if adding this class would make this dependency work but I’d expect that tablecloth has some other issues with bb as well

Dan11:04:09

Ah, I see. Thanks for the clarification!

borkdude11:04:08

The next thing when adding that missing class is:

$ clj -M:babashka/dev -Sdeps '{:deps {scicloj/tablecloth {:mvn/version "7.029.1"}}}' -e "(require '[tablecloth.api :as tc])"
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: org.apache.commons.math3.exception.NotANumberException

borkdude11:04:25

I don't think bb will have a dependency on this Java library, so I guess it won't work.

👍 1
Joakim Verona16:04:56

I have a little bb script that have subcomands and parses some args. The thing works fine as is, its mostly a hack. But I was thinking it would be nice to improve the quality using cli/dispatch and maybe cli/parse-opts. Is there any example doing this? Also it would be nice if there was some wrapper or something on dispatch so clojure functions could be called directly withouth having to parse the args themselves. Is there something like that available?

borkdude16:04:30

you can call clojure functions directly with bb.cli supports via:

bb -x foo.bar/baz

borkdude16:04:01

you can specify the parsing stuff as metadata on the function

Joakim Verona19:04:56

tnx! I'll have a look at neil

mmer07:04:49

I use clojure.tools.cli and I parse it in the :init of the tasks and then I can use the values in each of the tasks I have set up. Seems to work well.