pixi icon indicating copy to clipboard operation
pixi copied to clipboard

Nested tasks

Open apple-phi opened this issue 1 year ago • 2 comments

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.

apple-phi avatar Jul 05 '24 23:07 apple-phi

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!

ruben-arts avatar Jul 08 '24 18:07 ruben-arts

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?

apple-phi avatar Jul 10 '24 20:07 apple-phi

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

hab25 avatar May 15 '25 19:05 hab25

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

lucascolley avatar May 19 '25 12:05 lucascolley

Thanks @lucascolley closing the issue

ruben-arts avatar Jun 19 '25 12:06 ruben-arts