This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-02
Channels
- # announcements (13)
- # architecture (18)
- # babashka (90)
- # beginners (80)
- # calva (35)
- # chlorine-clover (29)
- # cider (24)
- # clj-kondo (4)
- # cljfx (3)
- # clojure (60)
- # clojure-australia (2)
- # clojure-europe (60)
- # clojure-france (2)
- # clojure-germany (3)
- # clojure-italy (4)
- # clojure-nl (84)
- # clojure-norway (7)
- # clojure-uk (53)
- # clojurescript (54)
- # clojureverse-ops (1)
- # community-development (6)
- # conjure (1)
- # contributions-welcome (1)
- # cursive (12)
- # datomic (1)
- # fulcro (16)
- # garden (61)
- # girouette (1)
- # graalvm (14)
- # hugsql (1)
- # instaparse (5)
- # jobs-discuss (11)
- # keechma (1)
- # lambdaisland (3)
- # off-topic (20)
- # pathom (1)
- # re-frame (3)
- # reitit (2)
- # releases (1)
- # remote-jobs (2)
- # reveal (11)
- # shadow-cljs (58)
- # spacemacs (5)
- # sql (3)
- # startup-in-a-month (1)
- # vim (2)
If I want to use babashka for project automation scripting, in a cross-platform way, would using the jar be wise?
Currently getting this error, but maybe I need to use a newer version of Java?
[brandon@brandon-desktop calva]$ java -jar bb.jar -h
Exception in thread "main" java.lang.UnsupportedClassVersionError: sci/impl/Reflector has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Is it only runnable with that specific version? I tried the above with jdk 15 and got IllegalArgumentException: Uknown signal: PIPE
[brandon@brandon-desktop calva]$ java -version
openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-b01)
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)
Thinking about it, I'm not sure the cross-platform / include-the-tool-in-project really is a big concern. Devs already need other tools to work on a given project. 😄
Worst case you could build a static binary with graal maybe? The babashka docker file and scripts are pretty manageable
Thanks. It seems for dev use it makes sense to just require the developer of Calva install the bb binary for their machine.
@brandon.ringe I'm not sure if the .jar adds anything beyond a normal clojure project. babashka is basically a clojure interpreter + a set of libraries. So using it from the JVM kind of defeats the purpose of good startup time.
Maybe you could explain your use case more. If this is just used as an alternative to clojure
inside of Calva I suggest using the deps.clj
jar.
Latest Calva actually is using deps.clj
for this (on Windows). Have I then introduced a requirement for some special version of Java?
As for @brandon.ringe’s use case it is for a script during Calva development. We’ll probably just require that people have babashska installed to use the script.
As for scripting for development. I think people should just install bb for Calva dev. It's available for every major OS
so people can run the scripts using that if they don't have bb and don't want to use it.
> As for scripting for development. I think people should just install bb for Calva dev. It’s available for every major OS Yes, that’s where we are going.
Is it possible to test a process that accepts stdin and produces to stdout via babashka?
my idea is to create some kind of integration test for clojure-lsp, where I run the process, send some json and expect other json
Is it possible with https://github.com/babashka/process?
I'm trying something like that:
#!/usr/bin/env bb
(require '[babashka.process :refer [process $ check]])
(with-out-str (check (process '[clojure-lsp]
{:in "{}\r\n" :out *out*})))
@UKFSJSM38 you, you can add :in
and :out
args to a process
I'm trying with something like this:
(def clojure-lsp-proc (process '[clojure-lsp]))
(when-not (.isAlive (:proc clojure-lsp-proc))
(println "TODO error")
(System/exit 1))
(def stdin (io/writer (:in clojure-lsp-proc)))
(binding [*out* stdin]
(println "{}\r\n"))
(.close stdin)
(println (slurp (:out clojure-lsp-proc)))
I'd need something that I can print to stdin and keep open and sync listen for stdout after each stdin input
the issue is: server can return a json on that pattern anytime, and I just want to parse it, check if is the json I want or ignore it
so the server receives an input in that pattern and can start respondinhg with multiple responses following that pattern
For some reason it keeps waiting for the stout stream:
(def clojure-lsp-proc (process '[./clojure-lsp]))
(when-not (.isAlive (:proc clojure-lsp-proc))
(println "TODO error")
(System/exit 1))
(def stdin (io/writer (:in clojure-lsp-proc)))
(def stout (io/reader (:out clojure-lsp-proc)))
(binding [*out* stdin]
(println "Content-Length: 3")
(println "")
(println "{}"))
(println (with-open [rdr stout]
(reduce conj [] (line-seq rdr))))
this is because line-seq will consume until EOF and if your process is still alive and waiting for more input, you won't get an EOF
what's the best approach here so? It'd be great if I could say, read next 3 lines (Content Type, newline and the json content)
yeah, so do (read-line)
twice, while binding *in*
to the stdout an then read one JSON value from the stream
(def clojure-lsp-proc (process '[./clojure-lsp]))
;; (def clojure-lsp-proc (process '[cat]))
(when-not (.isAlive (:proc clojure-lsp-proc))
(println "TODO error")
(System/exit 1))
(def stdin (io/writer (:in clojure-lsp-proc)))
(def stout (io/reader (:out clojure-lsp-proc)))
(binding [*out* stdin]
(println "Content-Length: 3")
(println "")
(println "{}"))
(binding [*in* stout]
(println (read-line))
(println (read-line))
(println (read-line)))
(println "Done!")
Right?
Still freezesI changed to
(binding [*in* stout]
(println "->" (read-line))
(println "->" (read-line))
(println "->" (read-line)))
Oh, also there is a time for the server start to respond (2-3s) Not sure if it's related
Not sure I did something wrong:
(def clojure-lsp-proc (process '[./clojure-lsp]
{:out :inherit}))
(def stdin (io/writer (:in clojure-lsp-proc)))
(def stout (io/reader (:out clojure-lsp-proc)))
(binding [*out* stdin]
(println "Content-Length: 3")
(println "")
(println "{}"))
(binding [*in* stout]
(println "->" (read-line))
(println "->" (read-line))
(println "->" (read-line)))
(println "Done!")
:
-> nil
-> nil
-> nil
Done!
(def clojure-lsp-proc (process '[./clojure-lsp]
{:out :inherit}))
(def stdin (io/writer (:in clojure-lsp-proc)))
;; (def stout (io/reader (:out clojure-lsp-proc)))
(binding [*out* stdin]
(println "Content-Length: 3")
(println "")
(println "{}"))
;; (binding [*in* stout]
;; (println "->" (read-line))
;; (println "->" (read-line))
;; (println "->" (read-line)))
(println "Done!")
(Thread/sleep 20000)
if it doesn't print anything, then something is probably wrong. Add some debugging by printing to stderr from the process. Also use :err :inherit
.
sorry, I forgot to mention that a {}
should return an error, but I though it was considered output anyway
Now I need to remove the debugging out inherit and handle that without sleeping somehow
Ok, with this:
(def clojure-lsp-proc (process '[./clojure-lsp]))
(def stdin (io/writer (:in clojure-lsp-proc)))
(def stout (io/reader (:out clojure-lsp-proc)))
(binding [*out* stdin]
(println "Content-Length: 59")
(println "")
(println "{\"jsonrpc\":\"2.0\",\"method\":\"initialize\",\"params\":{},\"id\":1}"))
(binding [*in* stout]
(println "->" (read-line))
(println "->" (read-line))
(println "->" (read-line)))
(println "Done!")
I get:thanks for the help @U04V15CAJ!
before trying bb, I searched a little bit on how to read process output dynamically and send input via bash
@U04V15CAJ Is it possible to run a babashka script (with bb interpreter on header) from windows?