From 38bb9fbd2c2675475596c2fa3aac8efe52cf3588 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Wed, 3 Apr 2024 10:16:37 -0500 Subject: [PATCH] Use editable install only when `project` and `build-system` are present in `pyproject.toml` (microsoft/vscode-python#23172) Fixes https://github.com/microsoft/vscode-python/issues/23042 --- .../creation/provider/venvUtils.ts | 13 +++++++++++-- .../creation/provider/venvUtils.unit.test.ts | 12 ++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/extensions/positron-python/src/client/pythonEnvironments/creation/provider/venvUtils.ts b/extensions/positron-python/src/client/pythonEnvironments/creation/provider/venvUtils.ts index cc506a11a88..94d20c674a3 100644 --- a/extensions/positron-python/src/client/pythonEnvironments/creation/provider/venvUtils.ts +++ b/extensions/positron-python/src/client/pythonEnvironments/creation/provider/venvUtils.ts @@ -61,6 +61,10 @@ function tomlHasBuildSystem(toml: tomljs.JsonMap): boolean { return toml['build-system'] !== undefined; } +function tomlHasProject(toml: tomljs.JsonMap): boolean { + return toml.project !== undefined; +} + function getTomlOptionalDeps(toml: tomljs.JsonMap): string[] { const extras: string[] = []; if (toml.project && (toml.project as tomljs.JsonMap)['optional-dependencies']) { @@ -139,7 +143,7 @@ async function pickRequirementsFiles( export function isPipInstallableToml(tomlContent: string): boolean { const toml = tomlParse(tomlContent); - return tomlHasBuildSystem(toml); + return tomlHasBuildSystem(toml) && tomlHasProject(toml); } export interface IPackageInstallSelection { @@ -162,12 +166,17 @@ export async function pickPackagesToInstall( let extras: string[] = []; let hasBuildSystem = false; + let hasProject = false; if (await fs.pathExists(tomlPath)) { const toml = tomlParse(await fs.readFile(tomlPath, 'utf-8')); extras = getTomlOptionalDeps(toml); hasBuildSystem = tomlHasBuildSystem(toml); + hasProject = tomlHasProject(toml); + if (!hasProject) { + traceVerbose('Create env: Found toml without project. So we will not use editable install.'); + } if (!hasBuildSystem) { traceVerbose('Create env: Found toml without build system. So we will not use editable install.'); } @@ -179,7 +188,7 @@ export async function pickPackagesToInstall( return MultiStepAction.Back; } - if (hasBuildSystem) { + if (hasBuildSystem && hasProject) { if (extras.length > 0) { traceVerbose('Create Env: Found toml with optional dependencies.'); diff --git a/extensions/positron-python/src/test/pythonEnvironments/creation/provider/venvUtils.unit.test.ts b/extensions/positron-python/src/test/pythonEnvironments/creation/provider/venvUtils.unit.test.ts index 1671026d5dd..053524331ba 100644 --- a/extensions/positron-python/src/test/pythonEnvironments/creation/provider/venvUtils.unit.test.ts +++ b/extensions/positron-python/src/test/pythonEnvironments/creation/provider/venvUtils.unit.test.ts @@ -64,6 +64,18 @@ suite('Venv Utils test', () => { assert.deepStrictEqual(actual, []); }); + test('Toml found with no project table', async () => { + findFilesStub.resolves([]); + pathExistsStub.resolves(true); + readFileStub.resolves( + '[tool.poetry]\nname = "spam"\nversion = "2020.0.0"\n[build-system]\nrequires = ["setuptools ~= 58.0", "cython ~= 0.29.0"]', + ); + + const actual = await pickPackagesToInstall(workspace1); + assert.isTrue(showQuickPickWithBackStub.notCalled); + assert.deepStrictEqual(actual, []); + }); + test('Toml found with no optional deps', async () => { findFilesStub.resolves([]); pathExistsStub.resolves(true);