-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathlib.rs
More file actions
67 lines (59 loc) · 1.97 KB
/
lib.rs
File metadata and controls
67 lines (59 loc) · 1.97 KB
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use env_variables::EnvVariables;
use environments::{get_project, is_virtualenvwrapper};
use pet_core::{
os_environment::Environment,
python_environment::{PythonEnvironment, PythonEnvironmentBuilder, PythonEnvironmentCategory},
reporter::Reporter,
Locator,
};
use pet_python_utils::version;
use pet_python_utils::{env::PythonEnv, executable::find_executables};
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_name(&self) -> &'static str {
"VirtualEnvWrapper"
}
fn supported_categories(&self) -> Vec<PythonEnvironmentCategory> {
vec![PythonEnvironmentCategory::VirtualEnvWrapper]
}
fn 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![];
if let Some(ref prefix) = env.prefix {
symlinks.append(&mut find_executables(prefix));
}
Some(
PythonEnvironmentBuilder::new(PythonEnvironmentCategory::VirtualEnvWrapper)
.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) {}
}