Fork me on GitHub
#babashka
<
2022-03-08
>
Eugen10:03:59

hi, I raised an issue in babashka.fs https://github.com/babashka/fs/issues/48

borkdude10:03:14

@eugen.stan As an alternative you can use for now

👍 1
Martynas Maciulevičius10:03:20

Hey. Does babashka support plumatic/schema and their generators? What about this? https://github.com/deercreeklabs/lancaster Is there a good reason it should support some of this?

borkdude10:03:58

@invertisment_clojuria It does not support schema (I doubt it will work from source), but bb does support clojure.spec.alpha (from source, here: https://github.com/babashka/spec.alpha) + clojure.test.check generators

Martynas Maciulevičius10:03:42

Then this means that can't be supported either because it uses schema underneath. Thanks.

borkdude10:03:58

If these deftypes were defrecords it might work in bb though: https://github.com/plumatic/schema/blob/2b864ab32ddf48bebe779876506577838a32dd1b/src/cljc/schema/utils.cljc#L91 It's worth looking into this.

Gunnar11:03:16

I'm struggling to organize my babashka project in a way that feels convenient with bb.edn vs preload vs tasks vs bb-invocation flags etc. My goal is simply to replace several bash aliases and shell functions with clojure implementations. Would anyone like to help me with tips/best practice/etc?... More details coming in thread.

1
Gunnar12:03:44

Basically, what I expect is this and I might extend it from there 1. One CLJ file containing several independent functions 2. Possibly using some extra Java lib, if it loads fast enough 3. Likely using some clojure libs 4. One .sh file connecting them, e.g. alias doit='bb -i '(myutils/doit *input*)' doit2() { # shell function some shell code branch out to clojure }

Gunnar12:03:00

Now, I looked at tasks but I'm not sure if I get it, or if it doesn't apply. It seems to suggest it should replace "Makefile" style operations. So it is for building/doing stuff with your project, rather than implementing small callable functions like above? Or is tasks the right way to access the individual functions in a single utils.clj ? It just hasn't clicked for me so far.

borkdude12:03:40

@U0359E1F02H You can make a global tasks file in e.g. ~/tasks/bb.edn and then call it with bb --config ~/tasks/bb.edn mytask . You can make a small bash wrapper for this, so you can call tasks mytask

Gunnar12:03:42

Of course I want the bb invocation to be as simple as possible from the shell side, but whatever is required is fine.... Another idea is to have a main function, which takes an argument and calls out to the clojure function with that name and provides the *command-line-args and input* etc.?

Gunnar12:03:29

OK... thanks let me try that with tasks, it didn't quite click before

borkdude12:03:22

You are right that tasks are mainly for project-specific tasks, but it can be used as I described above too

borkdude12:03:15

What you can also do:

bb -cp ~/tasks -m foo/bar
which executes the function bar in ~/tasks/foo.clj

borkdude12:03:22

and write a small bash wrapper for that

Gunnar12:03:57

OK, yeah, the second one feels more right to me. Considering this for example with tasks: https://gist.github.com/borkdude/35bc0a20bd4c112dec2c5645f67250e3 It feels to me like another indirection level. It feels more natural to me to do bb '(clojure function)' rather than bb 'task' and have to define each "task" as a simple redirect to the actual clojure function I want to call. and defining them all inside of the { } structure just doesn't feel nice to me.

Gunnar12:03:22

The second one seems reasonable, let me try it.

Gunnar12:03:08

... but ... hmm, how do I pass in input ?

bb -cp ~/tasks -m foo/bar

borkdude12:03:02

forget about *input* , just use (slurp *in*) in scripts.

Gunnar12:03:03

Let me try this a while and come back.

Gunnar12:03:50

Namespace used in foo.clj must be exactly "foo" for this to work?

Gunnar12:03:56

Got it. Yes I think this got me over the hump. Thanks @U04V15CAJ. And thanks for BB, awesome stuff! (I already wrote many of the functions 🎉 so I'm glad I got this invocation stuff clarified)

👍 1
oddsor13:03:42

Hello! Is there a way to require Specter in a bb-script? I’ve tried this:

(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {com.rpl/specter {:mvn/version "1.1.3"}
                        ; Add ridley because specter complains about it being missing
                        riddley/riddley {:mvn/version "0.1.12"}}})
(require '[com.rpl.specter :as s])
; => java.lang.Exception: Unable to resolve classname: clojure.lang.Var [at riddley/compiler.clj:2:3]

borkdude13:03:38

@odd.andreas specter relies on pretty low level Clojure stuff which isn't supported in bb (yet)

oddsor13:03:32

I suspected as much! Thanks anyway, I’ll suffer without it for now 😊

borkdude13:03:02

I do have a CLI here which brings specter to the command line: https://github.com/borkdude/specter-cli

👀 1
borkdude15:03:55

@odd.andreas I briefly looked into it and it seems specter may work with bb if a few patches are applied:

$ clojure -M:babashka/dev -cp src/clj -e "(use '[com.rpl.specter]) (def data [1 2 3 4 5 6 7 8]) (transform [ALL] inc data)"
[2 3 4 5 6 7 8 9]
It won't be fast, but you will have the convenience of the DSL

oddsor15:03:49

cool beans! The performance aspect isn’t that interesting to me at least, I was just working on a script that transformed a nested yaml file and the code ended up looking pretty horrible (`(update .. (map (update .. (map …))))`) So I figured if specter was easily available I could at least write a simple path down to the thing I want to modify 😊

borkdude15:03:26

I discovered some things which need to be fixed first so maybe in a couple of weeks or so

oddsor15:03:17

Very cool, thanks! Really loving Babashka as a tool so far 🙏 My use-case is covered for now with my terrible update-algorithm so I’m not in a hurry 😊

borkdude15:03:15

$ ./bb -cp src/clj -e "(use '[com.rpl.specter]) (def data {:a [1 2 3]}) (setval [:a END] [4 5] data)"
{:a [1 2 3 4 5]}

borkdude15:03:28

I'm surprised it works :)

🤓 1
babashka 1
borkdude 1
👍 1
borkdude20:03:40

@odd.andreas specter is now available as a library to be used in babashka, see Changelogs :)

🙌 1
🎉 1
babashka 1
borkdude20:03:11

You need to use my fork though, which adds a compatibility commit for babashka. Hopefully #specter will accept it back as a PR

borkdude20:03:56

All specter tests are passing