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

Improve logging during interpreter discovery #3790

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 13 additions & 7 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 a {request} interpreter 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 Expand Up @@ -1186,15 +1192,15 @@ impl fmt::Display for InterpreterRequest {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Any => write!(f, "any Python"),
Self::Version(version) => write!(f, "Python @ {version}"),
Self::Directory(path) => write!(f, "directory {}", path.user_display()),
Self::File(path) => write!(f, "file {}", path.user_display()),
Self::Version(version) => write!(f, "Python {version}"),
Self::Directory(path) => write!(f, "directory `{}`", path.user_display()),
Self::File(path) => write!(f, "path `{}`", path.user_display()),
Self::ExecutableName(name) => write!(f, "executable name `{name}`"),
Self::Implementation(implementation) => {
write!(f, "{implementation}")
}
Self::ImplementationVersion(implementation, version) => {
write!(f, "{implementation} @ {version}")
write!(f, "{implementation} {version}")
}
}
}
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
Loading