Skip to content

Commit 4f5b347

Browse files
authored
Use editable install only when project and build-system are present in pyproject.toml (#23172)
Fixes #23042
1 parent 3be3401 commit 4f5b347

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/client/pythonEnvironments/creation/provider/venvUtils.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ function tomlHasBuildSystem(toml: tomljs.JsonMap): boolean {
6161
return toml['build-system'] !== undefined;
6262
}
6363

64+
function tomlHasProject(toml: tomljs.JsonMap): boolean {
65+
return toml.project !== undefined;
66+
}
67+
6468
function getTomlOptionalDeps(toml: tomljs.JsonMap): string[] {
6569
const extras: string[] = [];
6670
if (toml.project && (toml.project as tomljs.JsonMap)['optional-dependencies']) {
@@ -139,7 +143,7 @@ async function pickRequirementsFiles(
139143

140144
export function isPipInstallableToml(tomlContent: string): boolean {
141145
const toml = tomlParse(tomlContent);
142-
return tomlHasBuildSystem(toml);
146+
return tomlHasBuildSystem(toml) && tomlHasProject(toml);
143147
}
144148

145149
export interface IPackageInstallSelection {
@@ -162,12 +166,17 @@ export async function pickPackagesToInstall(
162166

163167
let extras: string[] = [];
164168
let hasBuildSystem = false;
169+
let hasProject = false;
165170

166171
if (await fs.pathExists(tomlPath)) {
167172
const toml = tomlParse(await fs.readFile(tomlPath, 'utf-8'));
168173
extras = getTomlOptionalDeps(toml);
169174
hasBuildSystem = tomlHasBuildSystem(toml);
175+
hasProject = tomlHasProject(toml);
170176

177+
if (!hasProject) {
178+
traceVerbose('Create env: Found toml without project. So we will not use editable install.');
179+
}
171180
if (!hasBuildSystem) {
172181
traceVerbose('Create env: Found toml without build system. So we will not use editable install.');
173182
}
@@ -179,7 +188,7 @@ export async function pickPackagesToInstall(
179188
return MultiStepAction.Back;
180189
}
181190

182-
if (hasBuildSystem) {
191+
if (hasBuildSystem && hasProject) {
183192
if (extras.length > 0) {
184193
traceVerbose('Create Env: Found toml with optional dependencies.');
185194

src/test/pythonEnvironments/creation/provider/venvUtils.unit.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ suite('Venv Utils test', () => {
6464
assert.deepStrictEqual(actual, []);
6565
});
6666

67+
test('Toml found with no project table', async () => {
68+
findFilesStub.resolves([]);
69+
pathExistsStub.resolves(true);
70+
readFileStub.resolves(
71+
'[tool.poetry]\nname = "spam"\nversion = "2020.0.0"\n[build-system]\nrequires = ["setuptools ~= 58.0", "cython ~= 0.29.0"]',
72+
);
73+
74+
const actual = await pickPackagesToInstall(workspace1);
75+
assert.isTrue(showQuickPickWithBackStub.notCalled);
76+
assert.deepStrictEqual(actual, []);
77+
});
78+
6779
test('Toml found with no optional deps', async () => {
6880
findFilesStub.resolves([]);
6981
pathExistsStub.resolves(true);

0 commit comments

Comments
 (0)