Skip to content

Commit 771bd3c

Browse files
authored
feat: add option to skip package installation in venv and conda installers (#213)
closes: #212
1 parent 284d3d4 commit 771bd3c

File tree

3 files changed

+102
-41
lines changed

3 files changed

+102
-41
lines changed

src/common/localize.ts

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export namespace PackageManagement {
2929
export const selectPackagesToUninstall = l10n.t('Select packages to uninstall');
3030
export const enterPackagesPlaceHolder = l10n.t('Enter package names separated by space');
3131
export const editArguments = l10n.t('Edit arguments');
32+
export const skipPackageInstallation = l10n.t('Skip package installation');
3233
}
3334

3435
export namespace Pickers {

src/managers/builtin/pipUtils.ts

+45-35
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { PythonEnvironmentApi, PythonProject } from '../../api';
88
import { findFiles } from '../../common/workspace.apis';
99
import { EXTENSION_ROOT_DIR } from '../../common/constants';
1010
import { Installable, selectFromCommonPackagesToInstall, selectFromInstallableToInstall } from '../common/pickers';
11+
import { traceInfo } from '../../common/logging';
1112

1213
async function tomlParse(fsPath: string, log?: LogOutputChannel): Promise<tomljs.JsonMap> {
1314
try {
@@ -75,47 +76,56 @@ async function selectWorkspaceOrCommon(
7576
installable: Installable[],
7677
common: Installable[],
7778
): Promise<string[] | undefined> {
78-
if (installable.length > 0) {
79-
const selected = await showQuickPickWithButtons(
80-
[
81-
{
82-
label: PackageManagement.workspaceDependencies,
83-
description: PackageManagement.workspaceDependenciesDescription,
84-
},
85-
{
86-
label: PackageManagement.commonPackages,
87-
description: PackageManagement.commonPackagesDescription,
88-
},
89-
],
90-
{
91-
placeHolder: Pickers.Packages.selectOption,
92-
ignoreFocusOut: true,
93-
showBackButton: true,
94-
matchOnDescription: false,
95-
matchOnDetail: false,
96-
},
97-
);
98-
if (selected && !Array.isArray(selected)) {
99-
try {
100-
if (selected.label === PackageManagement.workspaceDependencies) {
101-
return await selectFromInstallableToInstall(installable);
102-
} else if (selected.label === PackageManagement.commonPackages) {
103-
return await selectFromCommonPackagesToInstall(common);
104-
}
105-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
106-
} catch (ex: any) {
107-
if (ex === QuickInputButtons.Back) {
108-
return selectWorkspaceOrCommon(installable, common);
109-
}
110-
}
111-
}
79+
if (installable.length === 0 && common.length === 0) {
11280
return undefined;
11381
}
11482

83+
const items = [];
84+
if (installable.length > 0) {
85+
items.push({
86+
label: PackageManagement.workspaceDependencies,
87+
description: PackageManagement.workspaceDependenciesDescription,
88+
});
89+
}
90+
11591
if (common.length > 0) {
116-
return selectFromCommonPackagesToInstall(common);
92+
items.push({
93+
label: PackageManagement.commonPackages,
94+
description: PackageManagement.commonPackagesDescription,
95+
});
11796
}
11897

98+
if (items.length > 0) {
99+
items.push({ label: PackageManagement.skipPackageInstallation });
100+
} else {
101+
return undefined;
102+
}
103+
104+
const selected = await showQuickPickWithButtons(items, {
105+
placeHolder: Pickers.Packages.selectOption,
106+
ignoreFocusOut: true,
107+
showBackButton: true,
108+
matchOnDescription: false,
109+
matchOnDetail: false,
110+
});
111+
112+
if (selected && !Array.isArray(selected)) {
113+
try {
114+
if (selected.label === PackageManagement.workspaceDependencies) {
115+
return await selectFromInstallableToInstall(installable);
116+
} else if (selected.label === PackageManagement.commonPackages) {
117+
return await selectFromCommonPackagesToInstall(common);
118+
} else {
119+
traceInfo('Package Installer: user selected skip package installation');
120+
return undefined;
121+
}
122+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
123+
} catch (ex: any) {
124+
if (ex === QuickInputButtons.Back) {
125+
return selectWorkspaceOrCommon(installable, common);
126+
}
127+
}
128+
}
119129
return undefined;
120130
}
121131

src/managers/conda/condaUtils.ts

+56-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ import {
1414
import * as path from 'path';
1515
import * as os from 'os';
1616
import * as fse from 'fs-extra';
17-
import { CancellationError, CancellationToken, l10n, LogOutputChannel, ProgressLocation, Uri } from 'vscode';
17+
import {
18+
CancellationError,
19+
CancellationToken,
20+
l10n,
21+
LogOutputChannel,
22+
ProgressLocation,
23+
QuickInputButtons,
24+
Uri,
25+
} from 'vscode';
1826
import { ENVS_EXTENSION_ID, EXTENSION_ROOT_DIR } from '../../common/constants';
1927
import { createDeferred } from '../../common/utils/deferred';
2028
import {
@@ -29,9 +37,9 @@ import { getGlobalPersistentState, getWorkspacePersistentState } from '../../com
2937
import which from 'which';
3038
import { isWindows, shortVersion, sortEnvironments, untildify } from '../common/utils';
3139
import { pickProject } from '../../common/pickers/projects';
32-
import { CondaStrings } from '../../common/localize';
40+
import { CondaStrings, PackageManagement, Pickers } from '../../common/localize';
3341
import { showErrorMessage } from '../../common/errors/utils';
34-
import { showInputBox, showQuickPick, withProgress } from '../../common/window.apis';
42+
import { showInputBox, showQuickPick, showQuickPickWithButtons, withProgress } from '../../common/window.apis';
3543
import { Installable, selectFromCommonPackagesToInstall } from '../common/pickers';
3644
import { quoteArgs } from '../../features/execution/execUtils';
3745
import { traceInfo } from '../../common/logging';
@@ -758,11 +766,53 @@ async function getCommonPackages(): Promise<Installable[]> {
758766
}
759767
}
760768

761-
export async function getCommonCondaPackagesToInstall(): Promise<string[] | undefined> {
762-
const common = await getCommonPackages();
769+
async function selectCommonPackagesOrSkip(common: Installable[]): Promise<string[] | undefined> {
763770
if (common.length === 0) {
764771
return undefined;
765772
}
766-
const selected = await selectFromCommonPackagesToInstall(common);
773+
774+
const items = [];
775+
if (common.length > 0) {
776+
items.push({
777+
label: PackageManagement.commonPackages,
778+
description: PackageManagement.commonPackagesDescription,
779+
});
780+
}
781+
782+
if (items.length > 0) {
783+
items.push({ label: PackageManagement.skipPackageInstallation });
784+
} else {
785+
return undefined;
786+
}
787+
788+
const selected = await showQuickPickWithButtons(items, {
789+
placeHolder: Pickers.Packages.selectOption,
790+
ignoreFocusOut: true,
791+
showBackButton: true,
792+
matchOnDescription: false,
793+
matchOnDetail: false,
794+
});
795+
796+
if (selected && !Array.isArray(selected)) {
797+
try {
798+
if (selected.label === PackageManagement.commonPackages) {
799+
return await selectFromCommonPackagesToInstall(common);
800+
} else {
801+
traceInfo('Package Installer: user selected skip package installation');
802+
return undefined;
803+
}
804+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
805+
} catch (ex: any) {
806+
if (ex === QuickInputButtons.Back) {
807+
return selectCommonPackagesOrSkip(common);
808+
}
809+
}
810+
}
811+
return undefined;
812+
}
813+
814+
export async function getCommonCondaPackagesToInstall(): Promise<string[] | undefined> {
815+
const common = await getCommonPackages();
816+
const selected = await selectCommonPackagesOrSkip(common);
767817
return selected;
768818
}

0 commit comments

Comments
 (0)