mirror of https://github.com/astral-sh/uv
Add handling for unnamed conda environments in base environment detection (#15681)
While investigating https://github.com/astral-sh/uv/pull/15679, I created an unnamed conda environment and noticed this quality which allows us to detect that it's not the base environment.
This commit is contained in:
parent
1943aba150
commit
d5012c66bd
|
|
@ -1337,6 +1337,36 @@ mod tests {
|
||||||
"Non-base conda environment should be available for virtual environment preference"
|
"Non-base conda environment should be available for virtual environment preference"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// When CONDA_PREFIX equals CONDA_DEFAULT_ENV, it should be treated as a virtual environment
|
||||||
|
let unnamed_env = context.tempdir.child("my-conda-env");
|
||||||
|
TestContext::mock_conda_prefix(&unnamed_env, "3.12.4")?;
|
||||||
|
let unnamed_env_path = unnamed_env.to_string_lossy().to_string();
|
||||||
|
|
||||||
|
let python = context.run_with_vars(
|
||||||
|
&[
|
||||||
|
(EnvVars::CONDA_PREFIX, Some(unnamed_env.as_os_str())),
|
||||||
|
(
|
||||||
|
EnvVars::CONDA_DEFAULT_ENV,
|
||||||
|
Some(&OsString::from(&unnamed_env_path)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
|| {
|
||||||
|
find_python_installation(
|
||||||
|
&PythonRequest::Default,
|
||||||
|
EnvironmentPreference::OnlyVirtual,
|
||||||
|
PythonPreference::OnlySystem,
|
||||||
|
&context.cache,
|
||||||
|
Preview::default(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)??;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
python.interpreter().python_full_version().to_string(),
|
||||||
|
"3.12.4",
|
||||||
|
"We should find the unnamed conda environment"
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,12 @@ impl CondaEnvironmentKind {
|
||||||
return Self::Child;
|
return Self::Child;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If the `CONDA_PREFIX` equals the `CONDA_DEFAULT_ENV`, we're in an unnamed environment
|
||||||
|
// which is typical for environments created with `conda create -p /path/to/env`.
|
||||||
|
if path == Path::new(¤t_env) {
|
||||||
|
return Self::Child;
|
||||||
|
}
|
||||||
|
|
||||||
// These are the expected names for the base environment; we may want to remove this
|
// These are the expected names for the base environment; we may want to remove this
|
||||||
// restriction in the future as it's not strictly necessary.
|
// restriction in the future as it's not strictly necessary.
|
||||||
if current_env != "base" && current_env != "root" {
|
if current_env != "base" && current_env != "root" {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue