From 66553975e4658d9c7b3b407396324360cc6a98ba Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Tue, 3 Dec 2024 15:04:45 +0100 Subject: [PATCH] fix: regression `detached-environments` not used (#2627) fixes #2623 --------- Co-authored-by: Bas Zalmstra --- src/environment.rs | 8 ++-- tests/integration_python/test_run_cli.py | 49 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/environment.rs b/src/environment.rs index fe5823156..f508570fd 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -53,7 +53,7 @@ use xxhash_rust::xxh3::Xxh3; /// not present. pub async fn verify_prefix_location_unchanged(environment_dir: &Path) -> miette::Result<()> { let prefix_file = environment_dir - .join("conda-meta") + .join(consts::CONDA_META_DIR) .join(consts::PREFIX_FILE_NAME); tracing::info!( @@ -131,7 +131,7 @@ fn write_file, C: AsRef<[u8]>>(path: P, contents: C) -> io::Resul /// Give it the environment path to place it. fn create_prefix_location_file(environment_dir: &Path) -> miette::Result<()> { let prefix_file_path = environment_dir - .join("conda-meta") + .join(consts::CONDA_META_DIR) .join(consts::PREFIX_FILE_NAME); let parent_dir = prefix_file_path.parent().ok_or_else(|| { @@ -163,7 +163,7 @@ fn create_prefix_location_file(environment_dir: &Path) -> miette::Result<()> { /// Create the conda-meta/history. /// This file is needed for `conda run -p .pixi/envs/` to work. fn create_history_file(environment_dir: &Path) -> miette::Result<()> { - let history_file = environment_dir.join("conda-meta").join("history"); + let history_file = environment_dir.join(consts::CONDA_META_DIR).join("history"); tracing::info!("Verify history file exists: {}", history_file.display()); @@ -309,7 +309,7 @@ pub(crate) fn read_environment_file( /// 4. It verifies that the prefix contains a `.gitignore` file. pub async fn sanity_check_project(project: &Project) -> miette::Result<()> { // Sanity check of prefix location - verify_prefix_location_unchanged(project.default_environment().dir().as_path()).await?; + verify_prefix_location_unchanged(project.environments_dir().as_path()).await?; // TODO: remove on a 1.0 release // Check for old `env` folder as we moved to `envs` in 0.13.0 diff --git a/tests/integration_python/test_run_cli.py b/tests/integration_python/test_run_cli.py index 28a9cc7af..7cce0ef58 100644 --- a/tests/integration_python/test_run_cli.py +++ b/tests/integration_python/test_run_cli.py @@ -1,6 +1,8 @@ import json from pathlib import Path + from .common import EMPTY_BOILERPLATE_PROJECT, verify_cli_command, ExitCode, default_env_path + import tempfile import os @@ -274,3 +276,50 @@ def test_run_with_activation(pixi: Path, tmp_pixi_workspace: Path) -> None: [pixi, "run", "--manifest-path", manifest, "--force-activate", "task", "-vvv"], stdout_contains="test123", ) + + +def test_detached_environments_run(pixi: Path, tmp_path: Path, dummy_channel_1: str) -> None: + tmp_project = tmp_path.joinpath("pixi-project") + tmp_project.mkdir() + detached_envs_tmp = tmp_path.joinpath("pixi-detached-envs") + manifest = tmp_project.joinpath("pixi.toml") + + # Create a dummy project + verify_cli_command([pixi, "init", tmp_project, "--channel", dummy_channel_1]) + verify_cli_command([pixi, "add", "dummy-a", "--no-install", "--manifest-path", manifest]) + + # Set detached environments + verify_cli_command( + [ + pixi, + "config", + "set", + "--manifest-path", + manifest, + "--local", + "detached-environments", + str(detached_envs_tmp), + ], + ) + + # Run the installation + verify_cli_command([pixi, "install", "--manifest-path", manifest]) + + # Validate the detached environment + assert detached_envs_tmp.exists() + + detached_envs_folder = None + for folder in detached_envs_tmp.iterdir(): + if folder.is_dir(): + detached_envs_folder = folder + break + assert detached_envs_folder is not None, "Couldn't find detached environment folder" + + # Validate the conda-meta folder exists + assert Path(detached_envs_folder).joinpath("envs", "default", "conda-meta").exists() + + # Verify that the detached environment is used + verify_cli_command( + [pixi, "run", "--manifest-path", manifest, "echo $CONDA_PREFIX"], + stdout_contains=f"{detached_envs_tmp}", + )