Skip to content

Extract DownloadUrl from uv.lock file - #1852

Closed
ryanbrandenburg wants to merge 1 commit into
mainfrom
rybrande/uvlock_data
Closed

Extract DownloadUrl from uv.lock file#1852
ryanbrandenburg wants to merge 1 commit into
mainfrom
rybrande/uvlock_data

Conversation

@ryanbrandenburg

Copy link
Copy Markdown
Contributor

This gets us extracting a DownloadUrl from packages in uv.lock files using either sdist (source distribution) or wheel (a pre-built distribution format).

Because the wheels field is an array that may contain many links (per-build-environement compilations) I thought it was preferable to offer the singular and platform-agnostic sdist as the primary download location.

The DTO PR and this will conflict with each other.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds extraction of a preferred artifact download URL from uv.lock packages (favoring sdist.url with a wheels[].url fallback) and surfaces it on detected PipComponents to improve package provenance in Component Detection’s Python/uv ecosystem support.

Changes:

  • Parse sdist.url and, when missing, fall back to the first wheels[].url in UvLock parsing.
  • Propagate the parsed URL onto PipComponent.DownloadUrl when converting UvPackage to a typed component.
  • Add unit tests covering URL parsing and detector-level behavior.
Show a summary per file
File Description
test/Microsoft.ComponentDetection.Detectors.Tests/UvLockTests.cs Adds parsing tests for DownloadUrl from sdist and wheels.
test/Microsoft.ComponentDetection.Detectors.Tests/UvLockDetectorTests.cs Adds detector test asserting PipComponent.DownloadUrl is populated from sdist.
src/Microsoft.ComponentDetection.Detectors/uv/UvPackage.cs Stores parsed URL on UvPackage and applies it to PipComponent.
src/Microsoft.ComponentDetection.Detectors/uv/UvLock.cs Extends TOML parsing to extract sdist/wheels URLs with helper methods.

Review details

  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment on lines +158 to +161
private static string? TryGetUrlFromArtifactTable(TomlTable artifactTable)
{
return artifactTable.TryGetValue("url", out var urlObj) && urlObj is string url ? url : null;
}
Comment on lines +35 to +41
var component = new PipComponent(this.Name, this.Version);
if (Uri.TryCreate(this.DownloadUrl, UriKind.Absolute, out var downloadUri))
{
component.DownloadUrl = downloadUri;
}

return component;
@ryanbrandenburg

Copy link
Copy Markdown
Contributor Author

CoPilot makes a good point, if the DownloadUrl is used to make identity decisions than selecting it from a wheels list of even a sdist may be inappropriate since neither of those are proport to be "canonical" links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants