Exclude editable root packages when scanning uv lockfile - #1868
Open
RKS (rksharma-owg) wants to merge 3 commits into
Open
RKS (rksharma-owg) wants to merge 3 commits into
RKS (rksharma-owg) wants to merge 3 commits into
Conversation
In standard uv projects with a build system or project configuration,
the root project is defined in uv.lock with source = { editable = "." }
rather than source = { virtual = "." }.
Previously, only virtual sources were recognized as root packages, causing
the root project itself to be registered as an external dependency and
preventing its direct and development dependency metadata from being correctly
attributed.
This change parses the editable field from the source table, treats
packages with either virtual or editable sources as root packages, and
aggregates dependency metadata across all root packages in the lockfile.
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Update docs/detectors/uv.md so it reflects the new editable-root behavior.
Pull request overview
Updates uv lockfile scanning to exclude editable root packages from detected components.
Changes:
- Parse and model
source.editable. - Aggregate dependencies across editable and virtual roots.
- Bump the detector version and add regression tests.
File summaries
| File | Summary |
|---|---|
test/Microsoft.ComponentDetection.Detectors.Tests/UvLockTests.cs |
Tests editable-source parsing. |
test/Microsoft.ComponentDetection.Detectors.Tests/UvLockDetectorTests.cs |
Tests editable-root exclusion and dependency classification. |
src/Microsoft.ComponentDetection.Detectors/uv/UvSource.cs |
Adds editable source modeling. Nit (1 vote): update the stale detector documentation. |
src/Microsoft.ComponentDetection.Detectors/uv/UvLockComponentDetector.cs |
Filters editable roots and aggregates dependencies. Nit (1 vote): update the stale detector documentation. |
src/Microsoft.ComponentDetection.Detectors/uv/UvLock.cs |
Parses editable source values. |
Review details
Suppressed comments (2)
src/Microsoft.ComponentDetection.Detectors/uv/UvLockComponentDetector.cs:38
- This changes the behavior documented in
docs/detectors/uv.md:19: editable and workspace-member packages are now filtered byIsRootPackageinstead of being registered as regular components. Please update that known-limitations entry so users are not told the opposite behavior.
return pck.Source?.Virtual != null || pck.Source?.Editable != null;
src/Microsoft.ComponentDetection.Detectors/uv/UvSource.cs:11
- This behavior change leaves
docs/detectors/uv.md:19inaccurate: it still says editable packages are registered as regular components, whileIsRootPackagenow filters them out. Please update/remove that known limitation in the same PR so the detector documentation does not describe the opposite behavior.
public string? Editable { get; set; }
- Files reviewed: 5/5 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Editable workspace members may be incorrectly excluded, and the virtual-source documentation needs correction.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (1)
src/Microsoft.ComponentDetection.Detectors/uv/UvLockComponentDetector.cs:138
- The new
Where(IsRootPackage)path is the behavior that supports multiple workspace roots, but the added detector test only exercises one root package. Add a fixture with at least two editable/virtual roots and distinct production/dev dependencies to verify that both roots contribute toexplicitPackages,devRootNames, andprodRoots; otherwise this central aggregation can regress back to handling only one root without a failing test.
var rootPackages = uvLock.Packages.Where(IsRootPackage).ToList();
var explicitPackages = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var devRootNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var rootPackage in rootPackages)
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an issue where non-virtual root packages in uv projects (defined in
uv.lockwithsource = { editable = "." }) are improperly reported as external components.Fixes #1586
Problem
In
uv.lock, root projects configured with standard project definitions or workspace layouts specify their source as editable (source = { editable = "." }or relative paths) rather than virtual (source = { virtual = "." }).Previously:
UvSourcedid not model or parse theeditableproperty from the lockfile'ssourcetable.UvLockComponentDetector.IsRootPackageonly checkedpck.Source?.Virtual != null.PipComponentdependencies, while their direct dependencies were omitted fromexplicitPackagesand development dependencies were not correctly categorized.Solution
Editableproperty toUvSource.editablefrom the TOMLsourcetable inUvLock.ParsePackage.IsRootPackageto checkpck.Source?.Virtual != null || pck.Source?.Editable != null.OnFileFoundAsync, evaluate all root packages (uvLock.Packages.Where(IsRootPackage)) to aggregate direct dependencies (requires-dist), development dependencies (requires-dev), and production roots across workspace roots.UvLockComponentDetector.Versionfrom 2 to 3.Tests
TestUvLockDetector_EditableRootPackage_ExcludedFromDetectedComponentsinUvLockDetectorTestsreproducing the lockfile structure from Root package issue when scanning uv repository #1586 and asserting:ParsePackage_ParsesSource_EditableOnlyandParsePackage_ParsesSource_EditableAndRegistryunit tests inUvLockTests.