-
Notifications
You must be signed in to change notification settings - Fork 41
Enhance sorting of installable files to prioritize shallower paths in getProjectInstallable function #1428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Enhance sorting of installable files to prioritize shallower paths in getProjectInstallable function #1428
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,4 +199,36 @@ suite('Pip Utils - getProjectInstallable', () => { | |
| assert.ok(firstResult.uri, 'Should have a URI'); | ||
| assert.ok(firstResult.uri.fsPath.startsWith(workspacePath), 'Should be in workspace directory'); | ||
| }); | ||
|
|
||
| test('should sort shallower files before deeper ones', async () => { | ||
| // Arrange: Return files at different depths, with deeper ones discovered first | ||
| findFilesStub.callsFake((pattern: string) => { | ||
| const workspacePath = Uri.file('/test/path/root').fsPath; | ||
| if (pattern === '**/*requirements*.txt') { | ||
| return Promise.resolve([ | ||
| Uri.file(path.join(workspacePath, 'deep', 'nested', 'sub', 'requirements.txt')), | ||
| Uri.file(path.join(workspacePath, 'subdir', 'dev-requirements.txt')), | ||
| ]); | ||
| } else if (pattern === '*requirements*.txt') { | ||
| return Promise.resolve([Uri.file(path.join(workspacePath, 'requirements.txt'))]); | ||
| } else if (pattern === '**/requirements/*.txt') { | ||
| return Promise.resolve([]); | ||
| } else if (pattern === '**/pyproject.toml') { | ||
| return Promise.resolve([]); | ||
| } | ||
| return Promise.resolve([]); | ||
| }); | ||
|
|
||
| // Act | ||
| const workspacePath = Uri.file('/test/path/root').fsPath; | ||
| const projects = [{ name: 'workspace', uri: Uri.file(workspacePath) }]; | ||
| const result = (await getProjectInstallable(mockApi as PythonEnvironmentApi, projects)).installables; | ||
|
|
||
| // Assert: root-level requirements.txt should come first | ||
| assert.strictEqual(result.length, 3); | ||
| const names = result.map((r) => r.name); | ||
| assert.strictEqual(names[0], 'requirements.txt', 'Root-level requirements.txt should be first'); | ||
| assert.strictEqual(names[1], 'dev-requirements.txt', 'One-level-deep file should be second'); | ||
| assert.strictEqual(names[2], 'requirements.txt', 'Deeply nested file should be last'); | ||
| }); | ||
|
Comment on lines
+205
to
+233
|
||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depth is currently computed from the absolute
fsPath. If multiple project roots are present, absolute path depth can differ due to the root’s location on disk (e.g.,/mnt/x/projectvs/x/project), which can reorder files across projects in a way unrelated to ‘shallower within the project’. To match the intent (‘top-level within a project’), compute depth relative to the owning project root (e.g.,api.getPythonProject(uri)?.uri.fsPath) and count segments on the relative path (after normalization and trimming empty segments).