This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-16
Channels
- # announcements (2)
- # asami (5)
- # babashka (52)
- # beginners (42)
- # biff (3)
- # cljdoc (4)
- # cljsrn (2)
- # clojure (30)
- # clojure-austin (35)
- # clojure-dev (3)
- # clojure-france (11)
- # clojurescript (36)
- # conjure (6)
- # cursive (5)
- # fulcro (33)
- # graalvm (41)
- # lsp (54)
- # malli (1)
- # music (2)
- # off-topic (7)
- # overtone (1)
- # pedestal (5)
- # polylith (2)
- # remote-jobs (1)
- # sci (28)
- # shadow-cljs (38)
- # vim (15)
- # web-security (1)
- # xtdb (8)
Hi, should it be possible in babashka to set a *print-length*
, so that clojure.pprint/pprint
doesn't hang on trying to print huge/infinite sequences? While it's possible to perform (set! *print-length* 10)
in usual clojure and pprint
's output gets trimmed accordingly, the same statement just prints out Can't change/establish root binding of #'clojure.core/*print-length* with set
. Is there any alternative approach to achieve "trimming" of pprint output?
user=> (alter-var-root #'*print-length* (constantly 10))
10
user=> (range)
(0 1 2 3 4 5 6 7 8 9 ...)
Not sure yet. I came to *print-length*
, because I was trying to work with a huge csv inside calva with cider-jack-in to bb repl. And calva always seemed to try to printout the whole output, no matter the pprint output is limited to something like 50 rows via calva.prettyPrintingOptions.maxLength
. When I start the clj repl instead, the output gets correctly truncated, but not with bb repl. Not sure whether that's an issue in calva or bb/sci yet. Or wheter it's an issue really or just expected behavior 🙂
regarding the alter-var-root
..
(clojure.pprint/pprint (take 50 (range)))
still prints out 50 items though. I guess that's why you asked the question whether "for REPL or running a script", right?
might be a bug in the pprint bindings. should work if it works in clj, else please post an issue
Awesome, thanks a lot! 😍 I'll try that asap. I believe this fix will help a lot with calva evaluations within bb repl. It's super annoying when the output gets stuck and sometimes one has to kill and restart the repl.
OK, a new binary will be posted in #babashka-circleci-builds and https://github.com/babashka/babashka-dev-builds once CI finishes
;; using following configuration:
;; "calva.prettyPrintingOptions": {
;; "maxDepth": 50,
;; "printEngine": "pprint",
;; "enabled": true,
;; "width": 120,
;; "maxLength": 5 <-- important setting
;; }
(set! *print-length* 5)
;; => 5 <-- no longer an warning printout, seems to work fine
(clojure.pprint/pprint (take 10 (range)))
;; (0 1 2 3 4 ...) <-- this one seems to behave ok now, nice!
(take 10 (range))
;; => (0 1 2 3 4 5 6 7 8 9) <-- still not limitting the number of results
It seems to me that calva might be using cider.nrepl.pprint
(ie https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/pprint.clj#L18-L47) for the printout of evaluated results.
the nrepl fix is a little bit more involved, I see some things about :print-length
as an option that CIDER sends, but I'd have to test this
I hope that's actually the correct assumption I made about that cider.nrepl/pprint
).
https://github.com/BetterThanTomorrow/calva/blob/d12ea27fc193aa3001dcf8658d238ed88648ce7f/src/printer.ts#L63-L70 seems to reference cider.nrepl.pprint/pprint
.
But on the other hand, when I look into that function, it seems to delegate the call to clojure.pprint/write
. So effectively something it probably executes something like this ... which already works even on current bb
(0.8.1).
(apply clojure.pprint/write (take 10 (range)) (mapcat identity {:stream nil
:length 5}))
So perhaps calva is printing that using even some other way, don't know.This is what I'm getting from CIDER:
:msg {"nrepl.middleware.print/options" {"right-margin" 80}, "id" #object["[B" 0x17a0eed9 "[[email protected]"], "nrepl.middleware.print/buffer-size" 4096, "nrepl.middleware.print/stream?" #object["[B" 0x24ffa64c "[[email protected]"], "nrepl.middleware.print/quota" 1048576, "line" 2, "column" 1, "file" #object["[B" 0x494f56c9 "[[email protected]"], "op" #object["[B" 0x2d59adc6 "[[email protected]"], "session" #object["[B" 0x1c97c1d6 "[[email protected]"], "code" #object["[B" 0xdd07349 "[[email protected]"], "nrepl.middleware.print/print" #object["[B" 0x96abd9a "[[email protected]"], "ns" #object["[B" 0x7b6ed293 "[[email protected]"]}
More readable:
:msg {:nrepl.middleware.print/buffer-size 4096, :ns "user", :file "/tmp/dude.clj", :nrepl.middleware.print/quota 1048576, :nrepl.middleware.print/print "cider.nrepl.pprint/pprint", :op :eval, :column 1, :line 2, :id "83", :code "(binding [*print-length* 20]\n (range 20))", :nrepl.middleware.print/stream? "1", :nrepl.middleware.print/options {"right-margin" 80}, :session "ad04d342-2974-48e2-95f2-4
After alter-var-root of print-length:
:msg {:nrepl.middleware.print/buffer-size 4096, :ns "user", :file "/tmp/dude.clj", :nrepl.middleware.print/quota 1048576, :nrepl.middleware.print/print "cider.nrepl.pprint/pprint", :op :eval, :column 1, :line 3, :id "107", :code "(binding [*print-length* 20]\n (range 20))", :nrepl.middleware.print/stream? "1", :nrepl.middleware.print/options {"right-margin" 80}, :session "ad04d342-2974-48e2-95f2-
From Calva I get:
:msg {:file "/private/tmp/dude.clj", :nrepl.middleware.print/print "cider.nrepl.pprint/pprint", :op :eval, :column 1, :line 5, :id "29", :code "(range 20)", :stderr {}, :pprint 1, :stdout {}, :nrepl.middleware.print/options {"right-margin" 120, "length" 50, "level" 10}, :session "f044f468-0367-4f8b-9f21-7b3790566066"}
c
strange.. "length" 50
in that last output seems to be what shall get passed to clojure.pprint/write
here https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/pprint.clj#L47
did you have to change anything?
I don't get it.. if those options in you last snippet ^^^ get correctly passed to that cider.nrepl.pprint/pprint
, it effectively turns into something like this, doesn't it?
(apply clojure.pprint/write (take 10 (range)) '(:right-margin 120 :length 5 :level 10 :stream nil))
;; => "(0 1 2 3 4 ...)"
And this already works OOTB to me.(I just modified length to 5, not 50)
so I added this:
(let [{:strs [right-margin length level]} (get msg :nrepl.middleware.print/options)]
(binding [*print-length* length
*print-level* level
clojure.pprint/*print-right-margin* right-margin]
(with-out-str (pprint-fn v))))
seems like a way to go :thumbsup:
Just checked the lastest built master. Yes, it works just great now, excelent job!
Thanks a lot. I'm wondering.. did this affact only Calva, or even other editors which are using cider nrepl?
Yeah, Calva doesn't do anything fancy here. Happy to learn that bb.nrepl supports the pprint pretty printer!
And I can confirm that it's a game changer. It's just so nice when your editor doesn't get stuck trying to printout 200k items parsed off a huge csv file and instead just prints a few.
Not to mention infinite seqs.
Hi,
I am following the example from dainiusjocas/babashka-lambda
and am using a bb.edn
with pods
.
Within my docker image, I am building an uberjar and I would like to include pods in the final zip file (package for aws lambda)
Where can I find the pods within the Docker image? or is there a way to tell bb to load the pod into a given directory?
@U440E3Q0K Pods are installed in ~/.babashka/pods
you can see a recent discussion about that here: https://clojurians.slack.com/archives/CLX41ASCS/p1649668142673779
So when I included the pod in my zip file and bootstrap with the command:
./bb --config bb-local-pods.edn -jar lambda.jar -m lambda.core
where bb-local-pods.edn
contains:
{:pods {org.babashka/aws {:path "./pod-babashka-aws"}}}
and the full contents of my zip are:
bb
bb-local-pods.edn
bootstrap
lambda.jar
pod-babashka-aws
I now encounter the error:
Exception in thread "main" java.io.FileNotFoundException: /var/task/.babashka/pod-babashka-aws.metadata.cache (No such file or directory)
FWIW i got it to work by turning namespace caching off with
{:path "./pod-babashka-aws"
:cache false}
This may be a bug as caching should work. /cc @U06FS3DLH . Perhaps a mkdir -p like bug
Perhaps you can create the parent directory of that cache file and see if that works
Seems likely that it's a read-only file system then?
@U440E3Q0K take a look at #holy-lambda - it has a solution for that