diff --git a/crates/uv-interpreter/src/lib.rs b/crates/uv-interpreter/src/lib.rs index 255c5d076..535888a78 100644 --- a/crates/uv-interpreter/src/lib.rs +++ b/crates/uv-interpreter/src/lib.rs @@ -33,8 +33,6 @@ mod virtualenv; pub enum Error { #[error("Expected `{0}` to be a virtualenv, but `pyvenv.cfg` is missing")] MissingPyVenvCfg(PathBuf), - #[error("Both VIRTUAL_ENV and CONDA_PREFIX are set. Please unset one of them.")] - Conflict, #[error("No versions of Python could be found. Is Python installed?")] PythonNotFound, #[error("Failed to locate a virtualenv or Conda environment (checked: `VIRTUAL_ENV`, `CONDA_PREFIX`, and `.venv`). Run `uv venv` to create a virtualenv.")] diff --git a/crates/uv-interpreter/src/python_environment.rs b/crates/uv-interpreter/src/python_environment.rs index 275738378..c60a97d93 100644 --- a/crates/uv-interpreter/src/python_environment.rs +++ b/crates/uv-interpreter/src/python_environment.rs @@ -1,7 +1,7 @@ use std::env; use std::path::{Path, PathBuf}; -use tracing::debug; +use tracing::{debug, info}; use uv_cache::Cache; use uv_fs::{LockedFile, Simplified}; @@ -124,32 +124,20 @@ impl PythonEnvironment { /// Locate the current virtual environment. pub(crate) fn detect_virtual_env() -> Result, Error> { - match ( - env::var_os("VIRTUAL_ENV").filter(|value| !value.is_empty()), - env::var_os("CONDA_PREFIX").filter(|value| !value.is_empty()), - ) { - (Some(dir), None) => { - debug!( - "Found a virtualenv through VIRTUAL_ENV at: {}", - Path::new(&dir).display() - ); - return Ok(Some(PathBuf::from(dir))); - } - (None, Some(dir)) => { - debug!( - "Found a virtualenv through CONDA_PREFIX at: {}", - Path::new(&dir).display() - ); - return Ok(Some(PathBuf::from(dir))); - } - (Some(venv), Some(conda)) if venv == conda => return Ok(Some(PathBuf::from(venv))), - (Some(_), Some(_)) => { - return Err(Error::Conflict); - } - (None, None) => { - // No environment variables set. Try to find a virtualenv in the current directory. - } - }; + if let Some(dir) = env::var_os("VIRTUAL_ENV").filter(|value| !value.is_empty()) { + info!( + "Found a virtualenv through VIRTUAL_ENV at: {}", + Path::new(&dir).display() + ); + return Ok(Some(PathBuf::from(dir))); + } + if let Some(dir) = env::var_os("CONDA_PREFIX").filter(|value| !value.is_empty()) { + info!( + "Found a virtualenv through CONDA_PREFIX at: {}", + Path::new(&dir).display() + ); + return Ok(Some(PathBuf::from(dir))); + } // Search for a `.venv` directory in the current or any parent directory. let current_dir = env::current_dir().expect("Failed to detect current directory");