Skip to content

Commit

Permalink
Improve logging during interpreter discovery
Browse files Browse the repository at this point in the history
# Conflicts:
#	crates/uv-interpreter/src/discovery.rs
  • Loading branch information
zanieb committed May 23, 2024
1 parent 306a4d7 commit 9953082
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
12 changes: 9 additions & 3 deletions crates/uv-interpreter/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ fn python_interpreters<'a>(
Ok((source, path)) => Interpreter::query(&path, cache)
.map(|interpreter| (source, interpreter))
.inspect(|(source, interpreter)| {
trace!(
"Found Python interpreter {} {} at {} from {source}",
debug!(
"Found {} {} at `{}` ({source})",
LenientImplementationName::from(interpreter.implementation_name()),
interpreter.python_full_version(),
path.display()
Expand Down Expand Up @@ -456,9 +456,9 @@ pub fn find_interpreter(
sources: &SourceSelector,
cache: &Cache,
) -> Result<InterpreterResult, Error> {
debug!("Searching for interpreter that fulfills {request}");
let result = match request {
InterpreterRequest::File(path) => {
debug!("Checking for Python interpreter at {request}");
if !sources.contains(InterpreterSource::ProvidedPath) {
return Err(Error::SourceNotSelected(
request.clone(),
Expand All @@ -476,6 +476,7 @@ pub fn find_interpreter(
}
}
InterpreterRequest::Directory(path) => {
debug!("Checking for Python interpreter in {request}");
if !sources.contains(InterpreterSource::ProvidedPath) {
return Err(Error::SourceNotSelected(
request.clone(),
Expand All @@ -499,6 +500,7 @@ pub fn find_interpreter(
}
}
InterpreterRequest::ExecutableName(name) => {
debug!("Searching for Python interpreter with {request}");
if !sources.contains(InterpreterSource::SearchPath) {
return Err(Error::SourceNotSelected(
request.clone(),
Expand All @@ -516,6 +518,7 @@ pub fn find_interpreter(
}
}
InterpreterRequest::Implementation(implementation) => {
debug!("Searching for {request} in {sources}");
let Some((source, interpreter)) =
python_interpreters(None, Some(implementation), system, sources, cache)
.find(|result| {
Expand All @@ -539,6 +542,7 @@ pub fn find_interpreter(
}
}
InterpreterRequest::ImplementationVersion(implementation, version) => {
debug!("Searching for {request} in {sources}");
let Some((source, interpreter)) =
python_interpreters(Some(version), Some(implementation), system, sources, cache)
.find(|result| {
Expand Down Expand Up @@ -569,6 +573,7 @@ pub fn find_interpreter(
}
}
InterpreterRequest::Any => {
debug!("Searching for Python interpreter in {sources}");
let Some((source, interpreter)) =
python_interpreters(None, None, system, sources, cache)
.find(|result| {
Expand All @@ -590,6 +595,7 @@ pub fn find_interpreter(
}
}
InterpreterRequest::Version(version) => {
debug!("Searching for {request} in {sources}");
let Some((source, interpreter)) =
python_interpreters(Some(version), None, system, sources, cache)
.find(|result| {
Expand Down
11 changes: 7 additions & 4 deletions crates/uv-interpreter/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ impl PythonEnvironment {
Self::from_default_python(cache)
} else {
// First check for a parent intepreter
match Self::from_parent_interpreter(system, cache) {
Ok(env) => return Ok(env),
Err(Error::NotFound(_)) => {}
Err(err) => return Err(err),
// We gate this check to avoid an extra log message when it is not set
if std::env::var_os("UV_INTERNAL__PARENT_INTERPRETER").is_some() {
match Self::from_parent_interpreter(system, cache) {
Ok(env) => return Ok(env),
Err(Error::NotFound(_)) => {}
Err(err) => return Err(err),
}
}

// Then a virtual environment
Expand Down
11 changes: 0 additions & 11 deletions crates/uv-interpreter/src/virtualenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::{
use fs_err as fs;
use pypi_types::Scheme;
use thiserror::Error;
use tracing::{debug, info};

/// The layout of a virtual environment.
#[derive(Debug)]
Expand Down Expand Up @@ -46,10 +45,6 @@ pub enum Error {
/// Supports `VIRTUAL_ENV`.
pub(crate) fn virtualenv_from_env() -> Option<PathBuf> {
if let Some(dir) = env::var_os("VIRTUAL_ENV").filter(|value| !value.is_empty()) {
info!(
"Found active virtual environment (via VIRTUAL_ENV) at: {}",
Path::new(&dir).display()
);
return Some(PathBuf::from(dir));
}

Expand All @@ -61,10 +56,6 @@ pub(crate) fn virtualenv_from_env() -> Option<PathBuf> {
/// Supports `CONDA_PREFIX`.
pub(crate) fn conda_prefix_from_env() -> Option<PathBuf> {
if let Some(dir) = env::var_os("CONDA_PREFIX").filter(|value| !value.is_empty()) {
info!(
"Found active virtual environment (via CONDA_PREFIX) at: {}",
Path::new(&dir).display()
);
return Some(PathBuf::from(dir));
}

Expand All @@ -82,7 +73,6 @@ pub(crate) fn virtualenv_from_working_dir() -> Result<Option<PathBuf>, Error> {
for dir in current_dir.ancestors() {
// If we're _within_ a virtualenv, return it.
if dir.join("pyvenv.cfg").is_file() {
debug!("Found a virtual environment at: {}", dir.display());
return Ok(Some(dir.to_path_buf()));
}

Expand All @@ -92,7 +82,6 @@ pub(crate) fn virtualenv_from_working_dir() -> Result<Option<PathBuf>, Error> {
if !dot_venv.join("pyvenv.cfg").is_file() {
return Err(Error::MissingPyVenvCfg(dot_venv));
}
debug!("Found a virtual environment at: {}", dot_venv.display());
return Ok(Some(dot_venv));
}
}
Expand Down

0 comments on commit 9953082

Please sign in to comment.