Skip to content

Commit 3a511a6

Browse files
committed
refactor: simplify environment filtering and enhance conda environment creation logic
1 parent e7add4d commit 3a511a6

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

src/managers/conda/condaEnvManager.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
111111
}
112112

113113
if (scope === 'global') {
114-
return this.collection.filter((env) => {
115-
env.name === 'base';
116-
});
114+
return this.collection.filter((env) => env.name === 'base');
117115
}
118116

119117
if (scope instanceof Uri) {
@@ -192,7 +190,10 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
192190
} catch (error) {
193191
this.log.error('Failed to create conda environment:', error);
194192
showErrorMessage(
195-
l10n.t('Failed to create conda environment: {0}', error instanceof Error ? error.message : String(error)),
193+
l10n.t(
194+
'Failed to create conda environment: {0}',
195+
error instanceof Error ? error.message : String(error),
196+
),
196197
);
197198
return undefined;
198199
}

src/managers/conda/condaUtils.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ export async function createPrefixCondaEnvironment(
10461046
export async function generateName(fsPath: string): Promise<string | undefined> {
10471047
let attempts = 0;
10481048
while (attempts < 5) {
1049+
attempts++;
10491050
const randomStr = Math.random().toString(36).substring(2);
10501051
const name = `env_${randomStr}`;
10511052
const prefix = path.join(fsPath, name);
@@ -1074,32 +1075,16 @@ export async function quickCreateConda(
10741075
},
10751076
async () => {
10761077
try {
1078+
const conda = await getConda();
10771079
await runCondaExecutable(['create', '--yes', '--prefix', prefix, 'python'], log);
10781080
if (additionalPackages && additionalPackages.length > 0) {
10791081
await runConda(['install', '--yes', '--prefix', prefix, ...additionalPackages], log);
10801082
}
10811083
const version = await getVersion(prefix);
10821084

1085+
// Use proper prefix-based activation with actual conda path
10831086
const environment = api.createPythonEnvironmentItem(
1084-
{
1085-
name: path.basename(prefix),
1086-
environmentPath: Uri.file(prefix),
1087-
displayName: `${version} (${name})`,
1088-
displayPath: prefix,
1089-
description: prefix,
1090-
version,
1091-
execInfo: {
1092-
run: { executable: execPath },
1093-
activatedRun: {
1094-
executable: execPath,
1095-
args: [],
1096-
},
1097-
activation: [{ executable: 'conda', args: ['activate', prefix] }],
1098-
deactivation: [{ executable: 'conda', args: ['deactivate'] }],
1099-
},
1100-
sysPrefix: prefix,
1101-
group: 'Prefix',
1102-
},
1087+
await getPrefixesCondaPythonInfo(prefix, execPath, version, conda, manager),
11031088
manager,
11041089
);
11051090
return environment;

0 commit comments

Comments
 (0)