Fork me on GitHub
#babashka
<
2022-02-09
>
Martynas Maciulevičius14:02:38

Is there a way to run part of my project as a babashka script? The only examples that I found in the repository are the ones that either import some kind of a library or are self-contained in the source file. What if I have many sources and I want to run it from sources? Edit: I found the bb --init but it's not enough because I have quite a bit of sources. Is there a way to form the "classpath-loadpath" automatically? (also I use leiningen for the project and I'm not familiar with edn format)

borkdude15:02:24

@U028ART884X You can use bb -m foo.bar/baz to execute a function if foo/bar.clj is on your classpath

Martynas Maciulevičius15:02:51

Classpath... does it need to be specified in edn? Because my project is in leiningen. Probably that's a problem.

borkdude15:02:17

you can specify it manually with bb -cp src -m foo.bar/baz

1
Martynas Maciulevičius15:02:04

Ok. I'll try it. But I think I have some libraries that babashka won't run. But I want to firstly run something. Thanks.

emccue15:02:57

lein classpath spits the classpath to a file - there is a way to wiggle that in to one command i’m sure

borkdude15:02:00

What you can also do if you want to use libraries that are brought in by leiningen:

lein classpath > .classpath
bb -cp $(cat .classpath) -m foo.bar/baz

Martynas Maciulevičius15:02:52

It worked. Now I have to decide what to do with all of it...

Type:     java.lang.Exception
Message:  Could not find namespace: java-time.

borkdude15:02:51

@U028ART884X It seems the classpath wasn't set properly, else you would see a different error, now it just can't find the java-time namespace since it's not on the classpath

borkdude15:02:37

is your project public?

Martynas Maciulevičius15:02:18

No, my project is internal to the company. But well. I've successfully hit a snag 😄 :

Type:     java.lang.Exception
Message:  Unable to resolve classname: java.lang.reflect.Field
Location: java_time/util.clj:3:3
But the trick with leiningen classpath worked really well. Thanks.

borkdude15:02:37

nice. yeah, this class isn't available in bb (yet). The java.time package is, so if you can avoid this library maybe that would help.

borkdude15:02:29

let me try to see what's needed to add compatibility with this lib

Martynas Maciulevičius15:02:04

It's not important, I think. I think that I import too much where I could split my namespaces.

borkdude15:02:18

OK. I think I was almost there, but java-time uses deftype which is one thing that bb can't handle (yet). https://github.com/dm3/clojure.java-time/blob/f9e11c3f852c14adf579d5101e7e98ec198eb343/src/java_time/properties.clj#L19-L31 If those would be records, then it would run.

😉 1
borkdude15:02:55

There are a couple of other java.time clojure libraries that do work with babashka, e.g. cljc-time

Martynas Maciulevičius15:02:25

Thanks. I don't want to push anybody into doing anything. I wanted to also try out the script runner. I'll try that time lib if I'll need time.