Fork me on GitHub
#beginners
<
2021-03-31
>
zackteo07:03:27

I believe I have asked this before but couldn't seem to find it from digging up the zulip logs. May I ask what ways are there to run python scripts from Clojure (backend)? I understand I can use clojure.java.shell/sh or some java interop (?) (I recall someone might have mentioned there a new api to do so?), as well as graalvm and lib-pythonclj . I want to send quite a lot of (database) data to the python scripts, would passing the python script a large json work out alright? Would preferably like to keep it as a python script so that my friends working pick up Clojure and do interop

cschep16:03:21

you could do something like, save the database data to a file (JSON maybe?) and then kick off a python script (from clojure or manually while testing) to read that JSON in and do whatever it needs to do

Franco Gasperino20:03:48

agree with cshep - use the file system as an async queue between applications.

zackteo23:03:49

Mmmm, I guess that does seem to be the best way :thinking_face: given the constraints. Just 2 questions - How should I call python from clojure - is there a better way than clojure.java.shell/sh ? Would the step of saving as a file be necessary - would sending the entire json in the call be better?

Drew Verlee16:03:52

swap! just calls compare-and-set! until it's accepted right?

ghadi16:03:40

correct @drewverlee

đź‘Ť 3
andy.fingerhut20:03:04

well, and repeating calls to your provided function each time, too.

sova-soars-the-sora21:03:28

I know you said no lein/boot... is there another way to run a clojure program / clojure server process?

noisesmith22:03:04

clojure is a java library, all you used to need is the java vm + a jar with clojure in it (plus your source), now you need a dep manager because clojure.jar no longer comes with all its deps

noisesmith22:03:18

that's why deps.edn / the clj cli tool came out

noisesmith22:03:11

similarly clojurescript is a java library (using clojure) that outputs js

noisesmith22:03:41

you can still run clojure without a dep manager, if you get a valid classpath

(ins)justin@abjection:~$ CLJCP=$(clj -Spath)
(ins)justin@abjection:~$ echo $CLJCP
src:/home/justin/.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1.jar:/home/justin/.m2/repository/org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar:/home/justin/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar
(ins)justin@abjection:~$ java -cp $CLJCP clojure.main
Clojure 1.10.1
user=> (+ 1 1)
2

noisesmith22:03:36

of course I used the package manager to get those deps into the .m2 cache

seancorfield23:03:54

@U3ES97LAC When @U01SUNLPN58 said “clojure clj” he meant the Clojure CLI — not Leiningen or Boot. And, yes, it is another way to “run a clojure program / clojure server process”. We use the Clojure CLI at work — with 112K lines of Clojure — we don’t use Leiningen, and we don’t use Boot. Although we did in the past (`lein` from 2011-2015, boot from 2015-2018, CLI/`deps.edn` since 2018).