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
2 changes: 1 addition & 1 deletion src/managers/builtin/pipManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class PipPackageManager implements PackageManager, Disposable {

if (selected.length === 0) {
const projects = this.venv.getProjectsByEnvironment(environment);
selected = (await getWorkspacePackagesToInstall(this.api, options, projects)) ?? [];
selected = (await getWorkspacePackagesToInstall(this.api, options, projects, environment)) ?? [];
}

if (selected.length === 0) {
Expand Down
12 changes: 9 additions & 3 deletions src/managers/builtin/pipUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as tomljs from '@iarna/toml';
import { LogOutputChannel, ProgressLocation, QuickInputButtons, Uri } from 'vscode';
import { showQuickPickWithButtons, withProgress } from '../../common/window.apis';
import { PackageManagement, Pickers, VenvManagerStrings } from '../../common/localize';
import { PackageInstallOptions, PythonEnvironmentApi, PythonProject } from '../../api';
import { PackageInstallOptions, PythonEnvironment, PythonEnvironmentApi, PythonProject } from '../../api';
import { findFiles } from '../../common/workspace.apis';
import { EXTENSION_ROOT_DIR } from '../../common/constants';
import { Installable, selectFromCommonPackagesToInstall, selectFromInstallableToInstall } from '../common/pickers';
Expand Down Expand Up @@ -76,6 +76,7 @@ async function selectWorkspaceOrCommon(
installable: Installable[],
common: Installable[],
showSkipOption: boolean,
installed?: string[],
): Promise<string[] | undefined> {
if (installable.length === 0 && common.length === 0) {
return undefined;
Expand Down Expand Up @@ -116,7 +117,7 @@ async function selectWorkspaceOrCommon(
if (selected.label === PackageManagement.workspaceDependencies) {
return await selectFromInstallableToInstall(installable);
} else if (selected.label === PackageManagement.commonPackages) {
return await selectFromCommonPackagesToInstall(common);
return await selectFromCommonPackagesToInstall(common, installed);
} else {
traceInfo('Package Installer: user selected skip package installation');
return undefined;
Expand All @@ -135,10 +136,15 @@ export async function getWorkspacePackagesToInstall(
api: PythonEnvironmentApi,
options?: PackageInstallOptions,
project?: PythonProject[],
environment?: PythonEnvironment,
): Promise<string[] | undefined> {
const installable = (await getProjectInstallable(api, project)) ?? [];
const common = await getCommonPackages();
return selectWorkspaceOrCommon(installable, common, !!options?.showSkipOption);
let installed: string[] | undefined;
if (environment) {
installed = (await api.getPackages(environment))?.map((pkg) => pkg.name);
}
return selectWorkspaceOrCommon(installable, common, !!options?.showSkipOption, installed);
}

export async function getProjectInstallable(
Expand Down
7 changes: 3 additions & 4 deletions src/managers/common/pickers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,13 @@ async function enterPackageManually(filler?: string): Promise<string[] | undefin

export async function selectFromCommonPackagesToInstall(
common: Installable[],
installed?: string[],
preSelected?: PackageQuickPickItem[] | undefined,
): Promise<string[] | undefined> {
const items: PackageQuickPickItem[] = common.map(installableToQuickPickItem);
const preSelectedItems = items
.filter((i) => i.kind !== QuickPickItemKind.Separator)
.filter((i) =>
preSelected?.find((s) => s.label === i.label && s.description === i.description && s.detail === i.detail),
);
.filter((i) => installed?.find((p) => i.id === p) || preSelected?.find((s) => s.id === i.id));

let selected: PackageQuickPickItem | PackageQuickPickItem[] | undefined;
try {
Expand Down Expand Up @@ -173,7 +172,7 @@ export async function selectFromCommonPackagesToInstall(
return result;
} catch (ex) {
if (ex === QuickInputButtons.Back) {
return selectFromCommonPackagesToInstall(common, selected);
return selectFromCommonPackagesToInstall(common, installed, selected);
}
return undefined;
}
Expand Down