Fork me on GitHub
#babashka
<
2022-04-14
>
Nom Nom Mousse07:04:21

I have a bb script in a Clojure project. Is there a standard place to put it?

Nom Nom Mousse07:04:52

<myproject>/src/... ?

Nom Nom Mousse07:04:08

I'd like users to be able to use it from the command line. (The script sends messages to a running program, modifying the program's behavior).

borkdude07:04:10

@endrebak I usually use <myproject>/bb/foo.clj now

🙏 1
borkdude07:04:02

and then bb.edn :

{:paths ["bb"]
 :tasks {foo foo/bar}
}
for example

Nom Nom Mousse07:04:46

In Cursive I cannot mark it as a bb script unless it is in the class path it seems. Will request that feature

Nom Nom Mousse07:04:58

Ah, does that :tasks make it runnable as foo from the command line? Will read the docs.

borkdude07:04:13

if you use :paths ["bb"] then it's on the bb classpath and indeed

borkdude07:04:32

also bb -m foo/bar works, without tasks

Nom Nom Mousse07:04:24

Hmm, I'd just like to run it as foo <cmd line opts>. Perhaps I need to invoke the bb script from a shell script?

borkdude07:04:19

if you don't mind typing bb foo <cmd line opts> then the above task usage does it

🙏 1
borkdude07:04:56

or you can use a shebang #!/usr/bin/env bb

Nom Nom Mousse07:04:24

My preferred library for debugging is https://github.com/weavejester/hashp Is this something you'd consider adding to babashka?

👀 1
borkdude08:04:26

You can probably run this as a dependency. Afk for a bit but I'll check later

🙏 1
borkdude09:04:45

It seems hashp is not going to work, since it seems to depend on deps that are not going to run with bb:

clojure.core.rrb-vector.nodes - clojure/core/rrb_vector/nodes.clj:11:3
clojure.core.rrb-vector       - clojure/core/rrb_vector.clj:43:3
fipp.deque                    - fipp/deque.cljc:4:3
fipp.engine                   - fipp/engine.cljc:4:3
puget.printer                 - puget/printer.clj:94:3

borkdude09:04:12

it's probably not too hard to write a simplified bb-compatible version of this which just uses pprint

borkdude09:04:57

There is also taoensso.timbre/spy in bb

borkdude09:04:12

$ bb -e '(taoensso.timbre/spy 1)'
2022-04-14T09:50:06.718Z m1.local DEBUG [user:1] - 1 => 1
1

🙏 1
Nom Nom Mousse14:04:07

Can puget be required in a babashka script?

borkdude14:04:20

Have you tried?

borkdude14:04:17

I expect it not to work since it depends on fipp and there's some things in fipp that don't work in bb (deftype), I think

borkdude14:04:24

but worth a try to see if what I think is correct

borkdude14:04:37

I have a CLI version of puget here: https://github.com/borkdude/puget-cli

borkdude14:04:49

you can pipe EDN into it and it will do puget stuff

borkdude19:04:57

Actually I'm now looking into making fipp compatible with bb and it looks like that might actually work with some changes

borkdude19:04:04

Tweaking fipp + puget a bit and it seems they can be made to work from source (hopefully the authors will cooperate). More info here: https://github.com/babashka/babashka/issues/1241

🎉 3
nice 1
Nom Nom Mousse05:04:36

Cool! I had tried and it did not work with a simple require. I should have written that!

Nom Nom Mousse05:04:05

Color can be so helpful when you have complex data to display

Benjamin19:04:34

I guess it's way to special without a simple repro but

java.util.zip.ZipException: invalid entry CRC (expected 0xbe1ee0ab but got 0xc113eb74)
 at java.util.zip.ZipInputStream.readEnd (ZipInputStream.java:410)

(defn
  unzip
  [zip-file destination]
  (with-open
    [xin
     (io/input-stream zip-file)
     ^ZipInputStream zip (ZipInputStream. xin)]
    (loop
        [ze (.getNextEntry zip)]
        (when
            ze
            (let [f (io/file
                     destination
                     (.getName ze))]
              (io/make-parents f)
              (io/copy zip f)
              (.closeEntry zip)
              (recur (.getNextEntry zip)))))))
any idea? for some reason it works on jvm. It also usually works, but I found a zip that throws. Can't really share the zip file that is causing it rn, it's sensitive, but I'll try to find a simple repro

1
borkdude19:04:24

Is this with a self-compiled binary?

Benjamin19:04:58

no its 0.7.8

borkdude19:04:10

can you try unzip from babashka.fs?

borkdude19:04:04

Tweaking fipp + puget a bit and it seems they can be made to work from source (hopefully the authors will cooperate). More info here: https://github.com/babashka/babashka/issues/1241

🎉 3
nice 1
borkdude20:04:05

Btw, zprint already works with bb:

(ns zprint
  (:require [babashka.deps :as deps]))

(deps/add-deps '{:deps {org.babashka/spec.alpha {:git/url ""
                                                 :git/sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"}
                        zprint/zprint {:mvn/version "1.2.3"}}})

(require '[zprint.core :as zp])

(println (zp/zprint-file-str (slurp *file*) "yolo" {:color? true :style :dark-color-map}))

🙏 1
rads00:08:26

FYI, it looks like this broke with 1.2.4 . Created an issue: https://github.com/kkinnear/zprint/issues/253

borkdude02:08:57

This was fixed in master I believe. Can you test with the master version?

borkdude02:08:19

Of bb. It had to do with upgrading rewrite-clj

borkdude19:08:10

The author just contacted me and he already tested it

rads20:08:10

Awesome 🙂