Skip to content

Commit f484fb2

Browse files
authored
Use enum for category (#23357)
1 parent e53f79e commit f484fb2

File tree

6 files changed

+16
-7
lines changed

6 files changed

+16
-7
lines changed

native_locator/src/common_python.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn report_path_python(dispatcher: &mut impl messaging::MessageDispatcher, path:
2727
dispatcher.send_message(messaging::PythonEnvironment::new(
2828
"Python".to_string(),
2929
vec![path.to_string()],
30-
"System".to_string(),
30+
messaging::PythonEnvironmentCategory::System,
3131
version,
3232
None,
3333
env_path,

native_locator/src/conda.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ pub fn find_and_report(
386386
Some(executable) => vec![executable.to_string_lossy().to_string()],
387387
None => vec![],
388388
},
389-
"conda".to_string(),
389+
messaging::PythonEnvironmentCategory::Conda,
390390
get_conda_python_version(&env.path),
391391
if env.named {
392392
Some(vec![

native_locator/src/messaging.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,21 @@ impl EnvManagerMessage {
4646
}
4747
}
4848

49+
#[derive(Serialize, Deserialize)]
50+
#[serde(rename_all = "camelCase")]
51+
pub enum PythonEnvironmentCategory {
52+
System,
53+
Conda,
54+
Pyenv,
55+
WindowsStore,
56+
}
57+
4958
#[derive(Serialize, Deserialize)]
5059
#[serde(rename_all = "camelCase")]
5160
pub struct PythonEnvironment {
5261
pub name: String,
5362
pub python_executable_path: Vec<String>,
54-
pub category: String,
63+
pub category: PythonEnvironmentCategory,
5564
pub version: Option<String>,
5665
pub activated_run: Option<Vec<String>>,
5766
pub env_path: Option<String>,
@@ -61,7 +70,7 @@ impl PythonEnvironment {
6170
pub fn new(
6271
name: String,
6372
python_executable_path: Vec<String>,
64-
category: String,
73+
category: PythonEnvironmentCategory,
6574
version: Option<String>,
6675
activated_run: Option<Vec<String>>,
6776
env_path: Option<String>,

native_locator/src/pyenv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn find_and_report(
9797
dispatcher.send_message(messaging::PythonEnvironment::new(
9898
"Python".to_string(),
9999
vec![executable.into_os_string().into_string().unwrap()],
100-
"Pyenv".to_string(),
100+
messaging::PythonEnvironmentCategory::Pyenv,
101101
Some(version.clone()),
102102
Some(vec![
103103
pyenv_binary_for_activation.clone(),

native_locator/src/windows_python.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn report_path_python(path: &str, dispatcher: &mut impl messaging::MessageDispat
1111
dispatcher.send_message(messaging::PythonEnvironment::new(
1212
"Python".to_string(),
1313
vec![path.to_string()],
14-
"WindowsStore".to_string(),
14+
messaging::PythonEnvironmentCategory::WindowsStore,
1515
version,
1616
None,
1717
None,

native_locator/tests/common_python_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ fn find_python_in_path_this() {
2727
common_python::find_and_report(&mut dispatcher, &known);
2828

2929
assert_eq!(dispatcher.messages.len(), 1);
30-
let expected_json = json!({"name":"Python","pythonExecutablePath":[unix_python_exe.clone()],"category":"System","version":null,"activatedRun":null,"envPath":unix_python.clone()});
30+
let expected_json = json!({"name":"Python","pythonExecutablePath":[unix_python_exe.clone()],"category":"system","version":null,"activatedRun":null,"envPath":unix_python.clone()});
3131
assert_messages(&[expected_json], &dispatcher);
3232
}

0 commit comments

Comments
 (0)