Fork me on GitHub
#babashka
<
2022-05-27
>
pinkfrog00:05:57

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.

Bob B01:05:50

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.

borkdude06:05:12

No, this should work, I'll take a look in an hour

borkdude06:05:28

Both shell and Clojure are synchronous in tasks

borkdude07:05:05

@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

borkdude07:05:28

{:tasks
 ;; see 
 {test (clojure "-M:test")}}

pinkfrog08:05:32

Cool. I was using the one from deps.

teodorlu12:05:49

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-file

1
teodorlu12:05:51

I 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------".
>

teodorlu12:05:39

This seems to do what I want:

(fs/create-file watch-file {:posix-file-permissions "rwxr-xr-x"})

teodorlu12:05:19

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.

teodorlu12:05:37

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

borkdude12:05:21

This is just java.nio, not some format that fs has decided on

👍 1
borkdude13:05:05

I feel adding this to babashka.fs and every babashka.* library would take that into account would not be unreasonable

ordnungswidrig14:05:36

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:

borkdude14:05:54

yeah, I think it would be less confusing if the scope of cwd was limited to only the babashka managed libs

ordnungswidrig14:05:13

babashka.cwd/*cwd*
` Will that be an atom?

borkdude14:05:48

no, a dynamic var since you don't want to change the cwd of another thread, I think?

ordnungswidrig14:05:55

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?

ordnungswidrig14:05:27

Maybe dynvar holding an atom?

borkdude14:05:02

(set! *cwd* "foo")

ordnungswidrig14:05:29

:man-facepalming: I totally forgot about that. I'm using it so seldomly.

borkdude14:05:56

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

borkdude14:05:22

Maybe we should ask clojure for such a dynvar :)

ordnungswidrig14:05:42

hehe, a single wrapping binding is a cheap price to pay.

borkdude14:05:13

Yeah:

(binding [*cwd* *cwd*] (your-program))

ordnungswidrig14:05:32

Ok, now replace all the posix and gnu tools by edn-driven alternatives for proper threading 🙂

😄 1
borkdude14:05:38

With panama around the corner, we could wait for that maybe

ordnungswidrig14:05:26

(->> (find {:file-glob "*.clj" :max-depth 5 :ignore-path-glob "*/target/*"}) (map #(grep %1 "FIXME")))

borkdude14:05:00

(fs/glob "." "*.clj" {:max-depth 5})
already works :)