Skip to content
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
5 changes: 4 additions & 1 deletion native_locator/src/common_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ impl Locator for PythonOnPath<'_> {
if environments.is_empty() {
None
} else {
Some(LocatorResult::Environments(environments))
Some(LocatorResult {
environments,
managers: vec![],
})
}
}
}
9 changes: 4 additions & 5 deletions native_locator/src/conda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,9 @@ impl Locator for Conda<'_> {
environments.push(env)
}

if environments.is_empty() {
Some(LocatorResult::Managers(vec![manager]))
} else {
Some(LocatorResult::Environments(environments))
}
Some(LocatorResult {
managers: vec![manager],
environments,
})
}
}
5 changes: 4 additions & 1 deletion native_locator/src/homebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ impl Locator for Homebrew<'_> {
if environments.is_empty() {
None
} else {
Some(LocatorResult::Environments(environments))
Some(LocatorResult {
managers: vec![],
environments,
})
}
}
}
6 changes: 3 additions & 3 deletions native_locator/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::{
};

#[derive(Debug)]
pub enum LocatorResult {
Managers(Vec<EnvManager>),
Environments(Vec<PythonEnvironment>),
pub struct LocatorResult {
pub managers: Vec<EnvManager>,
pub environments: Vec<PythonEnvironment>,
}

pub trait Locator {
Expand Down
12 changes: 7 additions & 5 deletions native_locator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ fn resolve_environment(
}

fn find_environments(locator: &dyn Locator, dispatcher: &mut JsonRpcDispatcher) -> Option<()> {
match locator.find()? {
locator::LocatorResult::Environments(envs) => envs
if let Some(result) = locator.find() {
result
.environments
.iter()
.for_each(|e| dispatcher.report_environment(e.clone())),
locator::LocatorResult::Managers(items) => items
.for_each(|e| dispatcher.report_environment(e.clone()));
result
.managers
.iter()
.for_each(|m| dispatcher.report_environment_manager(m.clone())),
.for_each(|m| dispatcher.report_environment_manager(m.clone()));
}
Some(())
}
10 changes: 5 additions & 5 deletions native_locator/src/pyenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ impl Locator for PyEnv<'_> {
environments.push(env);
}
}
if environments.is_empty() {
Some(LocatorResult::Managers(vec![manager]))
} else {
Some(LocatorResult::Environments(environments))
}

Some(LocatorResult {
managers: vec![manager],
environments,
})
}
}
5 changes: 4 additions & 1 deletion native_locator/src/virtualenvwrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ impl Locator for VirtualEnvWrapper<'_> {
if environments.is_empty() {
None
} else {
Some(LocatorResult::Environments(environments))
Some(LocatorResult {
managers: vec![],
environments,
})
}
}
}
5 changes: 4 additions & 1 deletion native_locator/src/windows_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ impl Locator for WindowsPython<'_> {
if environments.is_empty() {
None
} else {
Some(LocatorResult::Environments(environments))
Some(LocatorResult {
managers: vec![],
environments,
})
}
}
}
22 changes: 2 additions & 20 deletions native_locator/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,15 @@ pub fn assert_messages(expected_json: &[Value], actual_json: &[Value]) {
#[allow(dead_code)]
pub fn get_environments_from_result(result: &Option<LocatorResult>) -> Vec<PythonEnvironment> {
match result {
Some(environments) => match environments {
python_finder::locator::LocatorResult::Environments(envs) => envs.clone(),
_ => vec![],
},
Some(result) => result.environments.clone(),
None => vec![],
}
}

#[allow(dead_code)]
pub fn get_managers_from_result(result: &Option<LocatorResult>) -> Vec<EnvManager> {
match result {
Some(environments) => match environments {
python_finder::locator::LocatorResult::Managers(managers) => managers.clone(),
python_finder::locator::LocatorResult::Environments(envs) => {
let mut managers: HashMap<String, EnvManager> = HashMap::new();
envs.iter().for_each(|env| {
if let Some(manager) = env.env_manager.clone() {
let key = manager.executable_path.to_str().unwrap().to_string();
managers.insert(key, manager);
}
});
managers
.values()
.map(|m| m.clone())
.collect::<Vec<EnvManager>>()
}
},
Some(result) => result.managers.clone(),
None => vec![],
}
}