Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export namespace PackageManagement {
export const selectPackagesToUninstall = l10n.t('Select packages to uninstall');
export const enterPackagesPlaceHolder = l10n.t('Enter package names separated by space');
export const editArguments = l10n.t('Edit arguments');
export const skipPackageInstallation = l10n.t('Skip package installation');
}

export namespace Pickers {
Expand Down
80 changes: 45 additions & 35 deletions src/managers/builtin/pipUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PythonEnvironmentApi, PythonProject } from '../../api';
import { findFiles } from '../../common/workspace.apis';
import { EXTENSION_ROOT_DIR } from '../../common/constants';
import { Installable, selectFromCommonPackagesToInstall, selectFromInstallableToInstall } from '../common/pickers';
import { traceInfo } from '../../common/logging';

async function tomlParse(fsPath: string, log?: LogOutputChannel): Promise<tomljs.JsonMap> {
try {
Expand Down Expand Up @@ -75,47 +76,56 @@ async function selectWorkspaceOrCommon(
installable: Installable[],
common: Installable[],
): Promise<string[] | undefined> {
if (installable.length > 0) {
const selected = await showQuickPickWithButtons(
[
{
label: PackageManagement.workspaceDependencies,
description: PackageManagement.workspaceDependenciesDescription,
},
{
label: PackageManagement.commonPackages,
description: PackageManagement.commonPackagesDescription,
},
],
{
placeHolder: Pickers.Packages.selectOption,
ignoreFocusOut: true,
showBackButton: true,
matchOnDescription: false,
matchOnDetail: false,
},
);
if (selected && !Array.isArray(selected)) {
try {
if (selected.label === PackageManagement.workspaceDependencies) {
return await selectFromInstallableToInstall(installable);
} else if (selected.label === PackageManagement.commonPackages) {
return await selectFromCommonPackagesToInstall(common);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (ex: any) {
if (ex === QuickInputButtons.Back) {
return selectWorkspaceOrCommon(installable, common);
}
}
}
if (installable.length === 0 && common.length === 0) {
return undefined;
}

const items = [];
if (installable.length > 0) {
items.push({
label: PackageManagement.workspaceDependencies,
description: PackageManagement.workspaceDependenciesDescription,
});
}

if (common.length > 0) {
return selectFromCommonPackagesToInstall(common);
items.push({
label: PackageManagement.commonPackages,
description: PackageManagement.commonPackagesDescription,
});
}

if (items.length > 0) {
items.push({ label: PackageManagement.skipPackageInstallation });
} else {
return undefined;
}

const selected = await showQuickPickWithButtons(items, {
placeHolder: Pickers.Packages.selectOption,
ignoreFocusOut: true,
showBackButton: true,
matchOnDescription: false,
matchOnDetail: false,
});

if (selected && !Array.isArray(selected)) {
try {
if (selected.label === PackageManagement.workspaceDependencies) {
return await selectFromInstallableToInstall(installable);
} else if (selected.label === PackageManagement.commonPackages) {
return await selectFromCommonPackagesToInstall(common);
} else {
traceInfo('Package Installer: user selected skip package installation');
return undefined;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (ex: any) {
if (ex === QuickInputButtons.Back) {
return selectWorkspaceOrCommon(installable, common);
}
}
}
return undefined;
}

Expand Down
62 changes: 56 additions & 6 deletions src/managers/conda/condaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ import {
import * as path from 'path';
import * as os from 'os';
import * as fse from 'fs-extra';
import { CancellationError, CancellationToken, l10n, LogOutputChannel, ProgressLocation, Uri } from 'vscode';
import {
CancellationError,
CancellationToken,
l10n,
LogOutputChannel,
ProgressLocation,
QuickInputButtons,
Uri,
} from 'vscode';
import { ENVS_EXTENSION_ID, EXTENSION_ROOT_DIR } from '../../common/constants';
import { createDeferred } from '../../common/utils/deferred';
import {
Expand All @@ -29,9 +37,9 @@ import { getGlobalPersistentState, getWorkspacePersistentState } from '../../com
import which from 'which';
import { isWindows, shortVersion, sortEnvironments, untildify } from '../common/utils';
import { pickProject } from '../../common/pickers/projects';
import { CondaStrings } from '../../common/localize';
import { CondaStrings, PackageManagement, Pickers } from '../../common/localize';
import { showErrorMessage } from '../../common/errors/utils';
import { showInputBox, showQuickPick, withProgress } from '../../common/window.apis';
import { showInputBox, showQuickPick, showQuickPickWithButtons, withProgress } from '../../common/window.apis';
import { Installable, selectFromCommonPackagesToInstall } from '../common/pickers';
import { quoteArgs } from '../../features/execution/execUtils';
import { traceInfo } from '../../common/logging';
Expand Down Expand Up @@ -758,11 +766,53 @@ async function getCommonPackages(): Promise<Installable[]> {
}
}

export async function getCommonCondaPackagesToInstall(): Promise<string[] | undefined> {
const common = await getCommonPackages();
async function selectCommonPackagesOrSkip(common: Installable[]): Promise<string[] | undefined> {
if (common.length === 0) {
return undefined;
}
const selected = await selectFromCommonPackagesToInstall(common);

const items = [];
if (common.length > 0) {
items.push({
label: PackageManagement.commonPackages,
description: PackageManagement.commonPackagesDescription,
});
}

if (items.length > 0) {
items.push({ label: PackageManagement.skipPackageInstallation });
} else {
return undefined;
}

const selected = await showQuickPickWithButtons(items, {
placeHolder: Pickers.Packages.selectOption,
ignoreFocusOut: true,
showBackButton: true,
matchOnDescription: false,
matchOnDetail: false,
});

if (selected && !Array.isArray(selected)) {
try {
if (selected.label === PackageManagement.commonPackages) {
return await selectFromCommonPackagesToInstall(common);
} else {
traceInfo('Package Installer: user selected skip package installation');
return undefined;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (ex: any) {
if (ex === QuickInputButtons.Back) {
return selectCommonPackagesOrSkip(common);
}
}
}
return undefined;
}

export async function getCommonCondaPackagesToInstall(): Promise<string[] | undefined> {
const common = await getCommonPackages();
const selected = await selectCommonPackagesOrSkip(common);
return selected;
}