Skip to content

Commit

Permalink
Introduce default-source to slim lockfile
Browse files Browse the repository at this point in the history
Currently, we're repeating the same `source` line for every package, so the lockfiles have a lot of:

```toml
source = { registry = "https://pypi.org/simple" }
```

This PR introduces a top level `default-source` entry set to the default index URL, if any. When the source matches, we don't repeat the `source` entry. This reduces the number of lines in `uv.lock` noticeably across the board:

* A small data science project: 421 -> 394
* A small bot: 455 -> 426
* Transformers: 5683 -> 5419
* Warehouse: 4632 -> 4306
* Airflow: 2709 -> 2576

Caveat: We don't have good multi-index coverage (#5882).

3/3 for #4893
  • Loading branch information
konstin committed Aug 7, 2024
1 parent e4ec6e4 commit 7950c0e
Show file tree
Hide file tree
Showing 17 changed files with 472 additions and 479 deletions.
184 changes: 144 additions & 40 deletions crates/uv-resolver/src/lock.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ok(
version: 1,
fork_markers: None,
requires_python: None,
default_source: None,
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
exclude_newer: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ok(
version: 1,
fork_markers: None,
requires_python: None,
default_source: None,
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
exclude_newer: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ok(
version: 1,
fork_markers: None,
requires_python: None,
default_source: None,
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
exclude_newer: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Err(
Error {
inner: Error {
inner: TomlError {
message: "dependency a has missing `source` field but has more than one matching distribution",
message: "dependency a has no `source` and no `default-source` is defined field but has more than one matching distribution",
raw: None,
keys: [],
span: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ok(
version: 1,
fork_markers: None,
requires_python: None,
default_source: None,
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
exclude_newer: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ok(
version: 1,
fork_markers: None,
requires_python: None,
default_source: None,
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
exclude_newer: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ok(
version: 1,
fork_markers: None,
requires_python: None,
default_source: None,
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
exclude_newer: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ok(
version: 1,
fork_markers: None,
requires_python: None,
default_source: None,
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
exclude_newer: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ok(
version: 1,
fork_markers: None,
requires_python: None,
default_source: None,
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
exclude_newer: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ok(
version: 1,
fork_markers: None,
requires_python: None,
default_source: None,
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
exclude_newer: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Ok(
version: 1,
fork_markers: None,
requires_python: None,
default_source: None,
resolution_mode: Highest,
prerelease_mode: IfNecessaryOrExplicit,
exclude_newer: None,
Expand Down
5 changes: 4 additions & 1 deletion crates/uv/src/commands/project/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,10 @@ async fn do_lock(
// Notify the user of any resolution diagnostics.
pip::operations::diagnose_resolution(resolution.diagnostics(), printer)?;

Ok(Lock::from_resolution_graph(&resolution)?)
Ok(Lock::from_resolution_graph(
&resolution,
index_locations.index(),
)?)
}

/// Write the lockfile to disk.
Expand Down
30 changes: 12 additions & 18 deletions crates/uv/tests/branching_urls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ fn root_package_splits_transitive_too() -> Result<()> {

assert_snapshot!(fs_err::read_to_string(context.temp_dir.join("uv.lock"))?, @r###"
version = 1
default-source = { registry = "https://pypi.org/simple" }
requires-python = ">=3.11, <3.13"
environment-markers = [
"python_version < '3.12'",
Expand All @@ -219,15 +220,14 @@ fn root_package_splits_transitive_too() -> Result<()> {
version = "0.1.0"
source = { editable = "." }
dependencies = [
{ name = "anyio", version = "4.2.0", source = { registry = "https://pypi.org/simple" }, marker = "python_version < '3.12'" },
{ name = "anyio", version = "4.3.0", source = { registry = "https://pypi.org/simple" }, marker = "python_version >= '3.12'" },
{ name = "anyio", version = "4.2.0", marker = "python_version < '3.12'" },
{ name = "anyio", version = "4.3.0", marker = "python_version >= '3.12'" },
{ name = "b" },
]
[[distribution]]
name = "anyio"
version = "4.2.0"
source = { registry = "https://pypi.org/simple" }
environment-markers = [
"python_version < '3.12'",
]
Expand All @@ -243,7 +243,6 @@ fn root_package_splits_transitive_too() -> Result<()> {
[[distribution]]
name = "anyio"
version = "4.3.0"
source = { registry = "https://pypi.org/simple" }
environment-markers = [
"python_version >= '3.12'",
]
Expand Down Expand Up @@ -284,7 +283,6 @@ fn root_package_splits_transitive_too() -> Result<()> {
[[distribution]]
name = "idna"
version = "3.6"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/bf/3f/ea4b9117521a1e9c50344b909be7886dd00a519552724809bb1f486986c2/idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca", size = 175426 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f", size = 61567 },
Expand Down Expand Up @@ -315,7 +313,6 @@ fn root_package_splits_transitive_too() -> Result<()> {
[[distribution]]
name = "sniffio"
version = "1.3.1"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc", size = 20372 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2", size = 10235 },
Expand Down Expand Up @@ -381,6 +378,7 @@ fn root_package_splits_other_dependencies_too() -> Result<()> {

assert_snapshot!(fs_err::read_to_string(context.temp_dir.join("uv.lock"))?, @r###"
version = 1
default-source = { registry = "https://pypi.org/simple" }
requires-python = ">=3.11, <3.13"
environment-markers = [
"python_version < '3.12'",
Expand All @@ -393,16 +391,15 @@ fn root_package_splits_other_dependencies_too() -> Result<()> {
version = "0.1.0"
source = { editable = "." }
dependencies = [
{ name = "anyio", version = "4.2.0", source = { registry = "https://pypi.org/simple" }, marker = "python_version < '3.12'" },
{ name = "anyio", version = "4.3.0", source = { registry = "https://pypi.org/simple" }, marker = "python_version >= '3.12'" },
{ name = "anyio", version = "4.2.0", marker = "python_version < '3.12'" },
{ name = "anyio", version = "4.3.0", marker = "python_version >= '3.12'" },
{ name = "b1", marker = "python_version < '3.12'" },
{ name = "b2", marker = "python_version >= '3.12'" },
]
[[distribution]]
name = "anyio"
version = "4.2.0"
source = { registry = "https://pypi.org/simple" }
environment-markers = [
"python_version < '3.12'",
]
Expand All @@ -418,7 +415,6 @@ fn root_package_splits_other_dependencies_too() -> Result<()> {
[[distribution]]
name = "anyio"
version = "4.3.0"
source = { registry = "https://pypi.org/simple" }
environment-markers = [
"python_version >= '3.12'",
]
Expand All @@ -436,21 +432,20 @@ fn root_package_splits_other_dependencies_too() -> Result<()> {
version = "0.1.0"
source = { directory = "b1" }
dependencies = [
{ name = "iniconfig", version = "1.1.1", source = { registry = "https://pypi.org/simple" }, marker = "python_version < '3.12'" },
{ name = "iniconfig", version = "1.1.1", marker = "python_version < '3.12'" },
]
[[distribution]]
name = "b2"
version = "0.1.0"
source = { directory = "b2" }
dependencies = [
{ name = "iniconfig", version = "2.0.0", source = { registry = "https://pypi.org/simple" }, marker = "python_version >= '3.12'" },
{ name = "iniconfig", version = "2.0.0", marker = "python_version >= '3.12'" },
]
[[distribution]]
name = "idna"
version = "3.6"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/bf/3f/ea4b9117521a1e9c50344b909be7886dd00a519552724809bb1f486986c2/idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca", size = 175426 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f", size = 61567 },
Expand All @@ -459,7 +454,6 @@ fn root_package_splits_other_dependencies_too() -> Result<()> {
[[distribution]]
name = "iniconfig"
version = "1.1.1"
source = { registry = "https://pypi.org/simple" }
environment-markers = [
"python_version < '3.12'",
]
Expand All @@ -471,7 +465,6 @@ fn root_package_splits_other_dependencies_too() -> Result<()> {
[[distribution]]
name = "iniconfig"
version = "2.0.0"
source = { registry = "https://pypi.org/simple" }
environment-markers = [
"python_version >= '3.12'",
]
Expand All @@ -483,7 +476,6 @@ fn root_package_splits_other_dependencies_too() -> Result<()> {
[[distribution]]
name = "sniffio"
version = "1.3.1"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc", size = 20372 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2", size = 10235 },
Expand Down Expand Up @@ -526,6 +518,7 @@ fn branching_between_registry_and_direct_url() -> Result<()> {
// We have source dist and wheel for the registry, but only the wheel for the direct URL.
assert_snapshot!(fs_err::read_to_string(context.temp_dir.join("uv.lock"))?, @r###"
version = 1
default-source = { registry = "https://pypi.org/simple" }
requires-python = ">=3.11, <3.13"
environment-markers = [
"python_version < '3.12'",
Expand All @@ -538,14 +531,13 @@ fn branching_between_registry_and_direct_url() -> Result<()> {
version = "0.1.0"
source = { editable = "." }
dependencies = [
{ name = "iniconfig", version = "1.1.1", source = { registry = "https://pypi.org/simple" }, marker = "python_version < '3.12'" },
{ name = "iniconfig", version = "1.1.1", marker = "python_version < '3.12'" },
{ name = "iniconfig", version = "2.0.0", source = { url = "https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl" }, marker = "python_version >= '3.12'" },
]
[[distribution]]
name = "iniconfig"
version = "1.1.1"
source = { registry = "https://pypi.org/simple" }
environment-markers = [
"python_version < '3.12'",
]
Expand Down Expand Up @@ -603,6 +595,7 @@ fn branching_urls_of_different_sources_disjoint() -> Result<()> {
// We have source dist and wheel for the registry, but only the wheel for the direct URL.
assert_snapshot!(fs_err::read_to_string(context.temp_dir.join("uv.lock"))?, @r###"
version = 1
default-source = { registry = "https://pypi.org/simple" }
requires-python = ">=3.11, <3.13"
environment-markers = [
"python_version < '3.12'",
Expand Down Expand Up @@ -722,6 +715,7 @@ fn dont_pre_visit_url_packages() -> Result<()> {

assert_snapshot!(fs_err::read_to_string(context.temp_dir.join("uv.lock"))?, @r###"
version = 1
default-source = { registry = "https://pypi.org/simple" }
requires-python = ">=3.11, <3.13"
exclude-newer = "2024-03-25 00:00:00 UTC"
Expand Down
Loading

0 comments on commit 7950c0e

Please sign in to comment.