Fork me on GitHub
#babashka
<
2022-11-01
>
borkdude12:11:25

New #babashka release! 1.0.165 (2022-11-01) • Fix https://github.com/babashka/babashka/issues/1401: mutation of deftype field should be visible in protocol method • Fix https://github.com/babashka/babashka/issues/1405: drop name metadata from conditionally defined var • https://github.com/babashka/babashka/issues/602: add lib tests for clj-commons/fs (https://github.com/bobisageek) • Add java.net.URLConnection class • Add java.time.zone.ZoneRules class • Copy more docstrings for core macros and vars • Bump core.async to 1.6.673 • Implement in-ns as function, rather than special form (@SignSpice) • Bump deps.clj to 1.11.1.1182 • Bump GraalVM to 22.3.0 • SCI: don't rely on metadata for record implementation

🎉 5
tylerw21:11:41

I’m sure this has come up before but my search-fu is not yielding an answer. I have a ~/bb directory which is quickly amassing general purpose scripts (which I used to use bash or python for). Each script has an “(ns name-of-script …)” form at the start and the (when (= *file* ... snippet at the end. I would like to reuse helper functions defined in these scripts, but for some reason I am not able to (require) any scripts without first running (load-file "name-of-script.clj"). I have a bb.edn in there with {:paths ["."]} but that doesn’t help. Any ideas?

borkdude22:11:14

It might help if you add the parent directory of the script to the classpath:

(babashka.classpath/add-classpath (str (fs/parent *file*)))

borkdude22:11:43

or you can treat your util functions as a library, by using (babashka.deps/add-deps '{:deps {utils/utils {:local/root "/Users/foo/bb/utils"}}})

borkdude22:11:17

The bb.edn is only valid for the working directory you invoke the script from

borkdude22:11:33

Unless you use bb --config some-other-bb.edn

tylerw22:11:39

Creating a util library and using add-deps definitely works 👍

tylerw22:11:28

Couldn’t get the classpath manipulation working (I had tried various combinations of adding the current and parent dirs before as well), but not a big deal

tylerw22:11:30

Thanks!

👍 1