Fork me on GitHub
#babashka
<
2023-01-31
>
teodorlu09:01:57

This is kind of a weird use case, but I'm sharing in case. From a babashka REPL in Emacs, I evaluated:

(babashka.process/shell {:out :string} "pandoc" "-f" "markdown" "-t" "json")
This is hanging because pandoc is waiting for something on STDIN. When no input file is provided, pandoc should be used like this:
echo '_tihi_' | pandoc --from markdown --to json
But! M-x cider-interrupt wasn't able to stop the evaluation of the expression, and I had to restart Emacs to continue. If I M-x cider-interrupt from a JVM REPL, I trigger an 1. Unhandled java.lang.InterruptedException, and I gain control back.

borkdude09:01:15

CIDER interrupt doesn't work in babashka as it relies on Thread#stop which is deprecated and not implemented by GraalVM

👍 4
borkdude09:01:45

You could however process/destroy the process, but this requires you to not block on it

👍 2
borkdude09:01:31

with a timeout

👍 2
teodorlu09:01:37

Nice, thank you. I'll fix my code. Interestingly, this is not a problem when I just run my script and rely on lsp+clj-kondo -- which I usually do when I write babashka scripts. Then C-c just works.

borkdude09:01:06

because it kills the entire bb process

👍 2
borkdude09:01:18

you can always do cider-quit to kill the cider nrepl

👀 2
teodorlu09:01:56

M-x cider-quit waited for a while and gave me a "Sync nREPL request timed out (op close)" (when the repl was waiting for (babashka.process/shell {:out :string} "pandoc" "-f" "markdown" "-t" "json"))

borkdude09:01:44

maybe because the processing of messages is single-threaded in the bb nREPL

2
borkdude09:01:48

which can be fixed

borkdude09:01:14

but maybe CIDER should also support killing the nREPL server no matter what

teodorlu09:01:26

Are you seeing the same behavior on your end?

borkdude09:01:42

haven't tested

👍 2
teodorlu09:01:16

I'm not going to speculate on how this should be solved, but I would prefer to be able to get back into a working state without restarting Emacs.

lispyclouds10:01:35

@U3X7174KS is this a jacked-in cider repl? if yes, another work around is to start the repl in a terminal and connect cider to it. when it blocks like this next time ctrl+d in the terminal should get the control back to you in emacs.

👍 4
teodorlu10:01:51

Right, that's a good idea. Then I can also kill the separate process normally.

teodorlu10:01:02

Do you guys normally start your REPL from outside the editor?

lispyclouds10:01:19

i for one do it always. jack-in is too complected

👍 2
borkdude10:01:08

I used to do this a lot, since I wasn't a fan of jack-in but for the reverse reason: if your editor dies, your REPL dies with you. But nowadays I've sometimes been won over by the convenience

👍 2
lispyclouds10:01:21

me being in neovim, my editor almost always ends really often and wanna keep the REPL running 😄

😁 2
borkdude10:01:39

The ClojureStream #babashka workshop hosted by contributor / maintainer and power user @rahul080327 will take place at: 4 Mar 2023 08:00 AM EST / 14:00 CET/ 13:00 GMT https://clojure.stream/workshops/babashka

borkdude17:01:36

With some hack I was able to make (require '[clojure.tools.namespace.repl :refer [refresh]]) work in bb:

$ rlwrap bb -Sdeps '{:deps {org.clojure/tools.namespace {:mvn/version "1.3.0"}}}'

user=> (require '[clojure.tools.namespace.repl :refer [refresh]])
After that, evaluate:
(intern 'clojure.core (with-meta '*loaded-libs* {:dynamic true}) (ref #{}))
since SCI doesn't have *loaded-libs* yet. And also evaluate:
(alter-var-root #'clojure.java.classpath/classpath (constantly (fn [] (map  (babashka.classpath/split-classpath (babashka.classpath/get-classpath))))))
since clojure.java.classpath/classpath assumes class loader stuff that bb doesn't currently have But after that it's smooth sailing :) It's been asked here a few times, I think last time by @eveningsky

👀 2
skylize17:01:08

Not me. But I'm pretty sure I have commented on related threads, so I guess having my name can't hurt anything if trying to search the archives. 😎

skylize17:01:26

Oh. I see. Yeah. It was a dependency issue, not actually me personally way wanting refresh.

skylize17:01:01

... err .... Looks like refresh was my intent. Why did I forget about that? I cannot even remember what I was trying to accomplish. 😵

borkdude10:02:25

ok :) Well, the *loaded-libs* hack shouldn't be necessary anymore on bb master. I'll see if I can also address the clojure.lang.RT/baseLoader issue...

j4m3s21:01:16

Greetings ! First, thanks for this amazing tool it's been a pleasure using it so far. 🙂 I was trying the uberjar functionality and I think I may have found a bug using it. Am I correct to assume that the folders indicated in bb.edn's :paths should be included by default in the classpath ? So that I can open my issue and maybe try myself at fixing it. 🙂

borkdude21:01:00

Yes, this assumption is correct, unless you override the classpath with --classpath or BABASHKA_CLASSPATH

borkdude21:01:26

And thanks :)

borkdude21:01:46

borkdude@m1 /tmp/ub $ cat bb.edn
{:paths ["src"]}
borkdude@m1 /tmp/ub $ ls src
foo.clj
borkdude@m1 /tmp/ub $ bb uberjar foo.jar
borkdude@m1 /tmp/ub $ zipinfo foo.jar
Archive:  foo.jar
Zip file size: 490 bytes, number of entries: 3
-rw----     2.0 fat        0 bX defN 23-Jan-31 22:34 foo.clj
-rw----     1.0 fat        0 bx stor 23-Jan-31 22:35 META-INF/
-rw----     2.0 fat       59 bX defN 23-Jan-31 22:35 META-INF/MANIFEST.MF

j4m3s21:01:33

/tmp/nix-shell.azCa5p/tmp.zgqS5zqMye ❯ bb --version
babashka v1.1.172
/tmp/nix-shell.azCa5p/tmp.zgqS5zqMye ❯ ls
bb  bb.edn  foo.jar
/tmp/nix-shell.azCa5p/tmp.zgqS5zqMye ❯ cat bb.edn
{:path "bb"}
/tmp/nix-shell.azCa5p/tmp.zgqS5zqMye ❯ cat bb/foo.clj
(ns foo)
(defn -main [& args] (prn :hello))
/tmp/nix-shell.azCa5p/tmp.zgqS5zqMye ❯ bb uberjar foo.jar -m foo
Exception in thread "main" java.lang.Exception: The uberjar task needs a classpath.
	at babashka.main$exec.invokeStatic(main.clj:1045)
	at babashka.main$main.invokeStatic(main.clj:1104)
	at babashka.main$main.doInvoke(main.clj:1074)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:667)
	at babashka.main$_main.invokeStatic(main.clj:1137)
	at babashka.main$_main.doInvoke(main.clj:1129)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at babashka.main.main(Unknown Source)

borkdude21:01:02

:paths should be a vector of strings

j4m3s21:01:03

I looked quickly at the code and I think the problem is that the cp/get-classpath doesn't take bb.edn paths into account

borkdude21:01:21

also it's :paths, not :path

j4m3s21:01:49

Arf, I'm sure I tried it before but now it works

j4m3s21:01:10

Sorry for wasting your time, thanks 🙂

borkdude21:01:13

No worries, glad it's solved