Skip to content

Commit 04753c4

Browse files
authored
Ensure editable install is triggered if pyproject.toml is found. (#20572)
No-changelog because this feature is not in stable yet.
1 parent 80ef35f commit 04753c4

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,21 @@ async function getPipRequirementsFiles(
2525
return files;
2626
}
2727

28-
async function getTomlOptionalDeps(tomlPath: string): Promise<string[] | undefined> {
29-
if (await fs.pathExists(tomlPath)) {
30-
const content = await fs.readFile(tomlPath, 'utf-8');
31-
const extras: string[] = [];
32-
try {
33-
const toml = tomljs.parse(content);
34-
if (toml.project && (toml.project as Record<string, Array<string>>)['optional-dependencies']) {
35-
const deps = (toml.project as Record<string, Record<string, Array<string>>>)['optional-dependencies'];
36-
for (const key of Object.keys(deps)) {
37-
extras.push(key);
38-
}
28+
async function getTomlOptionalDeps(tomlPath: string): Promise<string[]> {
29+
const content = await fs.readFile(tomlPath, 'utf-8');
30+
const extras: string[] = [];
31+
try {
32+
const toml = tomljs.parse(content);
33+
if (toml.project && (toml.project as Record<string, Array<string>>)['optional-dependencies']) {
34+
const deps = (toml.project as Record<string, Record<string, Array<string>>>)['optional-dependencies'];
35+
for (const key of Object.keys(deps)) {
36+
extras.push(key);
3937
}
40-
} catch (err) {
41-
traceError('Failed to parse `pyproject.toml`:', err);
4238
}
43-
return extras;
39+
} catch (err) {
40+
traceError('Failed to parse `pyproject.toml`:', err);
4441
}
45-
return undefined;
42+
return extras;
4643
}
4744

4845
async function pickTomlExtras(extras: string[], token?: CancellationToken): Promise<string[] | undefined> {
@@ -109,9 +106,18 @@ export async function pickPackagesToInstall(
109106
): Promise<IPackageInstallSelection | undefined> {
110107
const tomlPath = path.join(workspaceFolder.uri.fsPath, 'pyproject.toml');
111108
traceVerbose(`Looking for toml pyproject.toml with optional dependencies at: ${tomlPath}`);
112-
const extras = await getTomlOptionalDeps(tomlPath);
113109

114-
if (extras && extras.length > 0) {
110+
let extras: string[] = [];
111+
let tomlExists = false;
112+
if (await fs.pathExists(tomlPath)) {
113+
tomlExists = true;
114+
extras = await getTomlOptionalDeps(tomlPath);
115+
}
116+
117+
if (tomlExists) {
118+
if (extras.length === 0) {
119+
return { installType: 'toml', installList: [], source: tomlPath };
120+
}
115121
traceVerbose('Found toml with optional dependencies.');
116122
const installList = await pickTomlExtras(extras, token);
117123
if (installList) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ suite('Venv Utils test', () => {
5454
const actual = await pickPackagesToInstall(workspace1);
5555
assert.isTrue(showQuickPickStub.notCalled);
5656
assert.deepStrictEqual(actual, {
57-
installType: 'none',
57+
installType: 'toml',
5858
installList: [],
59+
source: path.join(workspace1.uri.fsPath, 'pyproject.toml'),
5960
});
6061
});
6162

0 commit comments

Comments
 (0)