Skip to content

Commit bbb17fd

Browse files
committed
update local sourcing path preference
1 parent 0bd3547 commit bbb17fd

2 files changed

Lines changed: 20 additions & 15 deletions

File tree

src/managers/conda/condaSourcingUtils.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,22 +280,32 @@ async function getCondaBatActivationFile(condaPath: string): Promise<string | un
280280
* This function checks for a local 'activate' script in the same directory as the conda executable.
281281
* This script is used for direct conda activation without shell-specific configuration.
282282
*/
283+
284+
const knownSourcingScriptCache: string[] = [];
283285
export async function getLocalActivationScript(condaPath: string): Promise<string | undefined> {
284-
const activatePath = path.join(path.dirname(condaPath), 'activate');
285-
traceVerbose(`Checking for local activation script at: ${activatePath}`);
286+
const sourcingScript = isWindows()
287+
? path.join(condaPath, 'Scripts', 'activate.bat')
288+
: path.join(condaPath, 'bin', 'activate');
289+
traceVerbose(`Checking for local activation script at: ${sourcingScript}`);
286290

287291
if (!condaPath) {
288292
traceVerbose('No conda path provided, cannot find local activation script');
289293
return undefined;
290294
}
291295

296+
if (knownSourcingScriptCache.includes(sourcingScript)) {
297+
traceVerbose(`Found local activation script in cache at: ${sourcingScript}`);
298+
return sourcingScript;
299+
}
300+
292301
try {
293-
const exists = await fse.pathExists(activatePath);
302+
const exists = await fse.pathExists(sourcingScript);
294303
if (exists) {
295-
traceInfo(`Found local activation script at: ${activatePath}`);
296-
return activatePath;
304+
traceInfo(`Found local activation script at: ${sourcingScript}, adding to cache.`);
305+
knownSourcingScriptCache.push(sourcingScript);
306+
return sourcingScript;
297307
} else {
298-
traceVerbose(`No local activation script found at: ${activatePath}`);
308+
traceVerbose(`No local activation script found at: ${sourcingScript}`);
299309
return undefined;
300310
}
301311
} catch (err) {

src/managers/conda/condaUtils.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,15 +438,10 @@ async function generateShellActivationMap2(
438438
}
439439
traceInfo(`Local activation script status: ${localSourcingPath ? 'found at ' + localSourcingPath : 'not found'}`);
440440

441-
// Determine the preferred sourcing path based on platform
442-
const preferredSourcingPath = isWindows()
443-
? localSourcingPath || globalSourcingScript
444-
: globalSourcingScript || localSourcingPath;
445-
traceInfo(
446-
`Selected preferred sourcing path give machine type of ${isWindows() ? 'Windows' : 'non-Windows'} is: ${
447-
preferredSourcingPath ?? 'none found'
448-
}`,
449-
);
441+
// Determine the preferred sourcing path with preference to local
442+
const preferredSourcingPath = localSourcingPath || globalSourcingScript;
443+
444+
traceInfo(`Selected preferred sourcing path is: ${preferredSourcingPath ?? 'none found'}`);
450445

451446
// P2: Return shell activation if we have no sourcing
452447
if (!preferredSourcingPath) {

0 commit comments

Comments
 (0)