Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: regression detached-environments not used #2627

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions crates/pixi_utils/src/conda_environment_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ impl CondaEnvFile {
channels = config.default_channels();
}

dbg!(&channels);

Ok((conda_deps, pip_deps, channels))
}
}
Expand Down
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?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the fix


// TODO: remove on a 1.0 release
// Check for old `env` folder as we moved to `envs` in 0.13.0
Expand Down
42 changes: 42 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,43 @@ 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:
manifest = tmp_path.joinpath("pixi.toml")

# Create a dummy project
verify_cli_command([pixi, "init", tmp_path, "--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",
"/tmp/pixi-detached-envs",
],
)

# Run the installation
verify_cli_command([pixi, "install", "--manifest-path", manifest])

# Validate the detached environment
detached_envs = Path("/tmp/pixi-detached-envs")
ruben-arts marked this conversation as resolved.
Show resolved Hide resolved
assert detached_envs.exists()
detached_envs_folder = next(
(folder for folder in detached_envs.iterdir() if folder.is_dir()), "no_folder"
)
# Validate the conda-meta folder exists
assert Path(detached_envs_folder).joinpath("envs", "default", "conda-meta").exists()
ruben-arts marked this conversation as resolved.
Show resolved Hide resolved

# Verify that the detached environment is used
verify_cli_command(
[pixi, "run", "--manifest-path", manifest, "env"],
stdout_contains="CONDA_PREFIX=/tmp/pixi-detached-envs",
)
Loading