uv.lock: dependents are linked to every locked version of a dependency
What happened:
When a uv.lock locks several versions of the same package, the dependency relationships link each dependent to every locked version of the dependency, not only to the versions it depends on. This happens with a forked resolution, which is common: a project with requires-python = ">=3.9" that depends on pandas>=2.0 locks two pandas and four numpy versions.
In the lock file below, pandas 2.3.3 depends on numpy 1.26.4 and numpy 2.2.6, and pandas 3.0.6 on numpy 2.4.6 and numpy 2.5.3:
[[package]]
name = "pandas"
version = "2.3.3"
dependencies = [
{ name = "numpy", version = "1.26.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
{ name = "numpy", version = "2.2.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.10.*'" },
...syft reports both pandas versions as depending on all four numpy versions:
[email protected] depends on [email protected], [email protected], [email protected], [email protected]
[email protected] depends on [email protected], [email protected], [email protected], [email protected]What you expected to happen:
[email protected] depends on [email protected], [email protected]
[email protected] depends on [email protected], [email protected]Steps to reproduce the issue:
# pyproject.toml
[project]
name = "forkdemo"
version = "0.1.0"
requires-python = ">=3.9"
dependencies = [
"numpy>=1.24,<2; python_version < '3.10'",
"numpy>=2.1; python_version >= '3.10'",
"pandas>=2.0",
]uv lock
syft scan dir:. -o syft-json > sbom.jsonThen list the dependency-of relationships whose child is a pandas package.
Anything else we need to know?:
The uv lock parser resolves dependencies by name only: uvLockDependencySpecifier provides and requires packageRef(name, ""), so every locked version of a name satisfies the requirement. The comment in uvLockPackages says "The uv lock file doesn't store the dependency version in the dependency structure", but uv does record version in a dependency entry whenever several versions of that package are locked (it omits it only when the name is unique). uvDependencies doesn't read that field.
A fix would read version and use it when resolving, which probably means adding it to PythonUvLockDependencyEntry and therefore a schema change. I'm happy to send a PR if that direction works for you.
Environment:
- Output of
syft version: built frommainat a76b5fa3 - OS: macOS 26.5.2 (arm64)
Source: anchore/syft