Fork me on GitHub
#babashka
<
2019-11-27
>
borkdude13:11:43

this is a better foundation for including a sci or babashka version of clojure.spec

borkdude14:11:07

@holyjak I'm looking at your nio example now:

(do
  (.createNewFile (io/file "/tmp/f1"))
  (let [p (.toPath (io/file "/tmp/f1"))
        p' (.resolveSibling p "f2")]
    #_(try
      (java.nio.file.Files/move p p' (into-array java.nio.file.CopyOption []))
      (println "Target file did not exist and move succeeded")
      (catch java.nio.file.FileAlreadyExistsException _
        (println "Target file already exists, going to force it...")
        (java.nio.file.Files/move p p' (into-array [java.nio.file.StandardCopyOption/REPLACE_EXISTING]))))))
This works:
$ lein bb /tmp/nio.clj
But for the native one I get:
$ ./bb /tmp/nio.clj
Can't call public method of non-public class: public final java.nio.file.Path sun.nio.fs.AbstractPath.resolveSibling(java.lang.String) [at line 4, column 12]

borkdude14:11:12

Not sure yet

borkdude14:11:26

This might be a bug in graal?

borkdude15:11:45

ah it now works using a reflection config, phew

bananadance 4
Jakub Holý (HolyJak)15:11:35

so the class only wasn't public b/c it wasn't exposed by SCI, not per-se?

borkdude15:11:38

well, I had to add a config for:

{
    "name":"java.nio.file.Path",
    "allPublicMethods":true
  }

👍 4
borkdude15:11:12

but I added a config for the concrete class sun.nio.fs.UnixPath which didn't work

borkdude15:11:30

it seems I need to add them both

sogaiu15:11:18

i guess there is no way for a semi-automated generation of this info...

borkdude15:11:56

right now I'm adding stuff to reflection.json manually, but I think I will move to a generation script at some point, because JSON...

borkdude15:11:07

@holyjak your script now runs!

$ ./bb /tmp/nio.clj
Target file already exists, going to force it...
#object[sun.nio.fs.UnixPath 0x636d3fb7 "/tmp/f2"]

borkdude15:11:21

I'll push a branch and link you a binary

borkdude15:11:45

linux: https://1968-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.36-SNAPSHOT-linux-amd64.zip mac: https://1967-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.36-SNAPSHOT-macos-amd64.zip test script:

(do
  (.createNewFile (io/file "/tmp/f1"))
  (let [p (.toPath (io/file "/tmp/f1"))
        p' (.resolveSibling p "f2")]
    (try
      (java.nio.file.Files/move p p' (into-array java.nio.file.CopyOption []))
      (println "Target file did not exist and move succeeded")
      (catch java.nio.file.FileAlreadyExistsException _
        (println "Target file already exists, going to force it...")
        (java.nio.file.Files/move p p' (into-array [java.nio.file.StandardCopyOption/REPLACE_EXISTING]))))))

borkdude16:11:33

New mac version, (dotimes was broken in sci): https://1971-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.36-SNAPSHOT-macos-amd64.zip Test script:

(let [f (.File/createTempFile "foo" "bar")
      p (.toPath (io/file f))
      p' (.resolveSibling p "f2")]
  (.delete (.toFile p'))
  (dotimes [_ 2]
    (try
      (java.nio.file.Files/copy p p' (into-array java.nio.file.CopyOption []))
      (println "Target file did not exist and move succeeded")
      (catch java.nio.file.FileAlreadyExistsException _
        (println "Target file already exists, going to force it...")
        (java.nio.file.Files/copy p p' (into-array [java.nio.file.StandardCopyOption/REPLACE_EXISTING]))))))

$ ./bb /tmp/nio.clj
Target file did not exist and move succeeded
Target file already exists, going to force it...

👍 4
borkdude16:11:40

@holyjak Added to master. If you need support for more classes like LinkOption or whatever, feel free to add PRs. You can take this commit as an example: https://github.com/borkdude/babashka/commit/1885c452551a57ee1cffa88701a0500d427db365

👍 4
❤️ 4
borkdude16:11:10

I'll release a new version since dotimes was broken.

borkdude17:11:59

bb v0.0.38 now also released, adds clojure.walk and an example of a portable tree command: https://github.com/borkdude/babashka/blob/master/README.md#portable-tree-command

borkdude17:11:20

Pretty happy that this example "just worked" almost out of the box 🙂

4
nate17:11:16

@borkdude would you be amenable to the addition of clj-time to babashka? I have some millis in my data that could use a human format. I'd be willing to do the work for addition, just curious if it "fits"

borkdude17:11:54

that would be interesting, although I've been told that the new java time API pretty much replaces the need for it, so it might be better to add support for that instead?

borkdude17:11:37

I'll take a look, have to make dinner now, but I like the idea, so feel free to experiment

nate17:11:33

Cool. Sounds good.

borkdude21:11:02

Aggregate size of dir:

#!/usr/bin/env bb

(as-> (io/file (or (first *command-line-args*) ".")) $
  (file-seq $)
  (map #(.length %) $)
  (reduce + $)
  (/ $ (* 1024 1024))
  (println (int $) "mb"))

$ dir-size
130 mb

$ dir-size ~/Dropbox/bin
233 mb

borkdude22:11:07

Seems useful:

4
nate22:11:13

Super useful!

sogaiu22:11:02

will jet get color?

borkdude22:11:51

@sogaiu I guess it could, maybe using puget which uses fipp and jet also uses fipp. PR experiment welcome. Not sure how to deal with JSON coloring

borkdude22:11:08

but maybe that's not as important as EDN coloring 🙂

borkdude22:11:36

(@lee just told me he used puget for something)

sogaiu22:11:52

i guess it might be easier if some other tool can just add the color afterwards

borkdude22:11:25

I usually pipe something to a file and then open it in emacs for further inspection

borkdude22:11:29

and that adds the colors

sogaiu22:11:45

yeah, i use zprint-mode sometimes

sogaiu22:11:45

may be there's a nice way to use jet from inside emacs to get some nice history ability plus possibly some coloring

sogaiu22:11:17

i think comint can be taught to use certain syntax highlighting

lread22:11:00

like you two, I don't miss color for jet, --pretty to file then open in editor is fine by me.

lread22:11:26

puget is used by koacha's deep-diff, makes sense there for highlighting expected vs actual

sogaiu22:11:40

i think color is nice when you're looking at things in a flat view -- e.g. editors, but if you are using something like rebl, may be it's not so important?

sogaiu22:11:08

it turns out there is this undocumented feature in rebl (unsupported as well i guess), where you can get it to effectively receive certain sorts of things over the network -- so if the data in question is edn, we can send stuff from jet to rebl for viewing

borkdude22:11:52

I was confronted with this because https://github.com/borkdude/cljtree-graalvm had a colorize option. When I ported the script to babashka, it didn't support it 🙂 https://github.com/borkdude/babashka/blob/master/README.md#portable-tree-command

sogaiu22:11:30

well ofc you need color then!

borkdude22:11:10

yes, color and pprint were the two missing things. I will go for fipp for pprinting since I still can't get clojure.pprint to play nice with graalvm

sogaiu22:11:22

darn locking!

borkdude22:11:17

might be worth a chat in the native channel

borkdude22:11:25

but getting late here, so won't go there now

sogaiu22:11:33

hmm, when i tested lvh's statement the other day about not needing to patch clojure with the latest native-image, it was pprint that set off the monitor stuff

borkdude22:11:32

I think I had something working with --report-unsupported-elements-at-runtime

borkdude22:11:41

I can't remember exactly anymore

borkdude22:11:53

but so far I've been able to avoid that option

lread22:11:52

there might be indirect locking happening in pprint but there also seem to be other issues.

sogaiu22:11:10

everything is multicausal 🙂

lread22:11:30

and intertwingled

🙂 8