This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-21
Channels
- # adventofcode (47)
- # aleph (18)
- # announcements (20)
- # babashka (81)
- # beginners (23)
- # biff (6)
- # calva (5)
- # cider (50)
- # clojure (34)
- # clojure-europe (19)
- # clojure-norway (11)
- # clojure-spec (6)
- # clojure-uk (1)
- # clojurescript (2)
- # conjure (2)
- # cursive (14)
- # datomic (1)
- # humbleui (11)
- # hyperfiddle (3)
- # introduce-yourself (5)
- # joyride (1)
- # nbb (7)
- # off-topic (19)
- # podcasts-discuss (1)
- # reagent (3)
- # reitit (19)
- # releases (1)
- # ring-swagger (1)
- # shadow-cljs (29)
- # sql (6)
- # squint (56)
"Copying, moving, deleting, reading and writing files" - new howto entry https://github.com/pesterhazy/presumably/blob/master/posts/howto-babashka.md#copying-moving-deleting-reading-and-writing-files
"Working with dates and times" - another new howto entry https://github.com/pesterhazy/presumably/blob/master/posts/howto-babashka.md#working-with-dates-and-times
I wrote
> Common operations like spit
or slurp
and functions in https://github.com/babashka/fs/blob/master/API.md accept a string filename or, alternatively, an instance of java.io.File as returned by https://github.com/babashka/fs/blob/master/API.md#file-page_facing_up. So (spit "out" "xxx")
and (spit (babashka.fs/file "out") "xxx")
are interchangeable.
Is this accurate and safe?
Good work @pesterhazy
I think it would be nice to enable syntax highlight by adding clojure
to the code fence
Right, forgot it again - done
"Read standard input (stdin)" - another new one https://github.com/pesterhazy/presumably/blob/master/posts/howto-babashka.md#read-standard-input-stdin inspired by @arturdumchev’s question above
@pesterhazy Were you going to announce this somewhere? I'd want to share it on social media, but if you'd rather wait, then I'll wait as well
Ok, managed to find my AWS credentials and uploaded the post to my blog https://presumably.de/how-to-do-things-with-babashka.html
I think it would be great to share it on social media! I think there's enough stuff there to be useful now
@pesterhazy I shared it on twitter and this will also go to my mastodon: https://twitter.com/borkdude/status/1605591648875864064
@pesterhazy There's a small error here:
["cat" "/etc/hosts"]
This shouldn't be wrapped in a vectorDo you mean this line? It doesn't work without the []
(it's using process
, not shell
) https://github.com/pesterhazy/presumably/blob/master/posts/howto-babashka.md?plain=1#L102
About the destroy-tree call, I guess I was cargo-culting by copying it from the docs without thinking too much about it https://github.com/babashka/process#processing-streaming-output Basically you're saying it's needed only when you don't consume the entire process input - like when the process never stops?
To be clear, this doesn't work for me
(require '[babashka.process :refer [process]]
'[ :as io])
(let [stream (process {:err :inherit} "cat" "/etc/hosts")]
(with-open [rdr (io/reader (:out stream))]
(doseq [line (line-seq rdr)]
(println (str "#" line))))
nil)
----- Error --------------------------------------------------------------------
Type: java.lang.ClassCastException
Message: java.lang.Character cannot be cast to java.util.Map$Entry
Location: /Users/user/arena/bin/scrapbb:6:14
% bb --version
babashka v1.0.165
Hm, I updated to 1.0.168
Now "cat" "/etc/hosts"
works.
But ["cat" "/etc/hosts"]
doesn't work anymore - is this a breaking change?
I'm pretty sure I got this way of using it from the docs (at the time)
No, this is not a breaking change, (process {} ["foo"])
was never supposed to work, the first map should have been a process that you piped into the next process. The documented API was: (process ["foo"] {?opts})
You can check the docs of the previous version if you don't believe me ;) https://github.com/babashka/process/tree/ff4085c4dc571966a2bfa239b778de5e08b76aaf
I believe you! What I didn't get was that I misplaced the options map
OK, I fixed all usage of babashka.process/process and babashka.process/sh to use the new style (`opts? arg1 arg2 ....`) https://presumably.de/how-to-do-things-with-babashka.html?cb=1#read-command-output-line-by-line
Also added this note > Note: this example requires babashka v1.0.168 or higher.
I posted a link to HN with the title "How to Babashka (Clojure vs. Bash)" (I think mentioning bash and Clojure in the title will get more views and "things" is a word which could be left out imo)
Check out "How to do things with babashka" by @pesterhazy! A good intro with examples of how to do bash things in babashka ! https://presumably.de/how-to-do-things-with-babashka.html
About the destroy-tree call, I guess I was cargo-culting by copying it from the docs without thinking too much about it https://github.com/babashka/process#processing-streaming-output Basically you're saying it's needed only when you don't consume the entire process input - like when the process never stops?
Just for managing expectations on my side: in emacs+eglot+clojure-lsp, should I be able to see docs and jump-to-definition for babashka-bundled vars like babashka.process/process?
LSP does give me jump-to-definition for vars in my own namespace, so it's working that far
Not jump to definition since there isn't any source to jump to, but there will be analysis available for built-ins, so you will see arity warnings, docstrings, etc probably
Lemme try that again
OK, so my mini-project looks like this
% cat bb.edn
{:paths ["bb"]}
% cat src/scrap.clj
#!/usr/bin/env bb
(require '[babashka.process :refer [sh]])
(def myname (:out (sh "whoami")))
(print myname)
Now if I move the point to sh
and jump to definition, I get "No definitions found"
Ah, yes 🙂 But it doesn't change anything
Could you check what is the classpath clojure-lsp is finding? In emacs there is the lsp-clojure-server-info command
Any idea on how to do that with eglot, which is what I'm using?
Or from the command line perhaps
Not possible with eglot AFAIK as this is a custom request. you can check server logs though
Ok, I'm looking at the server log now. Is this what you mean?
2022-12-21T22:42:32.502Z INFO [clojure-lsp.source-paths:85] - [Startup] Using source-paths from classpath: ["/Users/user/arena/scrap/src"]
Almost, we need the classpath string, but it's probably using the cached classpath so it won't show on these logs, but if you delete .lsp/.cache it should show
2022-12-21T22:47:02.910Z INFO [clojure-lsp.classpath:103] - Finding classpath via `/Users/user/arena/bin/bb print-deps --format classpath`
2022-12-21T22:47:03.364Z DEBUG [clojure-lsp.classpath:115] - Classpath found, paths: ["src" "/Users/user/.gitlibs/libs/babashka/babashka.core/52a6037bd4b632bffffb04394fb4efd0cdab6b1e/src" "/Users/user/.m2/repository/babashka/babashka.curl/0.1.1/babashka.curl-0.1.1.jar" "/Users/user/.m2/repository/babashka/fs/0.1.2/fs-0.1.2.jar" "/Users/user/.m2/repository/cheshire/cheshire/5.11.0/cheshire-5.11.0.jar" "/Users/user/.m2/repository/clj-commons/clj-yaml/0.7.169/clj-yaml-0.7.169.jar" "/Users/user/.m2/repository/com/cognitect/transit-clj/1.0.329/transit-clj-1.0.329.jar" "/Users/user/.m2/repository/com/taoensso/timbre/6.0.1/timbre-6.0.1.jar" "/Users/user/.m2/repository/hiccup/hiccup/2.0.0-alpha2/hiccup-2.0.0-alpha2.jar" "/Users/user/.m2/repository/http-kit/http-kit/2.6.0-RC1/http-kit-2.6.0-RC1.jar" "/Users/user/.m2/repository/insn/insn/0.5.2/insn-0.5.2.jar" "/Users/user/.m2/repository/nrepl/bencode/1.1.0/bencode-1.1.0.jar" "/Users/user/.m2/repository/org/babashka/babashka.impl.reify/0.1.3/babashka.impl.reify-0.1.3.jar" "/Users/user/.m2/repository/org/babashka/cli/0.5.40/cli-0.5.40.jar" "/Users/user/.m2/repository/org/babashka/sci.impl.types/0.0.2/sci.impl.types-0.0.2.jar" "/Users/user/.m2/repository/org/clojure/clojure/1.11.1/clojure-1.11.1.jar" "/Users/user/.m2/repository/org/clojure/core.async/1.6.673/core.async-1.6.673.jar" "/Users/user/.m2/repository/org/clojure/core.match/1.0.0/core.match-1.0.0.jar" "/Users/user/.m2/repository/org/clojure/core.rrb-vector/0.1.2/core.rrb-vector-0.1.2.jar" "/Users/user/.m2/repository/org/clojure/data.csv/1.0.0/data.csv-1.0.0.jar" "/Users/user/.m2/repository/org/clojure/data.priority-map/1.1.0/data.priority-map-1.1.0.jar" "/Users/user/.m2/repository/org/clojure/data.xml/0.2.0-alpha8/data.xml-0.2.0-alpha8.jar" "/Users/user/.m2/repository/org/clojure/test.check/1.1.1/test.check-1.1.1.jar" "/Users/user/.m2/repository/org/clojure/tools.cli/1.0.214/tools.cli-1.0.214.jar" "/Users/user/.m2/repository/org/clojure/tools.logging/1.1.0/tools.logging-1.1.0.jar" "/Users/user/.m2/repository/rewrite-clj/rewrite-clj/1.1.45/rewrite-clj-1.1.45.jar" "/Users/user/.m2/repository/selmer/selmer/1.12.50/selmer-1.12.50.jar" "/Users/user/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.13.3/jackson-core-2.13.3.jar" "/Users/user/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-cbor/2.13.3/jackson-dataformat-cbor-2.13.3.jar" "/Users/user/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-smile/2.13.3/jackson-dataformat-smile-2.13.3.jar" "/Users/user/.m2/repository/tigris/tigris/0.1.2/tigris-0.1.2.jar" "/Users/user/.m2/repository/org/flatland/ordered/1.5.9/ordered-1.5.9.jar" "/Users/user/.m2/repository/org/yaml/snakeyaml/1.33/snakeyaml-1.33.jar" "/Users/user/.m2/repository/com/cognitect/transit-java/1.0.362/transit-java-1.0.362.jar" "/Users/user/.m2/repository/com/taoensso/encore/3.31.0/encore-3.31.0.jar" "/Users/user/.m2/repository/io/aviso/pretty/1.3/pretty-1.3.jar" "/Users/user/.m2/repository/org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar" "/Users/user/.m2/repository/org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar" "/Users/user/.m2/repository/org/clojure/tools.analyzer.jvm/1.2.2/tools.analyzer.jvm-1.2.2.jar" "/Users/user/.m2/repository/org/clojure/tools.reader/1.3.6/tools.reader-1.3.6.jar" "/Users/user/.m2/repository/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar" "/Users/user/.m2/repository/org/msgpack/msgpack/0.6.12/msgpack-0.6.12.jar" "/Users/user/.m2/repository/com/taoensso/truss/1.6.0/truss-1.6.0.jar" "/Users/user/.m2/repository/org/clojure/core.memoize/1.0.253/core.memoize-1.0.253.jar" "/Users/user/.m2/repository/org/clojure/tools.analyzer/1.1.0/tools.analyzer-1.1.0.jar" "/Users/user/.m2/repository/org/ow2/asm/asm/9.2/asm-9.2.jar" "/Users/user/.m2/repository/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1.jar" "/Users/user/.m2/repository/org/javassist/javassist/3.18.1-GA/javassist-3.18.1-GA.jar" "/Users/user/.m2/repository/org/clojure/core.cache/1.0.225/core.cache-1.0.225.jar"]
2022-12-21T22:47:03.365Z INFO [clojure-lsp.source-paths:85] - [Startup] Using source-paths from classpath: ["/Users/user/arena/scrap/src"]
No, for some reason it's missing
/Users/user/arena/bin/bb print-deps --format classpath
src:/Users/user/.gitlibs/libs/babashka/babashka.core/52a6037bd4b632bffffb04394fb4efd0cdab6b1e/src:/Users/user/.m2/repository/babashka/babashka.curl/0.1.1/babashka.curl-0.1.1.jar:/Users/user/.m2/repository/babashka/fs/0.1.2/fs-0.1.2.jar:/Users/user/.m2/repository/cheshire/cheshire/5.11.0/cheshire-5.11.0.jar:/Users/user/.m2/repository/clj-commons/clj-yaml/0.7.169/clj-yaml-0.7.169.jar:/Users/user/.m2/repository/com/cognitect/transit-clj/1.0.329/transit-clj-1.0.329.jar:/Users/user/.m2/repository/com/taoensso/timbre/6.0.1/timbre-6.0.1.jar:/Users/user/.m2/repository/hiccup/hiccup/2.0.0-alpha2/hiccup-2.0.0-alpha2.jar:/Users/user/.m2/repository/http-kit/http-kit/2.6.0-RC1/http-kit-2.6.0-RC1.jar:/Users/user/.m2/repository/insn/insn/0.5.2/insn-0.5.2.jar:/Users/user/.m2/repository/nrepl/bencode/1.1.0/bencode-1.1.0.jar:/Users/user/.m2/repository/org/babashka/babashka.impl.reify/0.1.3/babashka.impl.reify-0.1.3.jar:/Users/user/.m2/repository/org/babashka/cli/0.5.40/cli-0.5.40.jar:/Users/user/.m2/repository/org/babashka/sci.impl.types/0.0.2/sci.impl.types-0.0.2.jar:/Users/user/.m2/repository/org/clojure/clojure/1.11.1/clojure-1.11.1.jar:/Users/user/.m2/repository/org/clojure/core.async/1.6.673/core.async-1.6.673.jar:/Users/user/.m2/repository/org/clojure/core.match/1.0.0/core.match-1.0.0.jar:/Users/user/.m2/repository/org/clojure/core.rrb-vector/0.1.2/core.rrb-vector-0.1.2.jar:/Users/user/.m2/repository/org/clojure/data.csv/1.0.0/data.csv-1.0.0.jar:/Users/user/.m2/repository/org/clojure/data.priority-map/1.1.0/data.priority-map-1.1.0.jar:/Users/user/.m2/repository/org/clojure/data.xml/0.2.0-alpha8/data.xml-0.2.0-alpha8.jar:/Users/user/.m2/repository/org/clojure/test.check/1.1.1/test.check-1.1.1.jar:/Users/user/.m2/repository/org/clojure/tools.cli/1.0.214/tools.cli-1.0.214.jar:/Users/user/.m2/repository/org/clojure/tools.logging/1.1.0/tools.logging-1.1.0.jar:/Users/user/.m2/repository/rewrite-clj/rewrite-clj/1.1.45/rewrite-clj-1.1.45.jar:/Users/user/.m2/repository/selmer/selmer/1.12.50/selmer-1.12.50.jar:/Users/user/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.13.3/jackson-core-2.13.3.jar:/Users/user/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-cbor/2.13.3/jackson-dataformat-cbor-2.13.3.jar:/Users/user/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-smile/2.13.3/jackson-dataformat-smile-2.13.3.jar:/Users/user/.m2/repository/tigris/tigris/0.1.2/tigris-0.1.2.jar:/Users/user/.m2/repository/org/flatland/ordered/1.5.9/ordered-1.5.9.jar:/Users/user/.m2/repository/org/yaml/snakeyaml/1.33/snakeyaml-1.33.jar:/Users/user/.m2/repository/com/cognitect/transit-java/1.0.362/transit-java-1.0.362.jar:/Users/user/.m2/repository/com/taoensso/encore/3.31.0/encore-3.31.0.jar:/Users/user/.m2/repository/io/aviso/pretty/1.3/pretty-1.3.jar:/Users/user/.m2/repository/org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar:/Users/user/.m2/repository/org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar:/Users/user/.m2/repository/org/clojure/tools.analyzer.jvm/1.2.2/tools.analyzer.jvm-1.2.2.jar:/Users/user/.m2/repository/org/clojure/tools.reader/1.3.6/tools.reader-1.3.6.jar:/Users/user/.m2/repository/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar:/Users/user/.m2/repository/org/msgpack/msgpack/0.6.12/msgpack-0.6.12.jar:/Users/user/.m2/repository/com/taoensso/truss/1.6.0/truss-1.6.0.jar:/Users/user/.m2/repository/org/clojure/core.memoize/1.0.253/core.memoize-1.0.253.jar:/Users/user/.m2/repository/org/clojure/tools.analyzer/1.1.0/tools.analyzer-1.1.0.jar:/Users/user/.m2/repository/org/ow2/asm/asm/9.2/asm-9.2.jar:/Users/user/.m2/repository/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1.jar:/Users/user/.m2/repository/org/javassist/javassist/3.18.1-GA/javassist-3.18.1-GA.jar:/Users/user/.m2/repository/org/clojure/core.cache/1.0.225/core.cache-1.0.225.jar
It uses this deps.edn for this feature and process is missing because it's a git submodule of babashka. Please make an issue about it and I'll fix it. https://github.com/babashka/babashka/blob/master/resources/META-INF/babashka/deps.edn
It still doesn't work for babashka.fs/glob (or even clojure.core/print) but that's probably a problem with my emacs/lsp, not bb
Yeah that works fine - it's only the jump-to-definition that doesn't work
I also do get docs for it
maybe this is an eglot problem with jumping to definition into jars? I've heard about this before
Yes, I think so: https://github.com/joaotavora/eglot/issues/661#issuecomment-1307610635
Tried it, but it doesn't work for me https://github.com/joaotavora/eglot/issues/661#issuecomment-1362204524
can you try it with a regular jvm project to see if you can navigate into clojure.jar?
Will try tomorrow
Alright, so it was a general eglot problem. https://clojurians.slack.com/archives/C099W16KZ/p1671706650817479