forked from microsoft/python-environment-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
71 lines (63 loc) · 2.13 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use env_variables::EnvVariables;
use environments::{get_project, is_virtualenvwrapper};
use pet_core::{
env::PythonEnv,
os_environment::Environment,
python_environment::{PythonEnvironment, PythonEnvironmentBuilder, PythonEnvironmentKind},
reporter::Reporter,
Locator, LocatorKind,
};
use pet_python_utils::executable::find_executables;
use pet_python_utils::version;
mod env_variables;
mod environment_locations;
mod environments;
pub struct VirtualEnvWrapper {
pub env_vars: EnvVariables,
}
impl VirtualEnvWrapper {
pub fn from(environment: &dyn Environment) -> VirtualEnvWrapper {
VirtualEnvWrapper {
env_vars: EnvVariables::from(environment),
}
}
}
impl Locator for VirtualEnvWrapper {
fn get_kind(&self) -> LocatorKind {
LocatorKind::VirtualEnvWrapper
}
fn supported_categories(&self) -> Vec<PythonEnvironmentKind> {
vec![PythonEnvironmentKind::VirtualEnvWrapper]
}
fn try_from(&self, env: &PythonEnv) -> Option<PythonEnvironment> {
if !is_virtualenvwrapper(env, &self.env_vars) {
return None;
}
let version = match env.version {
Some(ref v) => Some(v.clone()),
None => match &env.prefix {
Some(prefix) => version::from_creator_for_virtual_env(prefix),
None => None,
},
};
let mut symlinks = vec![];
let mut name = None;
if let Some(ref prefix) = env.prefix {
symlinks.append(&mut find_executables(prefix));
name = prefix.file_name().and_then(|f| f.to_str());
}
Some(
PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::VirtualEnvWrapper))
.name(name.map(String::from))
.executable(Some(env.executable.clone()))
.version(version)
.prefix(env.prefix.clone())
.project(get_project(env))
.symlinks(Some(symlinks))
.build(),
)
}
fn find(&self, _reporter: &dyn Reporter) {}
}