Skip to content

Updates to extraction of version #20

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

Merged
merged 2 commits into from
Jun 6, 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
14 changes: 7 additions & 7 deletions crates/pet-utils/src/path.rs
Original file line number Diff line number Diff line change
@@ -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<P: AsRef<Path>>(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;
Expand Down
12 changes: 9 additions & 3 deletions crates/pet-venv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
// env path cannot be empty.
Expand Down Expand Up @@ -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(),
)
Expand Down
11 changes: 9 additions & 2 deletions crates/pet-virtualenv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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(),
)
Expand Down
11 changes: 9 additions & 2 deletions crates/pet-virtualenvwrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand Down
Loading