Fork me on GitHub
#babashka
<
2024-02-06
>
eval202012:02:23

I’m extending this https://book.babashka.org/#_pods_in_bb_edn like so:

(ns my-project.db
  (:require [pod.babashka.go-sqlite3 :as sqlite]
            [babashka.fs :as fs] :reload)) ;; <-- added

(defn -main [& _args]
  (prn (sqlite/query ":memory:" ["SELECT 1 + 1 AS sum"])))
Now running bb -m my-project.db fails like it does when not having the :pods {,,,} in bb.edn.

eval202012:02:05

$ bb -m my-project.db
----- Error --------------------------------------------------------------------
Type:     java.io.FileNotFoundException
Message:  Could not locate pod/babashka/go_sqlite3.bb, pod/babashka/go_sqlite3.clj or pod/babashka/go_sqlite3.cljc on classpath.
Location: /Users/gert/projects/playground/bb/pods/bb/my_project/db.clj:2:3

----- Context ------------------------------------------------------------------
1: (ns my-project.db
2:   (:require [pod.babashka.go-sqlite3 :as sqlite]
     ^--- Could not locate pod/babashka/go_sqlite3.bb, pod/babashka/go_sqlite3.clj or pod/babashka/go_sqlite3.cljc on classpath.
3:             [babashka.fs :as fs] :reload))
4:
5: (defn -main [& _args]
6:   (prn (sqlite/query ":memory:" ["SELECT 1 + 1 AS sum"])))

----- Stack trace --------------------------------------------------------------
babashka.main/exec/fn--32207/load-fn--32218 - <built-in>
my-project.db                               - /Users/gert/projects/playground/bb/pods/bb/my_project/db.clj:2:3
user                                        - <expr>:1:10

~/projects/playground/bb/pods
$ tree -C
.
├── bb
│   └── my_project
│       └── db.clj
└── bb.edn

2 directories, 2 files
without :reload it works fine. Bug?

borkdude12:02:26

No, :reload applies to all the namespaces, not only :fs

borkdude12:02:01

So it's best to separate babashka.fs in a separate require if you want to reload it

eval202012:02:25

TIL! Thanks

eval202014:02:06

What is btw the underlying reason a reload of a pod fails? Looking at the error it seems it’s not ‘really’ on the classpath(?)

borkdude14:02:19

a pod defines namespaces programmatically, not by source

eval202015:02:37

check - thanks for clarifying.

borkdude15:02:06

which update of fs did you need that wasn't in the last release ?

eval202015:02:44

I wanted to make the script more backwards compatible for older versions of bb.

eval202015:02:03

Often also just to be sure what version I have.

imre13:02:50

I found it somewhat confusing how clojure works from inside a bb task vs how deps/clojure from a bb script does: (running https://github.com/babashka/babashka/blob/68e8ac6e10c86650c191431b26c64b6966002bd7/src/babashka/deps.clj#L25)

; bb -e "(-> (deps/clojure '[-M -e (+ 1 2 3)] {:out :string}) deref :out println)"
6

; bb -Sdeps '{:tasks {example (-> (clojure \'[-M -e (+ 1 2 3)] {:out :string}) deref :out println)}}' example
WARNING: Implicit use of clojure.main with options is deprecated, use -M
Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).
[-M (No such file or directory)

Full report at:
/var/folders/sw/hg9d03hs7w50dfrhmxb4v6w00000gn/T/clojure-17864798851295072450.edn
Error while executing task: example

borkdude13:02:45

The official way of calling clojure is now:

(clojure {opts} ..args)

borkdude13:02:51

in both cases

borkdude13:02:33

if you find any documentation that suggests otherwise, please let me know

imre13:02:00

; bb -e '(-> (deps/clojure {:out :string} \'[-M -e (+ 1 2 3)]) deref :out println)'
WARNING: Implicit use of clojure.main with options is deprecated, use -M
Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).
[-M (No such file or directory)

Full report at:
/var/folders/sw/hg9d03hs7w50dfrhmxb4v6w00000gn/T/clojure-11961317677263333737.edn
It doesn't seem to work in this case

borkdude13:02:35

ok this needs to be changed then, thanks

borkdude13:02:00

the old way should still work, but is deprecated. issue about this is welcome

imre13:02:21

Sure thing

imre13:02:04

By "old way" you also mean the '[-M -e (+ 1 2 3)] part, right? That should now be passed as individual args if I see it correct

borkdude13:02:28

This is the recommended way:

$ bb -Sdeps "{:tasks {example (-> (clojure {:out :string } \"-M\" \"-e\" \"(+ 1 2 3)\") deref :out println)}}" example
6

imre13:02:49

Oh, so not even quoted symbols?

borkdude13:02:09

that works too I think

imre13:02:36

Are you okay with a PR straight away?

borkdude13:02:57

about what?

borkdude13:02:15

I mean, what's the problem statement now: docstring should be altered, or old behavior should be fixed?

imre13:02:56

I was going to suggest a doc update. Old way still works with -e. New way works from both. Mixed way (clojure {:out :string} '[-M -e (+ 1 2 3)]) doesn't work from either.

borkdude13:02:56

mixed way never worked I think, gotcha

borkdude13:02:03

ok docstring update welcome 🙏

imre13:02:34

Thank you!

👍 1
vlad_poh16:02:55

Has anyone created bb tasks to create binaries for your bb project?

Wanishing15:02:14

Not sure If I understood the question, but there's https://github.com/borkdude/jayfu which is a CLI built with graalvm and babashka

vlad_poh15:02:43

close but not quite. So @U04V15CAJ has shown you can cat the bb binary and a bb uberjar into a binary that runs. I currently do bb cmd, copy the text and run that. I would love to break that down into individual tasks {:paths ["src"] :require [[babashka.process :refer [shell process exec]]] :tasks {status (shell “git” “status”) cmd (println “bb uberjar foo.jar -m foo && cat ./bb foo.jar > foo && chmod +x ./foo && ./foo”) compile {:doc “Compile” :task (shell “bb” “uberjar” “foo.jar” “-m” “foo”)} release {:doc “Release” :task (do (shell “cat” “./bb” “foo.jar” “>” “foo”) (shell “chmod” “+x” “./foo”))} run {:doc “Run” :task (shell “./foo”)}}}