Skip to content

Commit

Permalink
Use editable install only when project and build-system are prese…
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig authored and seeM committed May 12, 2024
1 parent 6876734 commit 9e44f84
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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.');
}
Expand All @@ -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.');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9e44f84

Please sign in to comment.