This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-27
Channels
- # announcements (3)
- # babashka (35)
- # babashka-sci-dev (42)
- # beginners (27)
- # calva (7)
- # clj-kondo (18)
- # cljs-dev (1)
- # clojure (40)
- # clojure-europe (141)
- # clojure-nl (1)
- # clojure-norway (6)
- # clojure-uk (40)
- # clojurescript (15)
- # community-development (4)
- # cursive (54)
- # events (1)
- # fulcro (8)
- # helix (5)
- # hyperfiddle (22)
- # introduce-yourself (6)
- # jobs (3)
- # joyride (26)
- # lsp (7)
- # music (1)
- # nbb (7)
- # off-topic (28)
- # pathom (120)
- # pedestal (3)
- # podcasts (2)
- # portal (2)
- # rdf (2)
- # releases (20)
- # rewrite-clj (9)
- # shadow-cljs (26)
- # spacemacs (1)
- # sql (13)
- # vim (10)
- # xtdb (63)
Wonder what part goes from for this bb task. In the bb.edn, I have
{:tasks
;; see
{:requires ([babashka.deps :refer [clojure]])
test (clojure ["-M:test"])}}
and in the deps.edn
file, I have
:aliases
{:test
{:main-opts ["-e" "(prn 3)"]}}
Running on the command line with
clojure -M:test
indeed gives output 3.
But nothings happens with bb test
. The process just quits without any output.My guess is that because the clojure function uses process, it's called in a future, and if that's the only thing to be run, then bb exits before the clojure run finishes. I took your repro and thread-firsted the clojure call to deref, and it printed the output.
@UGC0NEP4Y @U013JFLRFS8 Oh I see. Pinkfrog was using clojure
from babashka.deps
, yeah that one is asynchronous. So you have to write (deref (clojure ...))
there. But you can also use clojure
from babashka.tasks
which is already available in bb.edn
without a require
and that one works probably like you expect
Hey!
How can I set file permissions with babashka.fs/create-file
?
This is what I tried:
(fs/create-file watch-file {:posix-file-permissions "777"})
;; error: invalid mode
(fs/create-file watch-file {:posix-file-permissions "+x"})
;; error: invalid mode
create-file implementation pasted below. Perhaps we can add a bit of help to the docstring.
(defn create-file
"Creates empty file using Files#createFile."
([path]
(create-file path nil))
([path {:keys [:posix-file-permissions]}]
(let [attrs (posix->attrs posix-file-permissions)]
(Files/createFile (as-path path) attrs))))
var docs: https://babashka.org/fs/codox/babashka.fs.html#var-create-fileI think I found something in another docstring: >
- (create-temp-dir {:keys [:prefix :suffix :path :posix-file-permissions]}): create
> temp file in path with prefix. If prefix and suffix are not
> provided, random ones are generated. The :posix-file-permissions
> option is a string like "rwx------".
> This seems to do what I want:
(fs/create-file watch-file {:posix-file-permissions "rwxr-xr-x"})
I noticed that posix-file-permissions
is used a lot in different places (18 matches in HTML page).
So adding complete docs to every function docstring is perhaps not a good solution.
I was also a bit surprised by ls -l
output gave me a permission string that was different from what the create-file
accepted.
create-file: rwxr-xr-x
ls -l: -rwxr-xr-x
I feel adding this to babashka.fs
and every babashka.*
library would take that into account would not be unreasonable
Depends on how far babashka should deviate from core clojure / jvm. If io/file
in babashka considers the cwd people might expect the same from clojure. :thinking_face:
yeah, I think it would be less confusing if the scope of cwd was limited to only the babashka managed libs
babashka.cwd/*cwd*
`
Will that be an atom?no, a dynamic var since you don't want to change the cwd of another thread, I think?
Ideally yes. But thinking of the shell example you want the "new cwd" to persist. So bring your own atom and binding
on each call to fs/xxx
?
Maybe dynvar holding an atom?
:man-facepalming: I totally forgot about that. I'm using it so seldomly.
But that only works within a binding :) Babashka can make that work, but on the JVM, you'd need to run your main function within a binding of that
hehe, a single wrapping binding
is a cheap price to pay.
Ok, now replace all the posix and gnu tools by edn-driven alternatives for proper threading 🙂
(->> (find {:file-glob "*.clj" :max-depth 5 :ignore-path-glob "*/target/*"}) (map #(grep %1 "FIXME")))
"panama"?