-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathmanager.rs
More file actions
78 lines (71 loc) · 2.04 KB
/
manager.rs
File metadata and controls
78 lines (71 loc) · 2.04 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub enum EnvManagerType {
Conda,
Pipenv,
Poetry,
Pyenv,
}
impl Ord for EnvManagerType {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
format!("{self:?}").cmp(&format!("{other:?}"))
}
}
impl PartialOrd for EnvManagerType {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
#[derive(Debug)]
pub struct EnvManager {
pub executable: PathBuf,
pub version: Option<String>,
pub tool: EnvManagerType,
}
impl Ord for EnvManager {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
match self.executable.cmp(&other.executable) {
std::cmp::Ordering::Equal => {}
ord => return ord,
}
match self.version.cmp(&other.version) {
std::cmp::Ordering::Equal => {}
ord => return ord,
}
self.tool.cmp(&other.tool)
}
}
impl PartialOrd for EnvManager {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl EnvManager {
pub fn new(executable_path: PathBuf, tool: EnvManagerType, version: Option<String>) -> Self {
Self {
executable: executable_path,
version,
tool,
}
}
}
impl std::fmt::Display for EnvManager {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
writeln!(f, "Manager ({:?})", self.tool).unwrap_or_default();
writeln!(
f,
" Executable : {}",
self.executable.to_str().unwrap_or_default()
)
.unwrap_or_default();
if let Some(version) = &self.version {
writeln!(f, " Version : {version}").unwrap_or_default();
}
Ok(())
}
}