Skip to content

Commit ba39d40

Browse files
committed
fix up
1 parent 203f09d commit ba39d40

3 files changed

Lines changed: 17 additions & 47 deletions

File tree

src/managers/conda/condaSourcingUtils.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export async function constructCondaSourcingStatus(condaPath: string): Promise<C
8989
const globalSourcingScript: string | undefined = await findGlobalSourcingScript(sourcingStatus.condaFolder);
9090
if (globalSourcingScript) {
9191
sourcingStatus.globalSourcingScript = globalSourcingScript;
92-
// TODO: determine if we want to exit here or continue to generate all the other activation scripts
92+
// note: future iterations could decide to exit here instead of continuing to generate all the other activation scripts
9393
}
9494

9595
// find and save all of the shell specific sourcing scripts
@@ -111,19 +111,18 @@ export async function findGlobalSourcingScript(condaFolder: string): Promise<str
111111
? path.join(condaFolder, 'Scripts', 'activate.bat')
112112
: path.join(condaFolder, 'bin', 'activate');
113113

114-
traceVerbose(`Checking for global conda sourcing script at: ${sourcingScript}`);
115114
if (await fse.pathExists(sourcingScript)) {
116115
traceInfo(`Found global conda sourcing script at: ${sourcingScript}`);
117116
return sourcingScript;
118117
} else {
119-
traceInfo(`No global conda sourcing script found.`);
118+
traceInfo(`No global conda sourcing script found. at: ${sourcingScript}`);
120119
return undefined;
121120
}
122121
}
123122

124123
export async function findShellSourcingScripts(sourcingStatus: CondaSourcingStatus): Promise<string[]> {
125124
const logs: string[] = [];
126-
logs.push('=== Conda Shell Script Search ===');
125+
logs.push('=== Conda Sourcing Shell Script Search ===');
127126

128127
let ps1Script: string | undefined;
129128
let shScript: string | undefined;
@@ -134,37 +133,32 @@ export async function findShellSourcingScripts(sourcingStatus: CondaSourcingStat
134133
logs.push('Searching for PowerShell hook script...');
135134
try {
136135
ps1Script = await getCondaHookPs1Path(sourcingStatus.condaFolder);
137-
logs.push(` Status: ${ps1Script ? '✓ Found' : '✗ Not found'}`);
138-
logs.push(` Path: ${ps1Script ?? 'N/A'}`);
136+
logs.push(` Path: ${ps1Script ?? '✗ Not found'}`);
139137
} catch (err) {
140138
logs.push(
141-
` ⚠️ Error during PowerShell script search: ${err instanceof Error ? err.message : 'Unknown error'}`,
139+
` Error during PowerShell script search: ${err instanceof Error ? err.message : 'Unknown error'}`,
142140
);
143141
}
144142

145143
// Search for Shell script (conda.sh)
146144
logs.push('\nSearching for Shell script...');
147145
try {
148146
shScript = await getCondaShPath(sourcingStatus.condaFolder);
149-
logs.push(` Status: ${shScript ? '✓ Found' : '✗ Not found'}`);
150-
logs.push(` Path: ${shScript ?? 'N/A'}`);
147+
logs.push(` Path: ${shScript ?? '✗ Not found'}`);
151148
} catch (err) {
152-
logs.push(` ⚠️ Error during Shell script search: ${err instanceof Error ? err.message : 'Unknown error'}`);
149+
logs.push(` Error during Shell script search: ${err instanceof Error ? err.message : 'Unknown error'}`);
153150
}
154151

155152
// Search for Windows CMD script (activate.bat)
156153
logs.push('\nSearching for Windows CMD script...');
157154
try {
158155
cmdActivate = await getCondaBatActivationFile(sourcingStatus.condaPath);
159-
logs.push(` Status: ${cmdActivate ? '✓ Found' : '✗ Not found'}`);
160-
logs.push(` Path: ${cmdActivate ?? 'N/A'}`);
156+
logs.push(` Path: ${cmdActivate ?? '✗ Not found'}`);
161157
} catch (err) {
162-
logs.push(` ⚠️ Error during CMD script search: ${err instanceof Error ? err.message : 'Unknown error'}`);
158+
logs.push(` Error during CMD script search: ${err instanceof Error ? err.message : 'Unknown error'}`);
163159
}
164160
} catch (error) {
165-
logs.push(
166-
`\n❌ Critical error during script search: ${error instanceof Error ? error.message : 'Unknown error'}`,
167-
);
161+
logs.push(`\nCritical error during script search: ${error instanceof Error ? error.message : 'Unknown error'}`);
168162
} finally {
169163
logs.push('\nSearch Summary:');
170164
logs.push(` PowerShell: ${ps1Script ? '✓' : '✗'}`);
@@ -189,8 +183,6 @@ export async function findShellSourcingScripts(sourcingStatus: CondaSourcingStat
189183
* - etc/profile.d/
190184
*/
191185
export async function getCondaHookPs1Path(condaFolder: string): Promise<string | undefined> {
192-
// Check cache first
193-
194186
// Create the promise for finding the hook path
195187
const hookPathPromise = (async () => {
196188
const condaRootCandidates: string[] = [
@@ -216,7 +208,6 @@ export async function getCondaHookPs1Path(condaFolder: string): Promise<string |
216208
return undefined;
217209
})();
218210

219-
// Store in cache and return
220211
return hookPathPromise;
221212
}
222213

@@ -325,11 +316,6 @@ async function getCondaBatActivationFile(condaPath: string): Promise<string | un
325316

326317
const knownSourcingScriptCache: string[] = [];
327318
export async function getLocalActivationScript(condaPath: string): Promise<string | undefined> {
328-
if (!condaPath) {
329-
traceVerbose('No conda path provided, cannot find local activation script');
330-
return undefined;
331-
}
332-
333319
// Define all possible paths to check
334320
const paths = [
335321
// Direct path
@@ -351,7 +337,6 @@ export async function getLocalActivationScript(condaPath: string): Promise<strin
351337
traceVerbose(`Found local activation script in cache at: ${sourcingScript}`);
352338
return sourcingScript;
353339
}
354-
traceVerbose(`Checking for local activation script at: ${sourcingScript}`);
355340
try {
356341
const exists = await fse.pathExists(sourcingScript);
357342
if (exists) {

src/managers/conda/condaUtils.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
import { ENVS_EXTENSION_ID, EXTENSION_ROOT_DIR } from '../../common/constants';
2929
import { showErrorMessageWithLogs } from '../../common/errors/utils';
3030
import { Common, CondaStrings, PackageManagement, Pickers } from '../../common/localize';
31-
import { traceError, traceInfo, traceVerbose } from '../../common/logging';
31+
import { traceInfo, traceVerbose } from '../../common/logging';
3232
import { getWorkspacePersistentState } from '../../common/persistentState';
3333
import { pickProject } from '../../common/pickers/projects';
3434
import { createDeferred } from '../../common/utils/deferred';
@@ -415,17 +415,12 @@ async function generateShellActivationMap2(
415415
};
416416

417417
if (!(envManager instanceof CondaEnvManager) || !envManager.sourcingInformation) {
418-
logs.push('⚠️ Error: Conda environment manager is not available, using default conda activation paths');
418+
logs.push('Error: Conda environment manager is not available, using default conda activation paths');
419419
shellMaps = await generateShellActivationMapFromConfig([condaCommonActivate], [condaCommonDeactivate]);
420420
return shellMaps;
421421
}
422422

423-
const { isActiveOnLaunch, globalSourcingScript, shellSourcingScripts } = envManager.sourcingInformation;
424-
logs.push(`Sourcing Information:
425-
- Active on Launch: ${isActiveOnLaunch}
426-
- Global Script: ${globalSourcingScript ?? 'none'}
427-
- Shell Scripts: ${shellSourcingScripts?.join(', ') ?? 'none'}
428-
`);
423+
const { isActiveOnLaunch, globalSourcingScript } = envManager.sourcingInformation;
429424

430425
// P1: first check to see if conda is already active in the whole VS Code workspace via sourcing info (set at startup)
431426
if (isActiveOnLaunch) {
@@ -439,9 +434,7 @@ async function generateShellActivationMap2(
439434
try {
440435
localSourcingPath = await getLocalActivationScript(prefix);
441436
} catch (err) {
442-
logs.push(
443-
`⚠️ Error getting local activation script: ${err instanceof Error ? err.message : 'Unknown error'}`,
444-
);
437+
logs.push(`Error getting local activation script: ${err instanceof Error ? err.message : 'Unknown error'}`);
445438
}
446439

447440
logs.push(`Local Activation:
@@ -458,7 +451,7 @@ async function generateShellActivationMap2(
458451

459452
// P2: Return shell activation if we have no sourcing
460453
if (!preferredSourcingPath) {
461-
logs.push('⚠️ No sourcing path found, using default conda activation');
454+
logs.push('No sourcing path found, using default conda activation');
462455
shellMaps = await generateShellActivationMapFromConfig([condaCommonActivate], [condaCommonDeactivate]);
463456
return shellMaps;
464457
}
@@ -483,9 +476,8 @@ async function generateShellActivationMap2(
483476
return shellMaps;
484477
} catch (error) {
485478
logs.push(
486-
`Error in shell activation map generation: ${error instanceof Error ? error.message : 'Unknown error'}`,
479+
`Error in shell activation map generation: ${error instanceof Error ? error.message : 'Unknown error'}`,
487480
);
488-
traceError('Failed to generate shell activation map. Falling back to default conda activation');
489481
// Fall back to default conda activation in case of error
490482
shellMaps = await generateShellActivationMapFromConfig(
491483
[{ executable: 'conda', args: ['activate', name || prefix] }],
@@ -542,12 +534,6 @@ async function windowsExceptionGenerateConfig(
542534
const shellActivation: Map<string, PythonCommandRunConfiguration[]> = new Map();
543535
const shellDeactivation: Map<string, PythonCommandRunConfiguration[]> = new Map();
544536

545-
// set the NOT gitbash and bash to be
546-
/// sourceInitPath conda activate ENVNAME
547-
// localActivationPath conda activate prefix
548-
// source pathInit ENVNAME for all NON bash
549-
550-
// not bash activate
551537
const ps1Hook = await getCondaHookPs1Path(condaFolder);
552538
traceVerbose(`PS1 hook path: ${ps1Hook ?? 'not found'}`);
553539
const activation = ps1Hook ? ps1Hook : sourceInitPath;
@@ -556,7 +542,6 @@ async function windowsExceptionGenerateConfig(
556542
const cmdActivate = [{ executable: sourceInitPath }, { executable: 'conda', args: ['activate', prefix] }];
557543

558544
const bashActivate = [{ executable: 'source', args: [sourceInitPath.replace(/\\/g, '/'), prefix] }];
559-
// TODO: for bashActivate the sep is \ but needs to be / ??? tried on gitbash
560545
traceVerbose(
561546
`Windows activation commands:
562547
PowerShell: ${JSON.stringify(pwshActivate)},

src/managers/conda/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function registerCondaFeatures(
1919
// get Conda will return only ONE conda manager, that correlates to a single conda install
2020
const condaPath: string = await getConda(nativeFinder);
2121
const sourcingStatus: CondaSourcingStatus = await constructCondaSourcingStatus(condaPath);
22-
traceInfo('Conda Sourcing Status:', sourcingStatus.toString());
22+
traceInfo(sourcingStatus.toString());
2323

2424
const envManager = new CondaEnvManager(nativeFinder, api, log);
2525
const packageManager = new CondaPackageManager(api, log);

0 commit comments

Comments
 (0)