prefix-dev / pixi

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

Running a task from a given environment within pixi shell of another environment #2468

Open maurosilber opened 3 weeks ago

maurosilber commented 3 weeks ago

Checks

Reproducible example

Here is a simple pixi.toml to reproduce this issue:

[project]
name = "tasks_from_env"
channels = ["https://fast.prefix.dev/conda-forge"]
platforms = ["osx-arm64"]

[feature.A.tasks]
echo_A = "echo hello from A"

[feature.B.tasks]
echo_B = "echo hello from B"

[environments]
a = ["A"]
b = ["B"]

And a series of commands and their outputs with pixi == 0.35:

❯ pixi run

Available tasks:
    echo_A
    echo_B

❯ pixi shell -e a

❯ pixi run

Available tasks:
    echo_A

❯ pixi run echo_B
echo_B: command not found

Available tasks:
    echo_A

❯ pixi run -e b echo_B
✨ Pixi task (echo_B in b): echo hello from B
hello from B

Issue description

This might not be a bug, but I cannot run a task from a given environment without explicitly adding -e <env> if I'm within the shell of another environment. In my project, I have lint environment with a lint task that I used to run with pixi run lint, since it is the only environment defining a task with that name. But the Python extension in VSCode activates another environment automatically in its terminal. Maybe I should just prevent the VSCode extension from activating an environment in the terminal.

Expected behavior

❯ pixi shell -e a

❯ pixi run

Available tasks:
    echo_A
        echo_B
Ragiton commented 1 week ago

I'm having the same issue. I have to specify which environment the task uses if I try to run it when I have my "tests" environment activated in VSCode.

This issue doesn't occur if I downgrade to 0.33.0 but reappears as soon as I go up to 0.34.0 and on.