pixi
pixi copied to clipboard
Nested tasks
Checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pixi, using
pixi --version.
Reproducible example
# pixi.toml
[project]
name = "cv"
channels = ["conda-forge"]
platforms = ["win-64"]
[tasks]
build = {cmd = ["tectonic", "-X", "build"]}
b = {depends-on = ["build"]}
watch = {cmd = ["tectonic", "-X", "watch"]}
pdfcpu = {cmd = ["go", "run", "github.com/pdfcpu/pdfcpu/cmd/pdfcpu@latest"]}
appendCL = {cmd = ["pdfcpu", "merge", "build/merged.pdf", "build/cv/cv.pdf"]}
[dependencies]
tectonic = ">=0.15.0,<0.16"
go = ">=1.22.5,<1.23"
> pixi run appendCL build/akuna/akuna.pdf
Pixi task (appendCL in default): pdfcpu merge build/merged.pdf build/cv/cv.pdf build/akuna/akuna.pdf
pdfcpu: command not found
Available tasks:
appendCL
b
build
pdfcpu
watch
Issue description
It appears that pixi tasks can't run other pixi tasks outside of depends-on (e.g. to run them with arguments), which I didn't notice in the documentation. Also, the error message is misleading, since it clearly lists the desired subtask pdfcpu in the available tasks after saying it can't be found.
So, either this is a bug in the error message, or this is an undocumented missing feature.
Expected behavior
Either pixi tasks should run other pixi tasks with supplied arguments, or the error message shouldn't state the contradiction that it can't find the task but lists it anyway.
We indeed don't parse the task itself as a pixi run command. This is where the depends-on comes in.
There is a feature request for arguments: #957
But the idea of simply allowing to run a task from a task is a good idea!
But the idea of simply allowing to run a task from a task is a good idea!
Any chance you could give some pointers on where in the codebase to look please so that I or someone else interested can figure out an implementation and make a PR?
You can already do this by calling pixi run from within the command of your pixi task.
E.g.,
appendCL = {cmd = ["pixi", "run", "pdfcpu", "merge", "build/merged.pdf", "build/cv/cv.pdf"]} (note however that, like in the issue description, this won't work because pdfcpu doesn't accept arguments).
disadvantages:
- multiple pixi processes
- probably more verbose than what what would could be achieved with some purpose-built syntax as is being requested here AFAIU
I think the intended behaviour can now be achieved like so:
[tasks.pdfcpu]
args = [{ "arg" = "cmd", "default" = "" }]
cmd = "go run github.com/pdfcpu/pdfcpu/cmd/pdfcpu@latest {{ cmd }}"
[tasks.appendCL]
args = [{ "arg" = "files", "default" = "" }]
depends-on = [{ "task" = "pdfcpu", "args" = ["merge build/merged.pdf build/cv/cv.pdf {{ files }}"]}]
❯ pixi run appendCL build/akuna/akuna.pdf
✨ Pixi task (pdfcpu): go run github.com/pdfcpu/pdfcpu/cmd/pdfcpu@latest merge build/merged.pdf build/cv/cv.pdf build/akuna/akuna.pdf
...
❯ pixi run pdfcpu foo
✨ Pixi task (pdfcpu): go run github.com/pdfcpu/pdfcpu/cmd/pdfcpu@latest foo
EDIT: fixed the example
Thanks @lucascolley closing the issue