Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add env to the tasks to specify tasks specific environment variables #972

Merged
merged 10 commits into from
Apr 18, 2024

Conversation

wolfv
Copy link
Member

@wolfv wolfv commented Mar 13, 2024

This adds the ability to set additional environment variables for a specific task. E.g.:

[tasks]
bla = { cmd = "echo $ABC", env = { ABC = "DEF" } }
path_mod = { cmd = "echo $PATH", env = { PATH="/tmp/path:$PATH" }}

This results in:

$ pixi run bla
DEF

$ ABC=hoi pixi run bla
hoi

$ pixi run path_mod
/tmp/path:/bin:/.local/bin .....

We might also want this for a feature / environment (as a lightweight way of adding an 'activation script').

TODO:

  • Add tests, preferrably in unit and an example where it is tested on their test task.
  • Add documentation
  • Add to schema.json

@ruben-arts ruben-arts marked this pull request as draft March 19, 2024 09:18
@ruben-arts
Copy link
Contributor

@wolfv Do you want to continue on this pr? other wise making an issue out of it and closing it would be nice.

@ruben-arts
Copy link
Contributor

ruben-arts commented Apr 17, 2024

I like this, a lot actually.

A few questions:

  • xxx = { cmd = "echo $ABC", env = { "ABC" = "asdsad" }} if i run this with ABC="hoi" pixi run xxx Should it say "hoi" or "asdsad"? I could imagine a nice use-case where it is used as a default but could be overwritten. This is also what task does: GREETING=hoi task greet uses hoi for GREETING instead of the value defined in taskfile.
  • Should the env transfer in a depends_on graph? Taskfile doens't do that, so maybe for later

@ruben-arts ruben-arts changed the title prototype the environment variable settings Add env to the tasks to specify tasks specific environment variables Apr 17, 2024
@ruben-arts ruben-arts changed the title Add env to the tasks to specify tasks specific environment variables feat: Add env to the tasks to specify tasks specific environment variables Apr 17, 2024
Copy link
Member Author

@wolfv wolfv left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for pushing. Also love the idea about using env vars as "positional arguments" and for task parameterization.

Just one note about the order of env vars.

docs/features/advanced_tasks.md Show resolved Hide resolved
src/task/mod.rs Outdated Show resolved Hide resolved
@wolfv wolfv marked this pull request as ready for review April 18, 2024 05:34
@wolfv
Copy link
Member Author

wolfv commented Apr 18, 2024

If I could, I would approve the PR (since I opened it I can't review!) :)

@ruben-arts ruben-arts merged commit 28d0ca9 into prefix-dev:main Apr 18, 2024
29 checks passed
@nicornk nicornk mentioned this pull request Apr 19, 2024
@wolfv wolfv deleted the prototype-env-var-setting branch April 21, 2024 06:13
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.

2 participants