feat(tasks): namespacing/grouping of tasks
Problem description
Hi all,
I love using Pixi for my ML robotics research, thank you for your great work! I also love tasks, and regularly use them to shorten unwieldy run invocations. However, I may love tasks a little too much, and I always end up a really long list of tasks as I'm iteratively testing different experiments. For example, here is the actual output from my current project.
(gigastrap:gsa) garylvov@roz:~/projects/gigastrap$ pixi r
Available tasks:
aov-rgb
aov-simple
base-train
bluey
gitmod
install-isaaclab
install-isaaclab-aov
lie
lint
play
play-latest
play2
play3
play5
rslg
rslg-allegro
rslg-allegro-mgpu
rslg-allegro-senc
rslg-allegro-senc-mgpu
rslg-c
rslg-c-tdo
rslg-c-tdo-fusion
rslg-custom-cnn
rslg-custom-cnn-debug
rslg-custom-cnn-mgpu
rslg-debug
rslg-debug-shadow
rslg-debug-vavg
rslg-distill-vavg
rslg-distill-vavg-debug
rslg-distill-vavg-mgpu
rslg-distill-vavg-no-critic
rslg-distill-vavg-no-critic-debug
rslg-distill-vavg-no-critic-mgpu
rslg-fabric
rslg-fabric-compiled
rslg-fabric-compiled-debug
rslg-fabric-compiled-large
rslg-fabric-debug
rslg-fabric-large
rslg-mgpu
rslg-rnn
rslg-rnn-debug
rslg-rnn-deep
rslg-rnn-deep-debug
rslg-rnn-deep-mgpu
rslg-rnn-mgpu
rslg-rnn-mlp-after
rslg-rnn-mlp-after-debug
rslg-rnn-mlp-after-mgpu
rslg-rnn-mlp-before
rslg-rnn-mlp-before-debug
rslg-rnn-mlp-before-mgpu
rslg-vavg
rslg-vavg-amp
rslg-vavg-amp-large
rslg-vavg-amp-mgpu
rslg-vavg-large
rslg-vavg-mgpu
rslg-vision-asym
rslg-vision-asym-goal
rslg-vision-asym-goal-mgpu
rslg-vision-asym-mgpu
rslg-vision-sym
rslg-vision-sym-mgpu
tb
test
Of course, I'm a bit forgetful, so after coming back to my computer, I often forget what specific command I want to run. In this situation, I oftentimes have to open up Vim or VSCode, and look for the specific command that has the flag flipped or command-line argument supplied in the pixi.toml.
Naturally, one might wonder,
- "Why not use tab complete with the existing tasks to narrow them down?" For me, if I run
pixi r rslg<TAB>in my project, nothing happens. Maybe here we could grep the existing pixi tasks, and list those that fit the tab complete? - "Why not name your tasks descriptively so you can just scroll up and find it in the terminal output?" This makes task names really long to type. One may suggest using tab complete, but then this adds a tab at the end of every letter typed, which doubles the length to type tasks, and more importantly tab complete doesn't work on tasks for me
- "Why not namespace tasks based on environment?"- Then I will have many environments, really annoying to activate the right one
- "Why not just live with how it currently is? It doesn't take that much time to figure out what command you're actually running?" - I have been, but I run many pixi tasks in a day, and I'm very lazy ;) I dream of even more convenience!
I'd love to have a functionality along the lines of the following to make using many tasks a bit more manageable (or at the very least, add tab completion while trying to type tasks as mentioned earlier).
In the pixi.toml, namespaces could be specified as something like:
[feature.gsa.tasks]
dt = "ls | grep .toml"
[feature.gsa.tasks.a]
alpha = "ls"
beta = "ls -la"
[feature.gsa.tasks.b]
gamma = "cd"
zeta = "rm"
so that when one does pixi r , they could get something like the following
Available Tasks:
namespace default:
dt
namespace a:
alpha
beta
namespace b:
gamma
zeta
Also, we could also do something like pixi ns to get something like the following:
Available namespaces:
default
a
b
Which could then be used in a command like pixi r ns a to get something like the following:
Available Tasks in 'a' Namspeace:
alpha
beta
Also, it would be cool to be able to define these tasks in external files to make the pixi toml shorter, is there an existing functionality for this?
There may be an obvious solution here that I'm missing with regard to just organizing my tasks better, or maybe I'm missing how to use an existing feature. I'm open to suggestions!
Thank you!
"Why not use tab complete with the existing tasks to narrow them down?" For me, if I run pixi r rslg
in my project, nothing happens. Maybe here we could grep the existing pixi tasks, and list those that fit the tab complete?
Do you have the completion script installed? https://pixi.sh/latest/misc/packaging/#shell-completion
[feature.gsa.tasks.a]
alpha = "ls"
beta = "ls -la"
This syntax is problematic because you can also define tasks like this:
[feature.gsa.tasks.a]
cmd = "ls"
It will be hard to distinguish between, is a a namespace or a task.
Maybe we can add a group field to tasks, so we can group the commands together in the output?
[feature.gsa.tasks]
dt = "ls | grep .toml"
[feature.gsa.tasks]
alpha = { cmd = "ls", group = "a" }
beta = { cmd = "ls -la", group = "a" }
[feature.gsa.tasks.b]
gamma = { cmd = "cd", group = "b" }
zeta = { cmd = "rm", group = "b" }
Available Tasks:
dt
group a:
alpha
beta
group b:
gamma
zeta
Or introducing task-groups:
[feature.gsa.task-group.a]
title = "Awesome group" #optional
description = "This is a long form description" #optional
[feature.gsa.task-group.a.tasks]
alpha = "ls"
beta = "ls -la"
[feature.gsa.task-group.a]
title = "Super group" #optional
description = "This is a long form description" #optional
[feature.gsa.task-group.b.tasks]
gamma = "cd"
zeta = "rm
Available Tasks:
- dt
Awesome group
This is a long form description
- alpha
- beta
Super group
This is a long form description
- gamma
- zeta
Not sure if the added complexity is worth it though. Wdyt @ruben-arts @Hofer-Julian @tdejager . How do other task runners approach this?
Both proposals look nice, I'm also not sure the added complexity is worth it. Maybe wait for more comments/+1?
Hi @baszalmstra @tdejager thank you for your comments!
The group specification @baszalmstra suggested looks great!
I didn't know about the shell completion, this already helps a lot ;)
Fair point about unneeded complexity; I can definitely scrape by with tab completion for now.
I would be curious to hear @ruben-arts opinion on this :)
I think that something like this would be extremely valuable in the context of pixi-gui!!
I actually have been thinking about this too. But more in regards to the reuse of tasks from different packages. Maybe these concepts could be mixed.
I was playing with the idea of having a package as a "namespace" so that would for instance look like this:
[package]
name = "my_package"
tasks = [{ fmt = "ruff"}]
[dependencies]
my_package = { path = "." }
pixi run my_package fmt
Where both my_package and fmt would autocomplete on "tabtab".
This could then also pottentionally be reused for the namespace idea.
There are previous ideas on improving tasks to make it more managable:
- Having named arguments: https://github.com/prefix-dev/pixi/issues/4280
- Having options for arguments. e.g.:
[tasks.test] cmd = "pytest -k {{ tests }}" args = [{ arg = "tests", options = ["integration", "all", "offline"] }]pixi run test Which option for the argument "test" do you want to run: -> integration > all > offline - Having reusable variables:
[vars] install-cmd = "cargo install --release" test-cmd = "pytest --fast-fail --bla" [tasks] test-integration = "{{ test-cmd }} -k integration" test-all = "{{ test-cmd }}" - Improved
pixi task list:> pixi task list # or pixi run Task Description Command build-backends Build build-backends cargo install --locked --path build-backends build-trampoline Build the trampolines cargo install --locked --path build-trampoline # Or with "search" capabilities > pixi task list tramp Task Description Command build-trampoline Build the trampolines cargo install --locked --path build-trampoline
Considering the autocompletion and some of these ideas would that combined improvement still benefit from the namespace logic? Would love to hear some input on these ideas.
I think some sort of grouping would be useful on top of those other suggestions. Consider how SciPy looks in pixi-gui right now, which groups tasks by environment and sorts alphabetically:
and the corresponding pixi task list, which just sorts all tasks alphabetically:
❯ pixi task list
Tasks that can run on this machine:
-----------------------------------
bench, build, build-accelerate-ilp64, build-accelerate-lp64, build-cpu, build-debug, build-scipy-openblas, build-system-libs, check-python-h, docs, ipython, lint, lldb, tach-check, tach-check-external, test, test-accelerate-ilp64, test-accelerate-lp64, test-coverage, test-cpu, test-dask, test-jax, test-scipy-openblas, test-strict, test-system-libs, test-torch, test-torch-float32, test-xslow
Task Description
build Build SciPy (default settings)
build-accelerate-ilp64 Build SciPy with accelerate (ilp64)
build-accelerate-lp64 Build SciPy with accelerate (lp64)
...
Neither of these are ideal. What I really want is to have one group containing the tasks that cover what 90% of contributors will need, like build, test, docs, lint etc. and these should show at the top. Being able to group more niche tasks like those for different array library backends or different BLAS libraries at the bottom to keep the noise away from the average user would be nice.
A further suggestion would be that task groups can opt in or out of the default pixi task list output. This would be helpful for workspaces with a large number of tasks to avoid spamming the terminal, while communicating to the user that they can pixi task list --all or pixi task list --group=... to learn about the other tasks.
I gave it my best shot in #5307 ! I know very little about Rust sorry!
As #5307 is handling just the single-file stuff, wanted to drop an idea here about multi-file stuff.
Especially in a publishable, discoverable task groups scenario, being able to document and then customize parameters to an imported file would be very powerful. The templating syntax would be usable in more places than a normal pixi.toml, under a new reserved namespace (kinda missed the boat on namespacing args), with full, self-documenting schema.
For example, a reusable test task group:
# pixi.toml
[feature.foo.task-groups]
test-foo = {file="test.tasks.toml", context={path="foo", prefix="foo-"}}
[feature.bar.task-groups]
test-bar = {file="test.tasks.toml", context={path="bar", prefix="bar-"}}
# test.tasks.toml
[group]
description = "some tests"
[schema]
required = ["path"]
[schema.properties]
prefix = {default="", description="a prefix", type="string"}
path = {description="a path to test", type="string"}
[tasks."{{ group.prefix }}test"]
cwd = "{{ group.path }}"
cmd = "cd {{ group.path }}"
inputs = ["{{ path }}/**/*.py"]
Would yield two groups in two features exposing two tasks, foo-test and bar-test.