Skip to content

Use enum for category #23357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion native_locator/src/common_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn report_path_python(dispatcher: &mut impl messaging::MessageDispatcher, path:
dispatcher.send_message(messaging::PythonEnvironment::new(
"Python".to_string(),
vec![path.to_string()],
"System".to_string(),
messaging::PythonEnvironmentCategory::System,
version,
None,
env_path,
Expand Down
2 changes: 1 addition & 1 deletion native_locator/src/conda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ pub fn find_and_report(
Some(executable) => vec![executable.to_string_lossy().to_string()],
None => vec![],
},
"conda".to_string(),
messaging::PythonEnvironmentCategory::Conda,
get_conda_python_version(&env.path),
if env.named {
Some(vec![
Expand Down
13 changes: 11 additions & 2 deletions native_locator/src/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,21 @@ impl EnvManagerMessage {
}
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum PythonEnvironmentCategory {
System,
Conda,
Pyenv,
WindowsStore,
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PythonEnvironment {
pub name: String,
pub python_executable_path: Vec<String>,
pub category: String,
pub category: PythonEnvironmentCategory,
pub version: Option<String>,
pub activated_run: Option<Vec<String>>,
pub env_path: Option<String>,
Expand All @@ -61,7 +70,7 @@ impl PythonEnvironment {
pub fn new(
name: String,
python_executable_path: Vec<String>,
category: String,
category: PythonEnvironmentCategory,
version: Option<String>,
activated_run: Option<Vec<String>>,
env_path: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion native_locator/src/pyenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn find_and_report(
dispatcher.send_message(messaging::PythonEnvironment::new(
"Python".to_string(),
vec![executable.into_os_string().into_string().unwrap()],
"Pyenv".to_string(),
messaging::PythonEnvironmentCategory::Pyenv,
Some(version.clone()),
Some(vec![
pyenv_binary_for_activation.clone(),
Expand Down
2 changes: 1 addition & 1 deletion native_locator/src/windows_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn report_path_python(path: &str, dispatcher: &mut impl messaging::MessageDispat
dispatcher.send_message(messaging::PythonEnvironment::new(
"Python".to_string(),
vec![path.to_string()],
"WindowsStore".to_string(),
messaging::PythonEnvironmentCategory::WindowsStore,
version,
None,
None,
Expand Down
2 changes: 1 addition & 1 deletion native_locator/tests/common_python_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ fn find_python_in_path_this() {
common_python::find_and_report(&mut dispatcher, &known);

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