prefix-dev / pixi

Package management made easy
https://pixi.sh
BSD 3-Clause "New" or "Revised" License
3.41k stars 193 forks source link

Can't modify PATH in env activation table #1465

Open beenje opened 6 months ago

beenje commented 6 months ago

Checks

Reproducible example

[project]
name = "myproject"
channels = ["conda-forge"]
platforms = ["osx-64", "linux-64"]

[activation]
env = { PATH = "$PIXI_PROJECT_ROOT/.pixi/envs/tangotest/bin:$PATH" }

[tasks]
echo = { cmd = "echo $PATH" }

[dependencies]
python = ">=3.12.3,<3.13"
pytango = ">=9.5.1,<9.6"

[feature.tangotest]
dependencies = { tango-test = "3.9" }

[environments]
tangotest = { features = ["tangotest"], no-default-feature = true }

Issue description

With pixi 0.23.0 and the new env activation table, I wanted to replace the following pixi.toml:

[project]
name = "myproject"
channels = ["conda-forge"]
platforms = ["osx-64", "linux-64"]

[tasks]
echo = { cmd = "echo $PATH", env = { PATH = "$PIXI_PROJECT_ROOT/.pixi/envs/tangotest/bin:$PATH" } }

[dependencies]
python = ">=3.12.3,<3.13"
pytango = ">=9.5.1,<9.6"

[feature.tangotest]
dependencies = { tango-test = "3.9" }

[environments]
tangotest = { features = ["tangotest"], no-default-feature = true }

With this file, it works:

$ myproject pixi run echo
✨ Pixi task (echo in default): echo $PATH
/Users/benjaminbertrand/tmp/myproject/.pixi/envs/tangotest/bin:/Users/benjaminbertrand/tmp/myproject/.pixi/envs/default/bin:/Users/benjaminbertrand/miniconda/condabin:/usr/local/opt/gnu-sed/libexec/gnubin...

But with the env activation table, this is what I get:

$ pixi run echo
✨ Pixi task (echo in default): echo $PATH
$PIXI_PROJECT_ROOT/.pixi/envs/tangotest/bin:$PATH
$ pixi shell
 . "/var/folders/5p/7800st6d3w76wy6pr67lm9680000gn/T/pixi_env_Ya1.sh"
$  myproject  . "/var/folders/5p/7800st6d3w76wy6pr67lm9680000gn/T/pixi_env_Ya1.sh"
(myproject) $ echo $PATH
/Users/benjaminbertrand/tmp/myproject/.pixi/envs/tangotest/bin:/usr/local/opt/gnu-sed/libexec/gnubin...

.pixi/envs/default/bin isn't part of the PATH.

When looking at shell-hook, it looks ok. I guess there is an issue in how the variables are expanded?

$ pixi shell-hook
export PATH="/Users/benjaminbertrand/tmp/myproject/.pixi/envs/default/bin:/Users/benjaminbertrand/miniconda/condabin:/usr/local/opt/gnused/libexec/gnubin:..."
...
export PATH="$PIXI_PROJECT_ROOT/.pixi/envs/tangotest/bin:$PATH"

Expected behavior

I'd expect the PATH to be identical to when using task env: /Users/benjaminbertrand/tmp/myproject/.pixi/envs/tangotest/bin:/Users/benjaminbertrand/tmp/myproject/.pixi/envs/default/bin:/Users/benjaminbertrand/miniconda/condabin:/usr/local/opt/gnu-sed/libexec/gnubin...

ruben-arts commented 6 months ago

Hmm that should be fixable. I also noted that it is placed in between the PIXI_PROJECT_ variables which can then also never work when using them in the PATH. I think it shouldn't be to hard to fix but I don't see a glaring issue when looking at it. As we already use an IndexMap and push them in, in the right order.