-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathmanager.rs
More file actions
101 lines (91 loc) · 3.33 KB
/
manager.rs
File metadata and controls
101 lines (91 loc) · 3.33 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use log::trace;
use pet_core::manager::{EnvManager, EnvManagerType};
use std::{env, path::PathBuf};
use crate::env_variables::EnvVariables;
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct PipenvManager {
pub executable: PathBuf,
}
impl PipenvManager {
pub fn find(executable: Option<PathBuf>, env_variables: &EnvVariables) -> Option<Self> {
// If an explicit executable path is provided, check if it exists
if let Some(executable) = executable {
if executable.is_file() {
return Some(PipenvManager { executable });
}
}
// Search in common installation locations
if let Some(home) = &env_variables.home {
let mut search_paths = vec![
// pip install --user pipenv on Linux/macOS
home.join(".local").join("bin").join("pipenv"),
// pipx install pipenv
home.join(".local")
.join("pipx")
.join("venvs")
.join("pipenv")
.join("bin")
.join("pipenv"),
];
if std::env::consts::OS == "windows" {
// pip install --user pipenv on Windows
search_paths.push(
home.join("AppData")
.join("Roaming")
.join("Python")
.join("Scripts")
.join("pipenv.exe"),
);
// Another common Windows location
search_paths.push(
home.join("AppData")
.join("Local")
.join("Programs")
.join("Python")
.join("Scripts")
.join("pipenv.exe"),
);
// pipx on Windows
search_paths.push(
home.join(".local")
.join("pipx")
.join("venvs")
.join("pipenv")
.join("Scripts")
.join("pipenv.exe"),
);
}
for executable in search_paths {
if executable.is_file() {
return Some(PipenvManager { executable });
}
}
// Look for pipenv in current PATH
if let Some(env_path) = &env_variables.path {
for each in env::split_paths(env_path) {
let executable = each.join("pipenv");
if executable.is_file() {
return Some(PipenvManager { executable });
}
if std::env::consts::OS == "windows" {
let executable = each.join("pipenv.exe");
if executable.is_file() {
return Some(PipenvManager { executable });
}
}
}
}
}
trace!("Pipenv exe not found");
None
}
pub fn to_manager(&self) -> EnvManager {
EnvManager {
executable: self.executable.clone(),
version: None,
tool: EnvManagerType::Pipenv,
}
}
}