Remove special casing for base and default conda environment names (#17758)

Under the `special-conda-env-names` preview feature, instead, just using
our path-based logic.

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Zanie Blue
2026-02-01 06:09:48 -06:00
committed by GitHub
parent ad3ad2210c
commit f5fcf93deb
5 changed files with 60 additions and 14 deletions
+12 -6
View File
@@ -8,6 +8,7 @@ use std::{
use fs_err as fs;
use thiserror::Error;
use uv_preview::{Preview, PreviewFeature};
use uv_pypi_types::Scheme;
use uv_static::EnvVars;
@@ -85,7 +86,7 @@ impl CondaEnvironmentKind {
/// name, e.g., `base`, which does not match the `CONDA_PREFIX`, e.g., `/usr/local` instead of
/// `/usr/local/conda/envs/<name>`. Note the name `CONDA_DEFAULT_ENV` is misleading, it's the
/// active environment name, not a constant base environment name.
fn from_prefix_path(path: &Path) -> Self {
fn from_prefix_path(path: &Path, preview: Preview) -> Self {
// Pixi never creates true "base" envs and names project envs "default", confusing our
// heuristics, so treat Pixi prefixes as child envs outright.
if is_pixi_environment(path) {
@@ -113,8 +114,10 @@ impl CondaEnvironmentKind {
// If the environment name is "base" or "root", treat it as a base environment
//
// These are the expected names for the base environment; and is retained for backwards
// compatibility, but in a future breaking release we should remove this special-casing.
if current_env == "base" || current_env == "root" {
// compatibility, but can be removed with the `special-conda-env-names` preview feature.
if !preview.is_enabled(PreviewFeature::SpecialCondaEnvNames)
&& (current_env == "base" || current_env == "root")
{
return Self::Base;
}
@@ -142,11 +145,14 @@ fn is_pixi_environment(path: &Path) -> bool {
///
/// If `base` is true, the active environment must be the base environment or `None` is returned,
/// and vice-versa.
pub(crate) fn conda_environment_from_env(kind: CondaEnvironmentKind) -> Option<PathBuf> {
pub(crate) fn conda_environment_from_env(
kind: CondaEnvironmentKind,
preview: Preview,
) -> Option<PathBuf> {
let dir = env::var_os(EnvVars::CONDA_PREFIX).filter(|value| !value.is_empty())?;
let path = PathBuf::from(dir);
if kind != CondaEnvironmentKind::from_prefix_path(&path) {
if kind != CondaEnvironmentKind::from_prefix_path(&path, preview) {
return None;
}
@@ -353,7 +359,7 @@ mod tests {
with_vars(vars, || {
assert_eq!(
CondaEnvironmentKind::from_prefix_path(prefix),
CondaEnvironmentKind::from_prefix_path(prefix, Preview::default()),
CondaEnvironmentKind::Child
);
});