From 8ca5716c188e848512c618261484594f9f69df44 Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Fri, 4 Oct 2024 23:13:12 +0200 Subject: [PATCH 1/4] increase pyenv compatybility --- crates/uv-python/src/discovery.rs | 10 ++++++++++ crates/uv-python/src/version_files.rs | 1 + 2 files changed, 11 insertions(+) diff --git a/crates/uv-python/src/discovery.rs b/crates/uv-python/src/discovery.rs index 636ff0f94..27e573d6b 100644 --- a/crates/uv-python/src/discovery.rs +++ b/crates/uv-python/src/discovery.rs @@ -1309,6 +1309,16 @@ impl PythonRequest { if let Ok(request) = PythonDownloadRequest::from_str(value) { return Self::Key(request); } + // Check if the value is current active pyenv virtualenv + // It mean that name is end of path provided by PYENV_VIRTUAL_ENV variable + if let Some(pyenv_virtual_env) = std::env::var_os("PYENV_VIRTUAL_ENV") { + if let Some(pyenv_virtual_env) = pyenv_virtual_env.to_str() { + if value == Path::new(pyenv_virtual_env).file_name().unwrap().to_str().unwrap() { + return Self::Directory(PathBuf::from(pyenv_virtual_env)); + } + } + } + // Finally, we'll treat it as the name of an executable (i.e. in the search PATH) // e.g. foo.exe Self::ExecutableName(value.to_string()) diff --git a/crates/uv-python/src/version_files.rs b/crates/uv-python/src/version_files.rs index b697f0cce..4fc6c169d 100644 --- a/crates/uv-python/src/version_files.rs +++ b/crates/uv-python/src/version_files.rs @@ -70,6 +70,7 @@ impl PythonVersionFile { let trimmed = line.trim(); !(trimmed.is_empty() || trimmed.starts_with('#')) }) + .flat_map(|line| line.split_whitespace()) .map(ToString::to_string) .map(|version| PythonRequest::parse(&version)) .collect(); From 2fc67f88b59fcb0a9b196e98a636c97e6aff62e6 Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Fri, 4 Oct 2024 23:33:28 +0200 Subject: [PATCH 2/4] fix formating --- crates/uv-python/src/discovery.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/uv-python/src/discovery.rs b/crates/uv-python/src/discovery.rs index 27e573d6b..f3b5acfcf 100644 --- a/crates/uv-python/src/discovery.rs +++ b/crates/uv-python/src/discovery.rs @@ -1313,7 +1313,13 @@ impl PythonRequest { // It mean that name is end of path provided by PYENV_VIRTUAL_ENV variable if let Some(pyenv_virtual_env) = std::env::var_os("PYENV_VIRTUAL_ENV") { if let Some(pyenv_virtual_env) = pyenv_virtual_env.to_str() { - if value == Path::new(pyenv_virtual_env).file_name().unwrap().to_str().unwrap() { + if value + == Path::new(pyenv_virtual_env) + .file_name() + .unwrap() + .to_str() + .unwrap() + { return Self::Directory(PathBuf::from(pyenv_virtual_env)); } } From ca308a746205d8790b129578f93e9f00c7695a81 Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Fri, 4 Oct 2024 23:35:03 +0200 Subject: [PATCH 3/4] fix formating 2 --- crates/uv-python/src/discovery.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/uv-python/src/discovery.rs b/crates/uv-python/src/discovery.rs index f3b5acfcf..2d5f8d4b7 100644 --- a/crates/uv-python/src/discovery.rs +++ b/crates/uv-python/src/discovery.rs @@ -1315,10 +1315,10 @@ impl PythonRequest { if let Some(pyenv_virtual_env) = pyenv_virtual_env.to_str() { if value == Path::new(pyenv_virtual_env) - .file_name() - .unwrap() - .to_str() - .unwrap() + .file_name() + .unwrap() + .to_str() + .unwrap() { return Self::Directory(PathBuf::from(pyenv_virtual_env)); } From 35fed182fcb8f6dca04a1be1ef9c8be97af01016 Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Mon, 7 Oct 2024 08:31:08 +0200 Subject: [PATCH 4/4] Update crates/uv-python/src/version_files.rs --- crates/uv-python/src/version_files.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/uv-python/src/version_files.rs b/crates/uv-python/src/version_files.rs index 4fc6c169d..b697f0cce 100644 --- a/crates/uv-python/src/version_files.rs +++ b/crates/uv-python/src/version_files.rs @@ -70,7 +70,6 @@ impl PythonVersionFile { let trimmed = line.trim(); !(trimmed.is_empty() || trimmed.starts_with('#')) }) - .flat_map(|line| line.split_whitespace()) .map(ToString::to_string) .map(|version| PythonRequest::parse(&version)) .collect();