Skip to content

Commit

Permalink
fix: regression detached-environments not used (prefix-dev#2627)
Browse files Browse the repository at this point in the history
fixes prefix-dev#2623

---------

Co-authored-by: Bas Zalmstra <bas@prefix.dev>
  • Loading branch information
ruben-arts and baszalmstra authored Dec 3, 2024
1 parent e8e8708 commit 6655397
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -131,7 +131,7 @@ fn write_file<P: AsRef<Path>, 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(|| {
Expand Down Expand Up @@ -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/<env>` 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());

Expand Down Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions tests/integration_python/test_run_cli.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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}",
)

0 comments on commit 6655397

Please sign in to comment.