Skip to content

feat: add template args for env vars in tasks as well#5613

Open
tdejager wants to merge 2 commits intoprefix-dev:mainfrom
tdejager:feature/pix-1534-feattasks-support-template-strings-in-env-entries
Open

feat: add template args for env vars in tasks as well#5613
tdejager wants to merge 2 commits intoprefix-dev:mainfrom
tdejager:feature/pix-1534-feattasks-support-template-strings-in-env-entries

Conversation

@tdejager
Copy link
Contributor

@tdejager tdejager commented Mar 5, 2026

Description

Fixes #5446

How Has This Been Tested?

I tested this with the following toml:

[workspace]
name = "template-env-test"
version = "0.1.0"
channels = ["conda-forge"]
platforms = ["osx-arm64"]

[tasks]
greet = { cmd = "echo $GREETING", env = { GREETING = "hello {{ name }}" }, args = [{ arg = "name", default = "world" }] }

json-env = { cmd = "echo $CONFIG", env = { CONFIG = '{"backend": "{{ backend }}"}' }, args = [{ arg = "backend", default = "numpy" }] }

[tasks.dep]
cmd = "echo BACKEND=$BACKEND"
env = { BACKEND = "{{ backend }}" }
args = [{ arg = "backend", default = "fallback" }]

[tasks.run-cupy]
depends-on = [{ task = "dep", args = ["CuPy"] }]
pixi run greet                     # hello world
pixi run greet pixi              # hello pixi
pixi run json-env               # {"backend": "numpy"}
pixi run json-env cupy      # {"backend": "cupy"}
pixi run run-cupy              # BACKEND=CuPy

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.

Tools: Claude Code

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added sufficient tests to cover my changes.
  • I have verified that changes that would impact the JSON schema have been made in schema/model.py.

@tdejager tdejager force-pushed the feature/pix-1534-feattasks-support-template-strings-in-env-entries branch from 0479745 to 720cddc Compare March 6, 2026 09:38
@tdejager tdejager force-pushed the feature/pix-1534-feattasks-support-template-strings-in-env-entries branch from 720cddc to eec37dc Compare March 6, 2026 09:41
@tdejager tdejager requested a review from nichmor March 6, 2026 13:45
export.push_str(&format!("export \"{key}={value}\";\n"));
let rendered = value.render(context)?;
// Escape double quotes so the export statement remains valid shell.
let escaped = rendered.replace('"', "\\\"");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it wasn't needed before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it should've been I think. Now I just reckoned it would happen more quickly.

@baszalmstra
Copy link
Contributor

Claude said:

Missing test coverage (high priority):: There are no tests for the non-happy path.

docs/workspace/advanced_tasks.md — MiniJinja Templating section (around line 335): Currently says "Task commands defined in the manifest support MiniJinja templating syntax." This is now factually incomplete — template strings also work in env values. This sentence and the section's examples need updating.

docs/workspace/advanced_tasks.md — Environment Variables section (around line 464): Describes env behavior but makes no mention of template string support. At minimum, add a note and example showing {{ }} syntax in env values.


The test coverage thing for non-happy path is fine I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(tasks): support template strings in env entries

3 participants