Fork me on GitHub
#babashka
<
2023-12-02
>
Piotr Kaznowski16:12:10

Is it possible to use a babashka project as a dependency for a different project? My use-case is related to Advent of Code -- I keep separate repos for each year, but reuse the same bb script for bootstrapping each day solution and running it. So ideally I would have a separate project, say, advent-of-code , and all other repos (`2023`, 2022 ...) would just have it as a dependency (that would mean the bb script from the AoC repo would be the executable for all particular repos). Hope it makes some sense.

borkdude16:12:35

Yes, just use deps.edn in your library and use this library from bb.edn

borkdude16:12:15

E.g. if you library is structured as src/my_script.clj

borkdude16:12:30

then add a deps.edn: {:paths ["src"}in the root of your library

borkdude16:12:54

and then in another project you can write in bb.edn:

{:deps {my/script {:local/root "/path/to/library"}}}

Piotr Kaznowski16:12:12

In my case the my_script.clj is just a bb.edn + a template file. So I would have 2 local repos (for simplicity sake) -- ~/aoc with bb.edn providing all the tasks and template.txt, and ~/aoc23 which will be populated with solutions for 2023. If I put {:deps {bb {:local/root "~/aoc"}}} in ~/aoc23/deps.edn would that work?

Piotr Kaznowski16:12:03

(Actually will test it rn)

borkdude16:12:21

ah you're using tasks?

Piotr Kaznowski16:12:58

It's a very simple bb script: https://github.com/caseneuve/aoc2023 -- I'd like to extract bb.edn and template.txt and reuse it

borkdude16:12:12

This will work when you add an adjacent script to your bb.edn like this:

#!/usr/bin/env bb
(require '[babashka.tasks :as tasks])
(apply tasks/run (symbol (first *command-line-args)) (rest *command-line-args*))
If you then put this script on your path, you can call it from everywhere. Tasks are usually only used for project-local tasks but this is a hack to make them more globally useful

Piotr Kaznowski16:12:46

Right! So in order to make it less hacky, I could think about rewriting the tasks into a script that would be a dependency. But then I'd need to write the tasks for each repo again, so it's not perfect.

borkdude16:12:22

you don't need to do everything via tasks, what you want is probably a command line interface that you can use across projects

borkdude16:12:31

you can do this with babashka.cli and bb -x for example

borkdude16:12:42

or write a globally installed command line tool

Piotr Kaznowski16:12:00

Yeah, I'm just processing what you said and trying to get out of the tasks box :)

borkdude16:12:37

yes, everything that deps.edn supports

👍 1