Fork me on GitHub
#babashka
<
2022-08-18
>
Ory Band12:08:00

Hi. I'm currently using a Makefile in combination with Docker Compose to automate launching multiple applications for integration tests. Make allows launching apps in order while also running simple code between them, for example sleeping or polling if an app has already launched before proceeding to launch the next one in order. For example: Launch MongoDB and RabbitMQ in parallel, wait for both of them to initialize, then populate fixtures in both, then launch an application which depends on them. I think bb task runner can replace it and I'm looking for examples for something similar. Questions: 1. Is this a good idea? Specifically what I care to get out of this is to minimize code and make it more cross platform (Linux and OSX). Also make it a bit more readable as Makefils tend to become spaghetti targets with lots of switches e.g. .PHONY everywhere etc 2. Any examples that resemble Makefile as a task runner? (not for compiling deps)

Ory Band13:08:26

very handy! it's the primary thing i'm doing between targets

Ory Band13:08:38

thanks for the link

Ory Band13:08:11

can i get an honest objective-as-possible opinion if it is a good idea to migrate away from Make? It's either gonna be stay on Make, move to bb task runner, or just https://github.com/casey/just

Ory Band13:08:23

i know you're biased, but give it a shot 😉

borkdude13:08:49

Well, I wrote babashka tasks as the Clojure answer to Make :)

borkdude13:08:29

You get all the expressivity of Clojure , so you don't even have to use the features of the task runner, but can just write a couple of functions and call those from the task runner

Ory Band13:08:30

what about comparing this to just? it looks spot on to this kind of thing. only disadvantage is that it's on rust. not a really important reason since i'm only using it and not developing anything

borkdude13:08:05

I would say read the documentation at https://book.babashka.org/#tasks or watch my talk on it and then make your own judgements

borkdude13:08:30

Make and Just are fine, but I like Clojure

Ory Band13:08:19

(i've read that before coming here, was still contemplating)

borkdude13:08:39

Of course there's other people in this channel too, so I'll let them reply here for less biased opinions ;)

lukasz15:08:54

My 2c: yes, you can even use Make for that, but Compose has a couple of features that you won't get easily with just bb + Docker: health checks, dependent services, networking that actually semi-works on macOS. Nothing is stopping you to use bb tasks to call Compose, but you might find yourself reinventing half of what it does (speaking from my experience, I tried to do exactly that some time ago)

pavlosmelissinos15:08:00

Hello! Is there a JSON validation library that is compatible with babashka? I tried out https://github.com/luposlip/json-schema but unfortunately it depends on Java classes that are unavailable (e.g. org.json.JSONObject).

borkdude15:08:22

@pavlos Not that I know of but you could convert the JSON to EDN and then use malli or schema?

borkdude15:08:37

Or you can use #nbb (node.js) which can be used with any npm library

pavlosmelissinos15:08:25

Oh, both are good ideas. I think I'll try nbb out, thanks a lot! 🙂

ingesol19:08:56

Would it be a lot of work bumping https://github.com/babashka/pod-babashka-etaoin to the latest etaoin version? I had a look myself, would be willing to do a PR, but did not immediately understand what everything does in the pod code.

borkdude19:08:17

@ingesol There's a much better solution now: etaoin itself is compatible with #babashka now :)

borkdude19:08:20

I'd be happy to bump things in the pod, but I think it will be deprecated in favor of the source lib sooner than later

ingesol19:08:14

oh, I’m a babashka noob so I thought the pods were required to make things happen

ingesol19:08:27

so I suppose this is the things to use then? https://book.babashka.org/#babashkadeps

borkdude19:08:39

@ingesol etaoin docs for bb: https://github.com/clj-commons/etaoin/blob/master/doc/01-user-guide.adoc#for-bababashka-users this is all very recent, so I'm not surprised you missed this at all

ingesol19:08:27

excellent, thanks! I actually already saw that, but still thought pods were required in addition 🙂

Ethan Miller21:08:40

I have a little data processing script that uses the tech stack (tech.ml.dataset & tablecloth). I am using a deps.edn so I added the bb.edn with {:deps {local/deps {:local/root "."}}}. When I then ran the file from the project root like bb src/main.clj, I got an “Unable to resolve classname” error for something within tech.v3.datatype, one of tech.ml.dataset’s dependencies:

----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: org.apache.commons.math3.exception.NotANumberException
Location: tech/v3/datatype/errors.clj:4:3

----- Context ------------------------------------------------------------------
1: (ns tech.v3.datatype.errors
2:   "Generic, basic error handling.  No dependencies aside from apache commons math
3:   for NAN exception."
4:   (:import [org.apache.commons.math3.exception NotANumberException]
     ^--- Unable to resolve classname: org.apache.commons.math3.exception.NotANumberException
5:            [java.util NoSuchElementException]))
6:
7:
8: (defmacro throwf
9:   "Throw an exception and format a message"

----- Stack trace --------------------------------------------------------------
tech.v3.datatype.errors   - tech/v3/datatype/errors.clj:4:3
tech.v3.datatype.dispatch - tech/v3/datatype/dispatch.clj:2:3
tech.v3.datatype-api      - tech/v3/datatype_api.clj:3:3
tech.v3.datatype          - tech/v3/datatype.clj:4:3
tablecloth.api            - tablecloth/api.clj:4:3
main                      - /Users/emiller/Projects/cts-tagging/src/main.clj:4:3
Any one have any insight as to whether this is because I’ve done something wrong?

Ethan Miller21:08:07

My deps.edn looks like:

{:paths ["src" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.10.3"}
        scicloj/tablecloth {:mvn/version "6.090"}
        io.github.nextjournal/clerk {:mvn/version "0.9.513"}}}

borkdude21:08:03

@U3RGL6XNF bb only supports a preselection of Java classes and can't run any other Java classes - so it's more limited than Clojure JVM

Ethan Miller21:08:27

Ahhh that explains it. Thanks.

teodorlu08:08:16

Hi 🙂 What's your motivation for using bb? Faster startup? Something else? Lots (all? most?) of babashka's nicities (babashka fs, babashka tasks, babashka cli) can be used from JVM Clojure. For example, it's possible to use babashka/cli for CLI argument parsing in a JVM application. bb tasks can easily dispatch to JVM Clojure functions, utilizing babashka/cli to turn bb mytask :message hello into (com.myns/myfunc {:message "hello"})

👀 1
Ethan Miller15:08:21

@U3X7174KS Hi! And thanks for asking. Actually, I had just written a tiny script to do a simple data task for work and since my team doesn’t use Clojure I was trying to sneak it in and make it very easy to run. I’m so inexperienced with actually making Clojure usable ’cause I never get to use it for work so I wasn’t sure what to do. I was hoping to just be able to allow them to run a single command without doing much install and without modifying the code to use a main function.

👍 1
Ethan Miller16:08:47

So basically I have a directory with a deps.edn and then a script src/main.clj . main.clj loads a csv from disk and then processes it. I just want to make it runnable in the easiest possible way.

👍 1
Ethan Miller16:08:00

I guess I may just be able to use clj -X src/main.clj

👍 1
teodorlu17:08:23

In that case, clj -X seems like a good option :) It's also possible to have a single clojure file that uses dependencies. Here's an example: https://stackoverflow.com/a/52433251

waffletower21:08:47

Is it unrealistic for https://github.com/cognitect-labs/aws-api to be loadable and usable via babashka? Currently I run into:

Unable to resolve classname: java.util.TimeZone
which had me looking around in: https://github.com/babashka/babashka/blob/3f404746b484f72df61cf35aef1b0b88347e270e/src/babashka/impl/classes.clj Does TimeZone require reflection or somesuch, or is it just missing?

waffletower21:08:58

A bit more context:

----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: java.util.TimeZone
Location: cognitect/aws/util.clj:11:3

----- Context ------------------------------------------------------------------
 7:             [clojure.data.xml :as xml]
 8:             [clojure.data.json :as json]
 9:             [ :as io]
10:             [clojure.core.async :as a])
11:   (:import [java.text SimpleDateFormat]
      ^--- Unable to resolve classname: java.util.TimeZone
12:            [java.util Date TimeZone]
13:            [java.util UUID]
14:            [ InputStream]
15:            [java.nio.charset Charset]
16:            [java.security MessageDigest]

----- Stack trace --------------------------------------------------------------
cognitect.aws.util    - cognitect/aws/util.clj:11:3
cognitect.aws.client  - cognitect/aws/client.clj:6:3
aws-api-util.core     - aws_api_util/core.clj:3:3
aws-api-util.redshift - aws_api_util/redshift.clj:2:3
user                  - /private/tmp/./redshift:7:1

borkdude21:08:22

@U0E2268BY Check out https://github.com/grzm/awyeah-api which is a re-make of cognitect aws-api for bb

waffletower21:08:57

or should I say …. awyeah

😎 5