Skip to content

Commit 7a1f006

Browse files
authored
Rename category to kind (#91)
1 parent 3ba3d26 commit 7a1f006

File tree

37 files changed

+192
-200
lines changed

37 files changed

+192
-200
lines changed

crates/pet-conda/src/environments.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use log::warn;
1010
use pet_core::{
1111
arch::Architecture,
1212
manager::EnvManager,
13-
python_environment::{PythonEnvironment, PythonEnvironmentBuilder, PythonEnvironmentCategory},
13+
python_environment::{PythonEnvironment, PythonEnvironmentBuilder, PythonEnvironmentKind},
1414
};
1515
use pet_fs::path::{norm_case, resolve_symlink};
1616
use pet_python_utils::executable::{find_executable, find_executables};
@@ -57,7 +57,7 @@ impl CondaEnvironment {
5757
}
5858
}
5959
// This is a root env.
60-
let builder = PythonEnvironmentBuilder::new(PythonEnvironmentCategory::Conda)
60+
let builder = PythonEnvironmentBuilder::new(PythonEnvironmentKind::Conda)
6161
.executable(self.executable.clone())
6262
.version(self.version.clone())
6363
.prefix(Some(self.prefix.clone()))

crates/pet-conda/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use log::{error, warn};
99
use manager::CondaManager;
1010
use pet_core::{
1111
os_environment::Environment,
12-
python_environment::{PythonEnvironment, PythonEnvironmentCategory},
12+
python_environment::{PythonEnvironment, PythonEnvironmentKind},
1313
reporter::Reporter,
1414
Locator, LocatorResult,
1515
};
@@ -149,8 +149,8 @@ impl Locator for Conda {
149149
fn get_name(&self) -> &'static str {
150150
"Conda"
151151
}
152-
fn supported_categories(&self) -> Vec<PythonEnvironmentCategory> {
153-
vec![PythonEnvironmentCategory::Conda]
152+
fn supported_categories(&self) -> Vec<PythonEnvironmentKind> {
153+
vec![PythonEnvironmentKind::Conda]
154154
}
155155
fn try_from(&self, env: &PythonEnv) -> Option<PythonEnvironment> {
156156
// Possible we do not have the prefix, but this exe is in the bin directory and its a conda env or root conda install.

crates/pet-conda/tests/ci_test.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn detect_conda_root() {
2626
use pet_conda::Conda;
2727
use pet_core::{
2828
manager::EnvManagerType, os_environment::EnvironmentApi,
29-
python_environment::PythonEnvironmentCategory, Locator,
29+
python_environment::PythonEnvironmentKind, Locator,
3030
};
3131
use pet_reporter::test::create_reporter;
3232

@@ -54,7 +54,7 @@ fn detect_conda_root() {
5454
.unwrap();
5555
assert_eq!(env.prefix, conda_dir.clone().into());
5656
assert_eq!(env.name, Some("base".into()));
57-
assert_eq!(env.category, PythonEnvironmentCategory::Conda);
57+
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
5858
assert_eq!(env.executable, Some(conda_dir.join("bin").join("python")));
5959
assert_eq!(env.version, Some(get_version(&info.python_version)));
6060

@@ -69,7 +69,7 @@ fn detect_conda_root_from_path() {
6969
use pet_conda::Conda;
7070
use pet_core::{
7171
manager::EnvManagerType, os_environment::EnvironmentApi,
72-
python_environment::PythonEnvironmentCategory, Locator,
72+
python_environment::PythonEnvironmentKind, Locator,
7373
};
7474
use pet_python_utils::env::PythonEnv;
7575
use std::path::PathBuf;
@@ -93,7 +93,7 @@ fn detect_conda_root_from_path() {
9393

9494
assert_eq!(env.prefix, conda_dir.clone().into());
9595
assert_eq!(env.name, Some("base".into()));
96-
assert_eq!(env.category, PythonEnvironmentCategory::Conda);
96+
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
9797
assert_eq!(env.executable, Some(conda_dir.join("bin").join("python")));
9898
assert_eq!(env.version, Some(get_version(&info.python_version)));
9999
}
@@ -105,7 +105,7 @@ fn detect_conda_root_from_path() {
105105
fn detect_new_conda_env() {
106106
use pet_conda::Conda;
107107
use pet_core::{
108-
os_environment::EnvironmentApi, python_environment::PythonEnvironmentCategory, Locator,
108+
os_environment::EnvironmentApi, python_environment::PythonEnvironmentKind, Locator,
109109
};
110110
use pet_reporter::test::create_reporter;
111111
use std::path::PathBuf;
@@ -144,7 +144,7 @@ fn detect_new_conda_env() {
144144
let prefix = conda_dir.clone().join("envs").join(env_name);
145145
assert_eq!(env.prefix, prefix.clone().into());
146146
assert_eq!(env.name, Some(env_name.into()));
147-
assert_eq!(env.category, PythonEnvironmentCategory::Conda);
147+
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
148148
assert_eq!(env.executable, prefix.join("bin").join("python").into());
149149
assert!(
150150
env.version.clone().unwrap_or_default().starts_with("3.10"),
@@ -163,7 +163,7 @@ fn detect_conda_env_from_path() {
163163
use pet_conda::Conda;
164164
use pet_core::{
165165
manager::EnvManagerType, os_environment::EnvironmentApi,
166-
python_environment::PythonEnvironmentCategory, Locator,
166+
python_environment::PythonEnvironmentKind, Locator,
167167
};
168168
use pet_python_utils::env::PythonEnv;
169169
use std::path::PathBuf;
@@ -193,7 +193,7 @@ fn detect_conda_env_from_path() {
193193

194194
assert_eq!(env.prefix, prefix.clone().into());
195195
assert_eq!(env.name, Some(env_name.into()));
196-
assert_eq!(env.category, PythonEnvironmentCategory::Conda);
196+
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
197197
assert_eq!(env.executable, exe.clone().into());
198198
assert!(
199199
env.version.clone().unwrap_or_default().starts_with("3.10"),
@@ -209,7 +209,7 @@ fn detect_conda_env_from_path() {
209209
fn detect_new_conda_env_without_python() {
210210
use pet_conda::Conda;
211211
use pet_core::{
212-
os_environment::EnvironmentApi, python_environment::PythonEnvironmentCategory, Locator,
212+
os_environment::EnvironmentApi, python_environment::PythonEnvironmentKind, Locator,
213213
};
214214
use pet_reporter::test::create_reporter;
215215
use std::path::PathBuf;
@@ -245,7 +245,7 @@ fn detect_new_conda_env_without_python() {
245245
let prefix = conda_dir.clone().join("envs").join(env_name);
246246
assert_eq!(env.prefix, prefix.clone().into());
247247
assert_eq!(env.name, Some(env_name.into()));
248-
assert_eq!(env.category, PythonEnvironmentCategory::Conda);
248+
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
249249
assert_eq!(env.executable.is_none(), true);
250250
assert_eq!(env.version.is_none(), true);
251251

@@ -260,7 +260,7 @@ fn detect_new_conda_env_created_with_p_flag_without_python() {
260260
use common::resolve_test_path;
261261
use pet_conda::Conda;
262262
use pet_core::{
263-
os_environment::EnvironmentApi, python_environment::PythonEnvironmentCategory, Locator,
263+
os_environment::EnvironmentApi, python_environment::PythonEnvironmentKind, Locator,
264264
};
265265
use pet_reporter::test::create_reporter;
266266

@@ -293,7 +293,7 @@ fn detect_new_conda_env_created_with_p_flag_without_python() {
293293

294294
assert_eq!(env.prefix, prefix.clone().into());
295295
assert_eq!(env.name, None);
296-
assert_eq!(env.category, PythonEnvironmentCategory::Conda);
296+
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
297297
assert_eq!(env.executable.is_none(), true);
298298
assert_eq!(env.version.is_none(), true);
299299

@@ -308,7 +308,7 @@ fn detect_new_conda_env_created_with_p_flag_with_python() {
308308
use common::resolve_test_path;
309309
use pet_conda::Conda;
310310
use pet_core::{
311-
os_environment::EnvironmentApi, python_environment::PythonEnvironmentCategory, Locator,
311+
os_environment::EnvironmentApi, python_environment::PythonEnvironmentKind, Locator,
312312
};
313313
use pet_reporter::test::create_reporter;
314314

@@ -345,7 +345,7 @@ fn detect_new_conda_env_created_with_p_flag_with_python() {
345345

346346
assert_eq!(env.prefix, prefix.clone().into());
347347
assert_eq!(env.name, None);
348-
assert_eq!(env.category, PythonEnvironmentCategory::Conda);
348+
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
349349
assert_eq!(env.executable, exe.into());
350350
assert!(
351351
env.version.clone().unwrap_or_default().starts_with("3.10"),

crates/pet-conda/tests/lib_test.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ mod common;
88
fn find_conda_env_without_manager() {
99
use common::{create_test_environment, resolve_test_path};
1010
use pet_conda::Conda;
11-
use pet_core::{
12-
self, arch::Architecture, python_environment::PythonEnvironmentCategory, Locator,
13-
};
11+
use pet_core::{self, arch::Architecture, python_environment::PythonEnvironmentKind, Locator};
1412
use pet_python_utils::env::PythonEnv;
1513
use std::collections::HashMap;
1614

@@ -28,7 +26,7 @@ fn find_conda_env_without_manager() {
2826

2927
assert_eq!(env.prefix, path.clone().into());
3028
assert_eq!(env.arch, Architecture::X64.into());
31-
assert_eq!(env.category, PythonEnvironmentCategory::Conda);
29+
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
3230
assert_eq!(env.executable, path.join("bin").join("python").into());
3331
assert_eq!(env.version, "3.12.2".to_string().into());
3432
assert_eq!(env.manager, None);
@@ -40,9 +38,7 @@ fn find_conda_env_without_manager() {
4038
fn find_conda_env_without_manager_but_detect_manager_from_history() {
4139
use common::{create_test_environment, resolve_test_path};
4240
use pet_conda::Conda;
43-
use pet_core::{
44-
self, arch::Architecture, python_environment::PythonEnvironmentCategory, Locator,
45-
};
41+
use pet_core::{self, arch::Architecture, python_environment::PythonEnvironmentKind, Locator};
4642
use pet_python_utils::env::PythonEnv;
4743
use std::{
4844
collections::HashMap,
@@ -79,7 +75,7 @@ fn find_conda_env_without_manager_but_detect_manager_from_history() {
7975

8076
assert_eq!(env.prefix, path.clone().into());
8177
assert_eq!(env.arch, Architecture::X64.into());
82-
assert_eq!(env.category, PythonEnvironmentCategory::Conda);
78+
assert_eq!(env.kind, PythonEnvironmentKind::Conda);
8379
assert_eq!(env.executable, path.join("bin").join("python").into());
8480
assert_eq!(env.version, "3.12.2".to_string().into());
8581
assert_eq!(

crates/pet-core/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::PathBuf;
55

66
use manager::EnvManager;
77
use pet_python_utils::env::PythonEnv;
8-
use python_environment::{PythonEnvironment, PythonEnvironmentCategory};
8+
use python_environment::{PythonEnvironment, PythonEnvironmentKind};
99
use reporter::Reporter;
1010

1111
pub mod arch;
@@ -40,7 +40,7 @@ pub trait Locator: Send + Sync {
4040
//
4141
}
4242
/// Returns a list of supported categories for this locator.
43-
fn supported_categories(&self) -> Vec<PythonEnvironmentCategory>;
43+
fn supported_categories(&self) -> Vec<PythonEnvironmentKind>;
4444
/// Given a Python executable, and some optional data like prefix,
4545
/// this method will attempt to convert it to a PythonEnvironment that can be supported by this particular locator.
4646
/// If an environment is not supported by this locator, then None is returned.

crates/pet-core/src/python_environment.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::path::PathBuf;
99
use crate::{arch::Architecture, manager::EnvManager};
1010

1111
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, Hash)]
12-
pub enum PythonEnvironmentCategory {
12+
pub enum PythonEnvironmentKind {
1313
Conda,
1414
Homebrew,
1515
Pyenv, // Relates to Python installations in pyenv that are from Python org.
@@ -28,12 +28,12 @@ pub enum PythonEnvironmentCategory {
2828
WindowsStore,
2929
WindowsRegistry,
3030
}
31-
impl Ord for PythonEnvironmentCategory {
31+
impl Ord for PythonEnvironmentKind {
3232
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
3333
format!("{self:?}").cmp(&format!("{other:?}"))
3434
}
3535
}
36-
impl PartialOrd for PythonEnvironmentCategory {
36+
impl PartialOrd for PythonEnvironmentKind {
3737
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
3838
Some(self.cmp(other))
3939
}
@@ -51,7 +51,7 @@ pub struct PythonEnvironment {
5151
pub name: Option<String>,
5252
// Python executable, can be empty in the case of conda envs that do not have Python installed in them.
5353
pub executable: Option<PathBuf>,
54-
pub category: PythonEnvironmentCategory,
54+
pub kind: PythonEnvironmentKind,
5555
pub version: Option<String>,
5656
// SysPrefix for the environment.
5757
pub prefix: Option<PathBuf>,
@@ -102,7 +102,7 @@ impl Default for PythonEnvironment {
102102
// Sometimes we might not know the env type.
103103
// Lets never default these to System/Global or others as thats not true.
104104
// Not knowing does not mean it is a system env.
105-
category: PythonEnvironmentCategory::Unknown,
105+
kind: PythonEnvironmentKind::Unknown,
106106
version: None,
107107
prefix: None,
108108
manager: None,
@@ -117,14 +117,14 @@ impl Default for PythonEnvironment {
117117
impl PythonEnvironment {
118118
pub fn new(
119119
executable: Option<PathBuf>,
120-
category: PythonEnvironmentCategory,
120+
kind: PythonEnvironmentKind,
121121
prefix: Option<PathBuf>,
122122
manager: Option<EnvManager>,
123123
version: Option<String>,
124124
) -> Self {
125125
Self {
126126
executable,
127-
category,
127+
kind,
128128
version,
129129
prefix,
130130
manager,
@@ -135,7 +135,7 @@ impl PythonEnvironment {
135135

136136
impl std::fmt::Display for PythonEnvironment {
137137
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
138-
writeln!(f, "Environment ({:?})", self.category).unwrap_or_default();
138+
writeln!(f, "Environment ({:?})", self.kind).unwrap_or_default();
139139
if let Some(name) = &self.display_name {
140140
writeln!(f, " Display-Name: {name}").unwrap_or_default();
141141
}
@@ -205,7 +205,7 @@ pub struct PythonEnvironmentBuilder {
205205
display_name: Option<String>,
206206
name: Option<String>,
207207
executable: Option<PathBuf>,
208-
category: PythonEnvironmentCategory,
208+
kind: PythonEnvironmentKind,
209209
version: Option<String>,
210210
prefix: Option<PathBuf>,
211211
manager: Option<EnvManager>,
@@ -216,9 +216,9 @@ pub struct PythonEnvironmentBuilder {
216216
}
217217

218218
impl PythonEnvironmentBuilder {
219-
pub fn new(category: PythonEnvironmentCategory) -> Self {
219+
pub fn new(kind: PythonEnvironmentKind) -> Self {
220220
Self {
221-
category,
221+
kind,
222222
display_name: None,
223223
name: None,
224224
executable: None,
@@ -314,7 +314,7 @@ impl PythonEnvironmentBuilder {
314314
};
315315
if let Some(executable) = &self.executable {
316316
self.executable = Some(
317-
get_shortest_executable(&self.category, &Some(all.clone()))
317+
get_shortest_executable(&self.kind, &Some(all.clone()))
318318
.unwrap_or(executable.clone()),
319319
);
320320
}
@@ -337,14 +337,14 @@ impl PythonEnvironmentBuilder {
337337
Some(all.clone())
338338
};
339339
let executable = self.executable.map(|executable| {
340-
get_shortest_executable(&self.category, &Some(all.clone())).unwrap_or(executable)
340+
get_shortest_executable(&self.kind, &Some(all.clone())).unwrap_or(executable)
341341
});
342342

343343
PythonEnvironment {
344344
display_name: self.display_name,
345345
name: self.name,
346346
executable,
347-
category: self.category,
347+
kind: self.kind,
348348
version: self.version,
349349
prefix: self.prefix,
350350
manager: self.manager,
@@ -359,11 +359,11 @@ impl PythonEnvironmentBuilder {
359359
// Given a list of executables, return the one with the shortest path.
360360
// The shortest path is the most likely to be most user friendly.
361361
fn get_shortest_executable(
362-
category: &PythonEnvironmentCategory,
362+
kind: &PythonEnvironmentKind,
363363
exes: &Option<Vec<PathBuf>>,
364364
) -> Option<PathBuf> {
365365
// For windows store, the exe should always be the one in the WindowsApps folder.
366-
if *category == PythonEnvironmentCategory::WindowsStore {
366+
if *kind == PythonEnvironmentKind::WindowsStore {
367367
if let Some(exes) = exes {
368368
if let Some(exe) = exes.iter().find(|e| {
369369
e.to_string_lossy().contains("AppData")
@@ -398,7 +398,7 @@ pub fn get_environment_key(env: &PythonEnvironment) -> Option<PathBuf> {
398398
Some(exe.clone())
399399
} else if let Some(prefix) = &env.prefix {
400400
// If this is a conda env without Python, then the exe will be prefix/bin/python
401-
if env.category == PythonEnvironmentCategory::Conda {
401+
if env.kind == PythonEnvironmentKind::Conda {
402402
Some(prefix.join("bin").join(if cfg!(windows) {
403403
"python.exe"
404404
} else {

crates/pet-core/src/telemetry/inaccurate_python_info.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
use crate::python_environment::PythonEnvironmentCategory;
4+
use crate::python_environment::PythonEnvironmentKind;
55

66
/// Information about an environment that was discovered to be inaccurate.
77
/// If the discovered information is None, then it means that the information was not found.
88
/// And we will not report that as an inaccuracy.
99
pub struct InaccuratePythonEnvironmentInfo {
10-
/// Python Env category
11-
pub category: PythonEnvironmentCategory,
10+
/// Python Env kind
11+
pub kind: PythonEnvironmentKind,
1212
/// Whether the actual exe is not what we expected.
1313
pub invalid_executable: Option<bool>,
1414
/// Whether the actual exe was not even in the list of symlinks that we expected.
@@ -23,7 +23,7 @@ pub struct InaccuratePythonEnvironmentInfo {
2323

2424
impl std::fmt::Display for InaccuratePythonEnvironmentInfo {
2525
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
26-
writeln!(f, "Environment {:?} incorrectly identified", self.category).unwrap_or_default();
26+
writeln!(f, "Environment {:?} incorrectly identified", self.kind).unwrap_or_default();
2727
if self.invalid_executable.unwrap_or_default() {
2828
writeln!(f, " Executable is incorrect").unwrap_or_default();
2929
}

0 commit comments

Comments
 (0)