Skip to content

Commit e201ef0

Browse files
Copiloteleanorjboyd
andcommitted
Add suppressProgress option to merge progress notifications
- Added suppressProgress option to PackageManagementOptions type - Updated PipPackageManager to respect suppressProgress flag - Updated CondaPackageManager to respect suppressProgress flag - Modified createWithProgress to update progress message when installing packages - Set suppressProgress:true when calling managePackages during env creation Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
1 parent a2c01ff commit e201ef0

4 files changed

Lines changed: 100 additions & 50 deletions

File tree

src/api.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,13 @@ export type PackageManagementOptions =
739739
* Show option to skip package installation or uninstallation.
740740
*/
741741
showSkipOption?: boolean;
742+
743+
/**
744+
* Suppress showing a progress notification when managing packages.
745+
* Used when package management is part of a larger operation with its own progress notification.
746+
*/
747+
suppressProgress?: boolean;
748+
742749
/**
743750
* The list of packages to install.
744751
*/
@@ -759,6 +766,13 @@ export type PackageManagementOptions =
759766
* Show option to skip package installation or uninstallation.
760767
*/
761768
showSkipOption?: boolean;
769+
770+
/**
771+
* Suppress showing a progress notification when managing packages.
772+
* Used when package management is part of a larger operation with its own progress notification.
773+
*/
774+
suppressProgress?: boolean;
775+
762776
/**
763777
* The list of packages to install.
764778
*/

src/managers/builtin/pipManager.ts

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {
22
CancellationError,
3+
CancellationToken,
34
Event,
45
EventEmitter,
56
LogOutputChannel,
67
MarkdownString,
8+
Progress,
79
ProgressLocation,
810
ThemeIcon,
911
window,
@@ -77,34 +79,45 @@ export class PipPackageManager implements PackageManager, Disposable {
7779
install: toInstall,
7880
uninstall: toUninstall,
7981
};
80-
await window.withProgress(
81-
{
82-
location: ProgressLocation.Notification,
83-
title: 'Installing packages',
84-
cancellable: true,
85-
},
86-
async (_progress, token) => {
87-
try {
88-
const before = this.packages.get(environment.envId.id) ?? [];
89-
const after = await managePackages(environment, manageOptions, this.api, this, token);
90-
const changes = getChanges(before, after);
91-
this.packages.set(environment.envId.id, after);
92-
this._onDidChangePackages.fire({ environment, manager: this, changes });
93-
} catch (e) {
94-
if (e instanceof CancellationError) {
95-
throw e;
96-
}
97-
this.log.error('Error managing packages', e);
98-
setImmediate(async () => {
99-
const result = await window.showErrorMessage('Error managing packages', 'View Output');
100-
if (result === 'View Output') {
101-
this.log.show();
102-
}
103-
});
82+
83+
const executeManage = async (
84+
_progress: Progress<{ message?: string; increment?: number }> | undefined,
85+
token: CancellationToken | undefined,
86+
) => {
87+
try {
88+
const before = this.packages.get(environment.envId.id) ?? [];
89+
const after = await managePackages(environment, manageOptions, this.api, this, token);
90+
const changes = getChanges(before, after);
91+
this.packages.set(environment.envId.id, after);
92+
this._onDidChangePackages.fire({ environment, manager: this, changes });
93+
} catch (e) {
94+
if (e instanceof CancellationError) {
10495
throw e;
10596
}
106-
},
107-
);
97+
this.log.error('Error managing packages', e);
98+
setImmediate(async () => {
99+
const result = await window.showErrorMessage('Error managing packages', 'View Output');
100+
if (result === 'View Output') {
101+
this.log.show();
102+
}
103+
});
104+
throw e;
105+
}
106+
};
107+
108+
if (options.suppressProgress) {
109+
// When suppressProgress is true, execute without showing a separate progress notification
110+
await executeManage(undefined, undefined);
111+
} else {
112+
await window.withProgress(
113+
{
114+
location: ProgressLocation.Notification,
115+
title: 'Installing packages',
116+
cancellable: true,
117+
},
118+
executeManage,
119+
);
120+
}
108121
}
109122

110123
async refresh(environment: PythonEnvironment): Promise<void> {

src/managers/builtin/venvUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export async function createWithProgress(
287287
basePython.version,
288288
),
289289
},
290-
async () => {
290+
async (progress) => {
291291
const result: CreateEnvironmentResult = {};
292292
try {
293293
const useUv = await isUvInstalled(log);
@@ -319,10 +319,13 @@ export async function createWithProgress(
319319
// install packages
320320
if (packages && (packages.install.length > 0 || packages.uninstall.length > 0)) {
321321
try {
322+
// Update progress message to indicate package installation
323+
progress.report({ message: l10n.t('Installing packages...') });
322324
await api.managePackages(env, {
323325
upgrade: false,
324326
install: packages?.install,
325327
uninstall: packages?.uninstall ?? [],
328+
suppressProgress: true,
326329
});
327330
} catch (e) {
328331
// error occurred while installing packages

src/managers/conda/condaPackageManager.ts

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import {
22
CancellationError,
3+
CancellationToken,
4+
CancellationTokenSource,
35
Disposable,
46
Event,
57
EventEmitter,
68
LogOutputChannel,
79
MarkdownString,
10+
Progress,
811
ProgressLocation,
912
} from 'vscode';
1013
import {
@@ -70,31 +73,48 @@ export class CondaPackageManager implements PackageManager, Disposable {
7073
install: toInstall,
7174
uninstall: toUninstall,
7275
};
73-
await withProgress(
74-
{
75-
location: ProgressLocation.Notification,
76-
title: CondaStrings.condaInstallingPackages,
77-
cancellable: true,
78-
},
79-
async (_progress, token) => {
80-
try {
81-
const before = this.packages.get(environment.envId.id) ?? [];
82-
const after = await managePackages(environment, manageOptions, this.api, this, token, this.log);
83-
const changes = getChanges(before, after);
84-
this.packages.set(environment.envId.id, after);
85-
this._onDidChangePackages.fire({ environment: environment, manager: this, changes });
86-
} catch (e) {
87-
if (e instanceof CancellationError) {
88-
throw e;
89-
}
9076

91-
this.log.error('Error installing packages', e);
92-
setImmediate(async () => {
93-
await showErrorMessageWithLogs(CondaStrings.condaInstallError, this.log);
94-
});
77+
const executeManage = async (
78+
_progress: Progress<{ message?: string; increment?: number }> | undefined,
79+
token: CancellationToken,
80+
) => {
81+
try {
82+
const before = this.packages.get(environment.envId.id) ?? [];
83+
const after = await managePackages(environment, manageOptions, this.api, this, token, this.log);
84+
const changes = getChanges(before, after);
85+
this.packages.set(environment.envId.id, after);
86+
this._onDidChangePackages.fire({ environment: environment, manager: this, changes });
87+
} catch (e) {
88+
if (e instanceof CancellationError) {
89+
throw e;
9590
}
96-
},
97-
);
91+
92+
this.log.error('Error installing packages', e);
93+
setImmediate(async () => {
94+
await showErrorMessageWithLogs(CondaStrings.condaInstallError, this.log);
95+
});
96+
}
97+
};
98+
99+
if (options.suppressProgress) {
100+
// When suppressProgress is true, execute without showing a separate progress notification
101+
// Create a cancellation token source since conda's managePackages requires one
102+
const tokenSource = new CancellationTokenSource();
103+
try {
104+
await executeManage(undefined, tokenSource.token);
105+
} finally {
106+
tokenSource.dispose();
107+
}
108+
} else {
109+
await withProgress(
110+
{
111+
location: ProgressLocation.Notification,
112+
title: CondaStrings.condaInstallingPackages,
113+
cancellable: true,
114+
},
115+
executeManage,
116+
);
117+
}
98118
}
99119

100120
async refresh(environment: PythonEnvironment): Promise<void> {

0 commit comments

Comments
 (0)