Fork me on GitHub
#babashka
<
2023-07-06
>
dev-hartmann15:07:15

hey fellow babashka folks, quick question that came up today: image I have a folder lib in my repo that bundles a lot of general use stuff like git.clj, docker.clj etc. If I was to write a script in another folder somewhere, what would be the smartest way to include that? deps.edn with {:local/root "../lib/git.clj}, or if i just had a script with a shebang it would be babashka.deps/add-deps and then require?

rads15:07:49

You can put your shared code in a folder with a deps.edn and use it as a library with another deps.edn or add-deps. Same approach as a regular Clojure library

rads15:07:38

So it would be {:local/root "../lib"} without the .clj in the script or project that needs it. And you can use a Git dep if you want to share the code more broadly

rads15:07:37

Glad I could help

❤️ 2
vlad_poh18:07:16

I’m using VSCode + calva and using babashka in the jack-in sequence. How do i specify the default name space? it currently goes to clj.user

borkdude18:07:41

This might be more a #CBE668G4R question

isak18:07:34

This may be related. I had the same question, though not for babashka: https://clojurians.slack.com/archives/C6QH853H8/p1688079148764219

👍 1
pez18:07:53

Calva defaults to user. Maybe the prompts looks like clj.user? When in user the prompt is rendered as clj:user:>, where clj indicates that it is a Clojure repl. Calva actually think it is a Clojure repl. There is no concept of anything else than Clojure or ClojureScript repl in Calva. We should probably fix that. But at least Babashka is very Clojure-y 😃

pez19:07:07

To make it start in some particular namespace you can use a https://calva.io/connect-sequences/ and configure afterCLJReplJackInCode, alternatively customJackInCommandLine. In both cases the thread that @U08JKUHA9 pointed at contains clues. I’m not sure if Babashka kan be started such that it both evaluates some expression and starts an nREPL server, but it probably can. If it can’t, then afterCLJReplJackInCode is the way to go.

👍 1
vlad_poh19:07:17

Thanks all. "afterCLJReplJackInCode": "(use 'mynamespace)" worked!

borkdude19:07:33

use does not switch to that namespace, it only refers all vers into the current namespace. To switch, you write: (do (require 'mynamespace) (in-ns 'mynamespace))

vlad_poh19:07:57

Yep noticed it after i posted. My script launches a small web app and i got excited when just jacking in brought it up immediately. Next question for you is when i do bb script.clj the app starts and dies immediately unless i have @(promise) at the end. when i add the babashka.file check both modes work without issue but building an uberjar and running bb uberjar ends immediately as the babashka.file property is not available. any other property i can use that would handle those 2 scenarios? This question is not very clear :rolling_on_the_floor_laughing:

borkdude19:07:23

My recommendation is to write a -main function and launch using bb -m main-ns/main-func

borkdude19:07:40

and then use bb uberjar the-jar.jar -m main-ns/main-func

vlad_poh20:07:05

ooo that works for all 3 scenarios. Thanks!!

vlad_poh20:07:27

just to make sure i understood correctly i have 2 fxns kmain and main main is just (do (kmain) @(promise)) For repl driven stuff i call kmain only. for bb scricpt or bb uberjar i call the later