Babashka tasks
Posted on Sun 02 March 2025 in en • Tagged with clojure, babashka, pip • 1 min read
I’ve been enjoying using babashka tasks for a while now. It’s nicer than Makefile and a great way to stash commands in your project.
This, for example, is how I compile my requirements.txt
from requirements.in
in a bunch of python projects, simply running bb pip
from the project’s root:
{:paths ["src" "."]
:tasks
{pip
{:task
(do
(shell "uv pip compile --no-strip-extras requirements.in -o requirements.txt")
(shell "uv pip sync requirements.txt"))}}}
It will shine when you have more things to do, and you can import some piece of clojure to do them.
This is how I do run a transcription pipeline for some lecture notes, offloading them to a remote machine with rsync
, and then running the transcription with some transync
I’ve written:
{:paths ["src" "."]
:tasks
{sync {:task (shell (str "rsync -vaL --progress --chmod=Du=rwx,Dg=rwx,Do=rx,Fu=rw,Fg=rw,Fo=r \""
(System/getProperty "user.home")
"Google Drive/My Drive/lectures\" "
"remotehost:~/data/transync/input/"))}
ffmpeg-convert {:requires [transync]
:task (transync/ffmpeg-convert!)}
transcribe-files {:requires [transync]
:depends [ffmpeg-convert]
:task (transync/transcribe-files!)}
remote-transcribe
{:task (do
(shell (str "ssh-add " (System/getProperty "user.home") "/.ssh/github"))
(shell "ssh remotehost '. ~/.zshrc && cd ~/path/to/project && git pull && bb transcribe-files'"))}
sync-back
{:depends [sync remote-transcribe]
:task
(shell (str "rsync -vaL --progress --chmod=Du=rwx,Dg=rwx,Do=rx,Fu=rw,Fg=rw,Fo=r "
"remotehost:~/data/transync/transcripts \""
(System/getProperty "user.home")
"/Google Drive/My Drive/transcripts\""))}}}
You’ll notice that I’m running some tasks on the remote host, after pulling from github with my ssh-add
‘ed github key. This might not be the production way to do it but it’s been very convenient for me so far. Especially without having to figure out how to escape strings in bash one more time.