Skip to content

Commit

Permalink
fix: select correct run environment (prefix-dev#2301)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-arts authored Oct 17, 2024
1 parent 2894275 commit 4b9bbd7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
let environment = project.environment_from_name_or_env_var(args.environment.clone())?;

// Find the environment to run the task in, if any were specified.
let explicit_environment = if args.environment.is_none() {
let explicit_environment = if args.environment.is_none() && environment.is_default() {
None
} else {
Some(environment.clone())
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/test_main_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ def test_search(pixi: Path) -> None:

def test_simple_project_setup(pixi: Path, tmp_path: Path) -> None:
manifest_path = tmp_path / "pixi.toml"
conda_forge = "https://fast.prefix.dev/conda-forge"
# Create a new project
verify_cli_command([pixi, "init", tmp_path], ExitCode.SUCCESS)
verify_cli_command([pixi, "init", "-c", conda_forge, tmp_path], ExitCode.SUCCESS)

# Add package
verify_cli_command(
Expand Down Expand Up @@ -208,7 +209,7 @@ def test_simple_project_setup(pixi: Path, tmp_path: Path) -> None:
manifest_path,
"--platform",
"linux-64",
"conda-forge::_r-mutex",
f"{conda_forge}::_r-mutex",
],
ExitCode.SUCCESS,
stderr_contains=["linux-64", "conda-forge"],
Expand Down Expand Up @@ -256,7 +257,7 @@ def test_simple_project_setup(pixi: Path, tmp_path: Path) -> None:
manifest_path,
"--platform",
"linux-64",
"conda-forge::_r-mutex",
f"{conda_forge}::_r-mutex",
],
ExitCode.SUCCESS,
stderr_contains=["linux-64", "conda-forge", "Removed"],
Expand Down
59 changes: 59 additions & 0 deletions tests/integration/test_run_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from pathlib import Path
from .common import verify_cli_command, ExitCode

ALL_PLATFORMS = '["linux-64", "osx-64", "win-64", "linux-ppc64le", "linux-aarch64"]'

EMPTY_BOILERPLATE_PROJECT = f"""
[project]
name = "test"
channels = []
platforms = {ALL_PLATFORMS}
"""


def test_run_in_shell(pixi: Path, tmp_path: Path) -> None:
manifest = tmp_path.joinpath("pixi.toml")
toml = f"""
{EMPTY_BOILERPLATE_PROJECT}
[tasks]
task = "echo default"
task1 = "echo default1"
[feature.a.tasks]
task = {{ cmd = "echo a", depends-on = "task1" }}
task1 = "echo a1"
[environments]
a = ["a"]
"""
manifest.write_text(toml)

# Run the default task
verify_cli_command(
[pixi, "run", "--manifest-path", manifest, "--environment", "default", "task"],
ExitCode.SUCCESS,
stdout_contains="default",
stderr_excludes="default1",
)

# Run the a task
verify_cli_command(
[pixi, "run", "--manifest-path", manifest, "--environment", "a", "task"],
ExitCode.SUCCESS,
stdout_contains=["a", "a1"],
)

# Error on non-specified environment as ambiguous
verify_cli_command(
[pixi, "run", "--manifest-path", manifest, "task"],
ExitCode.FAILURE,
stderr_contains=["ambiguous", "default", "a"],
)

# Simulate activated shell in environment 'a'
env = {"PIXI_IN_SHELL": "true", "PIXI_ENVIRONMENT_NAME": "a"}
verify_cli_command(
[pixi, "run", "--manifest-path", manifest, "task"],
ExitCode.SUCCESS,
stdout_contains=["a", "a1"],
env=env,
)

0 comments on commit 4b9bbd7

Please sign in to comment.