pixi icon indicating copy to clipboard operation
pixi copied to clipboard

Pixi task specification should support explicit argument parameterization

Open jleibs opened this issue 2 years ago • 2 comments

Problem description

In the task specification, it would be very nice to be able to parameterize the arguments passed to the task.

Simply provided named positional args that could then be substituted using env-variables would be a great starting point.

For example, something like:

paramterized = {  positional_args = [ "ARG1", "ARG2"], cmd = "python src/foo.py $ARG1 | python src/bar.py $ARG2 --some-flag"}

This would allow using arguments in a way that isn't possible with the current append-only version of passing in args. Without this we need to add an extra level of indirection to accomplish these kinds of invocations.

Additionally having structured args like would allow the args to be listed as part of pixi task list, making it more self-documenting how the task is intended to be invoked.

jleibs avatar Nov 27 '23 13:11 jleibs

I like the idea, let us think about this some more!

We've had some other users propose support for $1 $2 $... like bash does.

ruben-arts avatar Nov 28 '23 09:11 ruben-arts

I like this idea too. To add my 2¢, you don't have to write long inline tables to achieve this:

[tasks]
[tasks.paramterized]
positional_args = [ "ARG1", "ARG2"]
cmd = "python src/foo.py $ARG1 | python src/bar.py $ARG2 --some-flag"

Also, I would suggest a syntax for variadic arguments, so that this remains compatible with the current append-only argument passing.

For example, just uses *VARARG for zero or more arguments and +VARARG for one or more. An example recipe/task in just...

commit MESSAGE *FLAGS:
  git commit {{FLAGS}} -m "{{MESSAGE}}"

...could serve as inspiration for pixi:

[tasks]
[tasks.commit]
signature = ["MESSAGE", "*FLAGS"] # required and variadic arguments, respectively
cmd = ["git", "commit", "$FLAGS", "-m", "$MESSAGE"]

Jollywatt avatar Jul 10 '24 10:07 Jollywatt

This is now fixed using the arguments implementation, we've taking great inspiration from just and task. There are still lots of improvements we can do, but I will close this issue for now.

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

Amazing! Very excited to give this a try.

jleibs avatar Jun 19 '25 13:06 jleibs