Skip to content

Commit 4a1a772

Browse files
authored
fix: enhance conda executable retrieval with path existence checks (#677)
fixes #676: `getCondaExecutable` doesn't check if path exists Fixes
1 parent dbc5656 commit 4a1a772

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/managers/conda/condaUtils.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,31 @@ async function findConda(): Promise<readonly string[] | undefined> {
134134

135135
async function getCondaExecutable(native?: NativePythonFinder): Promise<string> {
136136
if (condaPath) {
137-
traceInfo(`Using conda from cache: ${condaPath}`);
138-
return untildify(condaPath);
137+
if (await fse.pathExists(untildify(condaPath))) {
138+
traceInfo(`Using conda from cache: ${condaPath}`);
139+
return untildify(condaPath);
140+
}
139141
}
140142

141143
const state = await getWorkspacePersistentState();
142144
condaPath = await state.get<string>(CONDA_PATH_KEY);
143145
if (condaPath) {
144-
traceInfo(`Using conda from persistent state: ${condaPath}`);
145-
return untildify(condaPath);
146+
if (await fse.pathExists(untildify(condaPath))) {
147+
traceInfo(`Using conda from persistent state: ${condaPath}`);
148+
return untildify(condaPath);
149+
}
146150
}
147151

148152
const paths = await findConda();
149153
if (paths && paths.length > 0) {
150-
condaPath = paths[0];
151-
traceInfo(`Using conda from PATH: ${condaPath}`);
152-
await state.set(CONDA_PATH_KEY, condaPath);
153-
return condaPath;
154+
for (let i = 0; i < paths.length; i++) {
155+
condaPath = paths[i];
156+
if (await fse.pathExists(untildify(condaPath))) {
157+
traceInfo(`Using conda from PATH: ${condaPath}`);
158+
await state.set(CONDA_PATH_KEY, condaPath);
159+
return condaPath;
160+
}
161+
}
154162
}
155163

156164
if (native) {
@@ -160,10 +168,14 @@ async function getCondaExecutable(native?: NativePythonFinder): Promise<string>
160168
.map((e) => e as NativeEnvManagerInfo)
161169
.filter((e) => e.tool.toLowerCase() === 'conda');
162170
if (managers.length > 0) {
163-
condaPath = managers[0].executable;
164-
traceInfo(`Using conda from native finder: ${condaPath}`);
165-
await state.set(CONDA_PATH_KEY, condaPath);
166-
return condaPath;
171+
for (let i = 0; i < managers.length; i++) {
172+
condaPath = managers[i].executable;
173+
if (await fse.pathExists(untildify(condaPath))) {
174+
traceInfo(`Using conda from native finder: ${condaPath}`);
175+
await state.set(CONDA_PATH_KEY, condaPath);
176+
return condaPath;
177+
}
178+
}
167179
}
168180
}
169181

0 commit comments

Comments
 (0)