Fork me on GitHub
#babashka
<
2022-09-30
>
Adam Helins08:09:50

What would be the most idiomatic approach for adding extra paths at runtime, akin to add-deps? Use add-classpath directly?

borkdude08:09:30

@adam678 You can use add-deps with {:paths ["foo" "bar"]}

Adam Helins08:09:14

Ah yes :face_palm: Thanks

Adam Helins08:09:58

I can't seem to find a solution :thinking_face: Essentially, my BB tasks would ideally require aliases from my root deps.edn for a few reasons (e.g. not duplicating common deps, common paths, ...) However I think it's impossible to do anything about it dynamically in [:tasks :init] when using :requires in tasks, right? Because whatever :requires need won't be available yet.

borkdude08:09:58

@adam678 Does it help that individual tasks support :extra-deps ?

Adam Helins08:09:00

Unfortunately not because the quest here is being able to consume what's defined in deps.edn

Adam Helins08:09:39

In aliases, so a :local/root in bb.edn 's :deps won't do

borkdude08:09:14

You could also do this:

(classpath/add-classpath (with-out-str (clojure "-Spath" "-A:whatever")))

Adam Helins08:09:16

I don't think so, here is what happens when the :init hook in :tasksuses add-deps to add foo.bar and the task :requires it:

----- Context ------------------------------------------------------------------
1:
2:  ;; deps
3:
4: (ns user-2fd6eac7-5ec0-4e75-9211-7cd306f95634 (:require [foo.bar]))
                                                 ^--- Could not find namespace: foo.bar.
At this point, :init hasn't run yet. So any dynamic solution like add-deps or add-classpath outside of a task can't work if my understanding is correct.

borkdude08:09:32

Please provide a complete bb.edn or repo because this is confusing to me :)

Adam Helins08:09:31

Okay let me try to work it out, I'm obviously trying to do a bit of magic here, and if I'm still stuck I'll come back 🙏

borkdude08:09:23

You could also start bb like this:

bb --classpath $(clojure -Spath -A:whatever) 
but this will ignore any deps in bb.edn

Adam Helins08:09:56

Something like this would probably be more reliable. I'd find it interesting having a add-deps variant that work with a path to a deps.edn file. Keeping that optional second argument for activating aliases.

Adam Helins09:09:03

Eh, eventually I settled for a hack. In bb.edn I simply use a :local/root to a generated EDN file. It merges all deps from aliases as well as paths. And for those paths, where that deps.edn resides, the generating scripts creates hard links to those. That allows me to never duplicate deps, consume paths from everywhere in the repo without deps complaining about outside paths (`../xxx`), without having do to anything with BB or prepare it in any way when using it (e.g. --classpath)

George P9s12:09:55

Hello everyone, I'm having a problem with babashka.process. I'm trying to execute git show --name-only pretty="" as (process/process '[git "show" "--name-only" "--pretty=\"\""]) but the form does not like the last argument. Is there an other way to write this?

borkdude13:09:37

@george.per It seems to work, but git doesn't seem to like "" :

user=> (:cmd @(process/process '[git "show" "--name-only" "--pretty=\"\""] {:out :inherit :err :inherit}) )
fatal: invalid --pretty format: ""
["git" "show" "--name-only" "--pretty=\"\""]

George P9s13:09:47

In bash, the command returns without error.

borkdude13:09:46

Bash seems to just drop "":

$ bb -e '*command-line-args*' git show --name-only pretty=""
("git" "show" "--name-only" "pretty=")

borkdude13:09:56

So the equivalent would be to just omit those strings

George P9s13:09:35

Ah it works! Thank you @borkdude

🎉 1
borkdude13:09:12

Random tip: here is how you can add the latest quickdoc to your bb.edn with neil:

neil add dep io.github.borkdude/quickdoc --latest-sha --deps-file bb.edn

nice 2
escherize15:09:20

Is anyone building desktop apps with babashka? Are there any resources for e.g. crossplatform tray icons, or strategies for distributing executables? Would I be better off building things in clojure and using graalvm?

borkdude15:09:36

I think HumbleUI might be a good option which I think some people have gotten to work with GraalVM.

😮 2
Crispin13:10:34

cljfx + jpackage could be an option: https://vlaaad.github.io/year-of-clojure-on-the-desktop. Gluon has a GraalVM substrate that compiles JavaFX applications to native but as far as I know no one has got gluon and cljfx working together.

Crispin13:10:10

Gluon substrate here https://github.com/gluonhq/substrate if you want to be a pioneer 😄