Skip to content

Commit 7ce33db

Browse files
authored
Refactor environment identification logic to use find_map for cleaner code (#292)
Fixes #284
1 parent ad5eff5 commit 7ce33db

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

crates/pet/src/locators.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ pub fn identify_python_environment_using_locators(
105105
"Identifying Python environment using locators: {:?}",
106106
executable
107107
);
108-
if let Some(env) = locators.iter().fold(
109-
None,
110-
|e, loc| if e.is_some() { e } else { loc.try_from(env) },
111-
) {
108+
if let Some(env) = locators.iter().find_map(|loc| loc.try_from(env)) {
112109
return Some(env);
113110
}
114111
trace!(
@@ -121,12 +118,7 @@ pub fn identify_python_environment_using_locators(
121118
// We try to get the interpreter info, hoping that the real exe returned might be identifiable.
122119
if let Some(resolved_env) = ResolvedPythonEnv::from(&executable) {
123120
let env = resolved_env.to_python_env();
124-
if let Some(env) =
125-
locators.iter().fold(
126-
None,
127-
|e, loc| if e.is_some() { e } else { loc.try_from(&env) },
128-
)
129-
{
121+
if let Some(env) = locators.iter().find_map(|loc| loc.try_from(&env)) {
130122
trace!("Env ({:?}) in Path resolved as {:?}", executable, env.kind);
131123
// TODO: Telemetry point.
132124
// As we had to spawn earlier.

0 commit comments

Comments
 (0)