diff --git a/crates/pet-utils/src/path.rs b/crates/pet-utils/src/path.rs index 6af051c0..2d965bd4 100644 --- a/crates/pet-utils/src/path.rs +++ b/crates/pet-utils/src/path.rs @@ -1,18 +1,18 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use std::{ - fs, - path::{Path, PathBuf}, -}; +use std::path::{Path, PathBuf}; // Similar to fs::canonicalize, but ignores UNC paths and returns the path as is (for windows). pub fn normalize>(path: P) -> PathBuf { // On unix do not use canonicalize, results in weird issues with homebrew paths - if cfg!(unix) { - return path.as_ref().to_path_buf(); - } + #[cfg(unix)] + return path.as_ref().to_path_buf(); + + #[cfg(windows)] + use std::fs; + #[cfg(windows)] if let Ok(resolved) = fs::canonicalize(&path) { if cfg!(unix) { return resolved; diff --git a/crates/pet-venv/src/lib.rs b/crates/pet-venv/src/lib.rs index c57a7c2a..6db9e724 100644 --- a/crates/pet-venv/src/lib.rs +++ b/crates/pet-venv/src/lib.rs @@ -5,7 +5,7 @@ use pet_core::{ python_environment::{PythonEnvironment, PythonEnvironmentBuilder, PythonEnvironmentCategory}, Locator, LocatorResult, }; -use pet_utils::{env::PythonEnv, pyvenv_cfg::PyVenvCfg}; +use pet_utils::{env::PythonEnv, headers::Headers, pyvenv_cfg::PyVenvCfg}; fn is_venv_internal(env: &PythonEnv) -> Option { // env path cannot be empty. @@ -40,12 +40,18 @@ impl Locator for Venv { if let Some(filename) = &env.prefix { name = filename.to_str().map(|f| f.to_string()); } - + let version = match env.version { + Some(ref v) => Some(v.clone()), + None => match &env.prefix { + Some(prefix) => Headers::get_version(prefix), + None => None, + }, + }; Some( PythonEnvironmentBuilder::new(PythonEnvironmentCategory::Venv) .name(name) .executable(Some(env.executable.clone())) - .version(env.version.clone()) + .version(version) .prefix(env.prefix.clone()) .build(), ) diff --git a/crates/pet-virtualenv/src/lib.rs b/crates/pet-virtualenv/src/lib.rs index c95e62b8..17e699b9 100644 --- a/crates/pet-virtualenv/src/lib.rs +++ b/crates/pet-virtualenv/src/lib.rs @@ -7,7 +7,7 @@ use pet_core::{ python_environment::{PythonEnvironment, PythonEnvironmentBuilder, PythonEnvironmentCategory}, Locator, LocatorResult, }; -use pet_utils::env::PythonEnv; +use pet_utils::{env::PythonEnv, headers::Headers}; pub fn is_virtualenv(env: &PythonEnv) -> bool { if env.prefix.is_none() { @@ -70,12 +70,19 @@ impl Locator for VirtualEnv { if let Some(filename) = &env.prefix { name = filename.to_str().map(|f| f.to_string()); } + let version = match env.version { + Some(ref v) => Some(v.clone()), + None => match &env.prefix { + Some(prefix) => Headers::get_version(prefix), + None => None, + }, + }; Some( PythonEnvironmentBuilder::new(PythonEnvironmentCategory::VirtualEnv) .name(name) .executable(Some(env.executable.clone())) - .version(env.version.clone()) + .version(version) .prefix(env.prefix.clone()) .build(), ) diff --git a/crates/pet-virtualenvwrapper/src/lib.rs b/crates/pet-virtualenvwrapper/src/lib.rs index 319333d1..0f44a359 100644 --- a/crates/pet-virtualenvwrapper/src/lib.rs +++ b/crates/pet-virtualenvwrapper/src/lib.rs @@ -9,7 +9,7 @@ use pet_core::{ python_environment::{PythonEnvironment, PythonEnvironmentBuilder, PythonEnvironmentCategory}, Locator, LocatorResult, }; -use pet_utils::env::PythonEnv; +use pet_utils::{env::PythonEnv, headers::Headers}; mod env_variables; mod environment_locations; @@ -36,12 +36,19 @@ impl Locator for VirtualEnvWrapper { if let Some(filename) = &env.prefix { name = filename.to_str().map(|f| f.to_string()); } + let version = match env.version { + Some(ref v) => Some(v.clone()), + None => match &env.prefix { + Some(prefix) => Headers::get_version(prefix), + None => None, + }, + }; Some( PythonEnvironmentBuilder::new(PythonEnvironmentCategory::VirtualEnvWrapper) .name(name) .executable(Some(env.executable.clone())) - .version(env.version.clone()) + .version(version) .prefix(env.prefix.clone()) .project(get_project(env)) .build(),