Revert normalization of trailing slashes on index URLs (#14511)

Reverts:

- #14349
- #14346
- #14245

Retains the test cases. Includes a `find-links` test case.

Supersedes

- https://github.com/astral-sh/uv/pull/14387
- https://github.com/astral-sh/uv/pull/14503

We originally got a report at
https://github.com/astral-sh/uv/issues/13707 that inclusion of a
trailing slash on an index URL was causing lockfile churn despite having
no semantic meaning and resolved the issue by adding normalization that
stripped trailing slashes at parse time.

We then discovered that, while there are not semantic differences for
trailing slashes on Simple API index URLs, there are differences for
some flat (or find links) indexes. As reported in
https://github.com/astral-sh/uv/issues/14367, the change in
https://github.com/astral-sh/uv/pull/14245 caused a regression for at
least one user.

We attempted to fix the regression via a few approaches.

https://github.com/astral-sh/uv/pull/14387 attempted to differentiate
between Simple API and flat index URL parsing, but failed to account for
the `Deserialize` implementation, which always assumed Simple API-style
index URLs and incorrectly trimmed trailing slashes in various cases
where we deserialized the `IndexUrl` type from a file. I attempted to
resolve this by performing a larger refactor, but it ended up being
quite painful. In particular, the `Index` type was a blocker — we don't
know the `IndexUrl` variant until we've parsed the `IndexFormat` and
having a multi-stage deserializer is not appealing but adding a new
intermediate type (i.e., `RawIndex`) is painful due to the pervasiveness
of `Index`. Given that we've regressed behavior here and there's not a
straight-forward fix, we're reverting the normalization entirely.

https://github.com/astral-sh/uv/pull/14503 attempted to perform
normalization at compare-time, but that means we'd fail to invalidate
the lockfile when the a trailing slash was added or removed and given
that a trailing slash has semantic meaning for a find-links URL... we'd
have another correctness problem.

After this revert, we'll retain all index URLs verbatim. The downside to
this approach is that we'll be adding a bunch of trailing slashes back
to lockfiles that we previously normalized out, and we'll be reverting
our fix for users with inconsistent trailing slashes on their index
URLs. Users affected by the original motivating issue should use
consistent trailing slashes on their URLs, as they do frequently have
semantic meaning. We may want to revisit normalization and type aware
index URL parsing as part of a larger change.

Closes  https://github.com/astral-sh/uv/issues/14367
This commit is contained in:
Zanie Blue 2025-07-09 06:50:31 -05:00 committed by GitHub
parent afcbcc7498
commit 2709c441a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 344 additions and 266 deletions

View file

@ -169,26 +169,6 @@ impl UrlString {
.map(|(path, _)| Cow::Owned(UrlString(SmallString::from(path)))) .map(|(path, _)| Cow::Owned(UrlString(SmallString::from(path))))
.unwrap_or(Cow::Borrowed(self)) .unwrap_or(Cow::Borrowed(self))
} }
/// Return the [`UrlString`] (as a [`Cow`]) with trailing slash removed.
///
/// This matches the semantics of [`Url::pop_if_empty`], which will not trim a trailing slash if
/// it's the only path segment, e.g., `https://example.com/` would be unchanged.
#[must_use]
pub fn without_trailing_slash(&self) -> Cow<'_, Self> {
self.as_ref()
.strip_suffix('/')
.filter(|path| {
// Only strip the trailing slash if there's _another_ trailing slash that isn't a
// part of the scheme.
path.split_once("://")
.map(|(_scheme, rest)| rest)
.unwrap_or(path)
.contains('/')
})
.map(|path| Cow::Owned(UrlString(SmallString::from(path))))
.unwrap_or(Cow::Borrowed(self))
}
} }
impl AsRef<str> for UrlString { impl AsRef<str> for UrlString {
@ -283,38 +263,4 @@ mod tests {
); );
assert!(matches!(url.without_fragment(), Cow::Owned(_))); assert!(matches!(url.without_fragment(), Cow::Owned(_)));
} }
#[test]
fn without_trailing_slash() {
// Borrows a URL without a slash
let url = UrlString("https://example.com/path".into());
assert_eq!(&*url.without_trailing_slash(), &url);
assert!(matches!(url.without_trailing_slash(), Cow::Borrowed(_)));
// Removes the trailing slash if present on the URL
let url = UrlString("https://example.com/path/".into());
assert_eq!(
&*url.without_trailing_slash(),
&UrlString("https://example.com/path".into())
);
assert!(matches!(url.without_trailing_slash(), Cow::Owned(_)));
// Does not remove a trailing slash if it's the only path segment
let url = UrlString("https://example.com/".into());
assert_eq!(&*url.without_trailing_slash(), &url);
assert!(matches!(url.without_trailing_slash(), Cow::Borrowed(_)));
// Does not remove a trailing slash if it's the only path segment with a missing scheme
let url = UrlString("example.com/".into());
assert_eq!(&*url.without_trailing_slash(), &url);
assert!(matches!(url.without_trailing_slash(), Cow::Borrowed(_)));
// Removes the trailing slash when the scheme is missing
let url = UrlString("example.com/path/".into());
assert_eq!(
&*url.without_trailing_slash(),
&UrlString("example.com/path".into())
);
assert!(matches!(url.without_trailing_slash(), Cow::Owned(_)));
}
} }

View file

@ -38,8 +38,6 @@ impl IndexUrl {
/// ///
/// If no root directory is provided, relative paths are resolved against the current working /// If no root directory is provided, relative paths are resolved against the current working
/// directory. /// directory.
///
/// Normalizes non-file URLs by removing trailing slashes for consistency.
pub fn parse(path: &str, root_dir: Option<&Path>) -> Result<Self, IndexUrlError> { pub fn parse(path: &str, root_dir: Option<&Path>) -> Result<Self, IndexUrlError> {
let url = match split_scheme(path) { let url = match split_scheme(path) {
Some((scheme, ..)) => { Some((scheme, ..)) => {
@ -258,20 +256,13 @@ impl<'de> serde::de::Deserialize<'de> for IndexUrl {
} }
impl From<VerbatimUrl> for IndexUrl { impl From<VerbatimUrl> for IndexUrl {
fn from(mut url: VerbatimUrl) -> Self { fn from(url: VerbatimUrl) -> Self {
if url.scheme() == "file" { if url.scheme() == "file" {
Self::Path(Arc::new(url)) Self::Path(Arc::new(url))
} else if *url.raw() == *PYPI_URL {
Self::Pypi(Arc::new(url))
} else { } else {
// Remove trailing slashes for consistency. They'll be re-added if necessary when Self::Url(Arc::new(url))
// querying the Simple API.
if let Ok(mut path_segments) = url.raw_mut().path_segments_mut() {
path_segments.pop_if_empty();
}
if *url.raw() == *PYPI_URL {
Self::Pypi(Arc::new(url))
} else {
Self::Url(Arc::new(url))
}
} }
} }
} }

View file

@ -171,11 +171,6 @@ impl VerbatimUrl {
&self.url &self.url
} }
/// Return a mutable reference to the underlying [`DisplaySafeUrl`].
pub fn raw_mut(&mut self) -> &mut DisplaySafeUrl {
&mut self.url
}
/// Convert a [`VerbatimUrl`] into a [`DisplaySafeUrl`]. /// Convert a [`VerbatimUrl`] into a [`DisplaySafeUrl`].
pub fn to_url(&self) -> DisplaySafeUrl { pub fn to_url(&self) -> DisplaySafeUrl {
self.url.clone() self.url.clone()

View file

@ -1478,11 +1478,9 @@ impl Lock {
if let Source::Registry(index) = &package.id.source { if let Source::Registry(index) = &package.id.source {
match index { match index {
RegistrySource::Url(url) => { RegistrySource::Url(url) => {
// Normalize URL before validating.
let url = url.without_trailing_slash();
if remotes if remotes
.as_ref() .as_ref()
.is_some_and(|remotes| !remotes.contains(&url)) .is_some_and(|remotes| !remotes.contains(url))
{ {
let name = &package.id.name; let name = &package.id.name;
let version = &package let version = &package
@ -1490,11 +1488,7 @@ impl Lock {
.version .version
.as_ref() .as_ref()
.expect("version for registry source"); .expect("version for registry source");
return Ok(SatisfiesResult::MissingRemoteIndex( return Ok(SatisfiesResult::MissingRemoteIndex(name, version, url));
name,
version,
url.into_owned(),
));
} }
} }
RegistrySource::Path(path) => { RegistrySource::Path(path) => {
@ -1799,7 +1793,7 @@ pub enum SatisfiesResult<'lock> {
/// The lockfile is missing a workspace member. /// The lockfile is missing a workspace member.
MissingRoot(PackageName), MissingRoot(PackageName),
/// The lockfile referenced a remote index that was not provided /// The lockfile referenced a remote index that was not provided
MissingRemoteIndex(&'lock PackageName, &'lock Version, UrlString), MissingRemoteIndex(&'lock PackageName, &'lock Version, &'lock UrlString),
/// The lockfile referenced a local index that was not provided /// The lockfile referenced a local index that was not provided
MissingLocalIndex(&'lock PackageName, &'lock Version, &'lock Path), MissingLocalIndex(&'lock PackageName, &'lock Version, &'lock Path),
/// A package in the lockfile contains different `requires-dist` metadata than expected. /// A package in the lockfile contains different `requires-dist` metadata than expected.

View file

@ -4374,7 +4374,7 @@ fn add_lower_bound_local() -> Result<()> {
filters => context.filters(), filters => context.filters(),
}, { }, {
assert_snapshot!( assert_snapshot!(
pyproject_toml, @r#" pyproject_toml, @r###"
[project] [project]
name = "project" name = "project"
version = "0.1.0" version = "0.1.0"
@ -4384,8 +4384,8 @@ fn add_lower_bound_local() -> Result<()> {
] ]
[[tool.uv.index]] [[tool.uv.index]]
url = "https://astral-sh.github.io/packse/PACKSE_VERSION/simple-html" url = "https://astral-sh.github.io/packse/PACKSE_VERSION/simple-html/"
"# "###
); );
}); });
@ -4403,7 +4403,7 @@ fn add_lower_bound_local() -> Result<()> {
[[package]] [[package]]
name = "local-simple-a" name = "local-simple-a"
version = "1.2.3+foo" version = "1.2.3+foo"
source = { registry = "https://astral-sh.github.io/packse/PACKSE_VERSION/simple-html" } source = { registry = "https://astral-sh.github.io/packse/PACKSE_VERSION/simple-html/" }
sdist = { url = "https://astral-sh.github.io/packse/PACKSE_VERSION/files/local_simple_a-1.2.3+foo.tar.gz", hash = "sha256:ebd55c4a79d0a5759126657cb289ff97558902abcfb142e036b993781497edac" } sdist = { url = "https://astral-sh.github.io/packse/PACKSE_VERSION/files/local_simple_a-1.2.3+foo.tar.gz", hash = "sha256:ebd55c4a79d0a5759126657cb289ff97558902abcfb142e036b993781497edac" }
wheels = [ wheels = [
{ url = "https://astral-sh.github.io/packse/PACKSE_VERSION/files/local_simple_a-1.2.3+foo-py3-none-any.whl", hash = "sha256:6f30e2e709b3e171cd734bb58705229a582587c29e0a7041227435583c7224cc" }, { url = "https://astral-sh.github.io/packse/PACKSE_VERSION/files/local_simple_a-1.2.3+foo-py3-none-any.whl", hash = "sha256:6f30e2e709b3e171cd734bb58705229a582587c29e0a7041227435583c7224cc" },
@ -9259,7 +9259,7 @@ fn add_index_with_trailing_slash() -> Result<()> {
filters => context.filters(), filters => context.filters(),
}, { }, {
assert_snapshot!( assert_snapshot!(
pyproject_toml, @r#" pyproject_toml, @r###"
[project] [project]
name = "project" name = "project"
version = "0.1.0" version = "0.1.0"
@ -9272,8 +9272,8 @@ fn add_index_with_trailing_slash() -> Result<()> {
constraint-dependencies = ["markupsafe<3"] constraint-dependencies = ["markupsafe<3"]
[[tool.uv.index]] [[tool.uv.index]]
url = "https://pypi.org/simple" url = "https://pypi.org/simple/"
"# "###
); );
}); });
@ -9297,7 +9297,7 @@ fn add_index_with_trailing_slash() -> Result<()> {
[[package]] [[package]]
name = "iniconfig" name = "iniconfig"
version = "2.0.0" version = "2.0.0"
source = { registry = "https://pypi.org/simple" } source = { registry = "https://pypi.org/simple/" }
sdist = { url = "https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", size = 4646, upload-time = "2023-01-07T11:08:11.254Z" } sdist = { url = "https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", size = 4646, upload-time = "2023-01-07T11:08:11.254Z" }
wheels = [ wheels = [
{ url = "https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374", size = 5892, upload-time = "2023-01-07T11:08:09.864Z" }, { url = "https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374", size = 5892, upload-time = "2023-01-07T11:08:09.864Z" },
@ -11194,7 +11194,7 @@ fn repeated_index_cli_reversed() -> Result<()> {
filters => context.filters(), filters => context.filters(),
}, { }, {
assert_snapshot!( assert_snapshot!(
pyproject_toml, @r#" pyproject_toml, @r###"
[project] [project]
name = "project" name = "project"
version = "0.1.0" version = "0.1.0"
@ -11204,8 +11204,8 @@ fn repeated_index_cli_reversed() -> Result<()> {
] ]
[[tool.uv.index]] [[tool.uv.index]]
url = "https://test.pypi.org/simple" url = "https://test.pypi.org/simple/"
"# "###
); );
}); });
@ -11226,7 +11226,7 @@ fn repeated_index_cli_reversed() -> Result<()> {
[[package]] [[package]]
name = "iniconfig" name = "iniconfig"
version = "2.0.0" version = "2.0.0"
source = { registry = "https://test.pypi.org/simple" } source = { registry = "https://test.pypi.org/simple/" }
sdist = { url = "https://test-files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", size = 4646, upload-time = "2023-01-07T11:08:16.826Z" } sdist = { url = "https://test-files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", size = 4646, upload-time = "2023-01-07T11:08:16.826Z" }
wheels = [ wheels = [
{ url = "https://test-files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374", size = 5892, upload-time = "2023-01-07T11:08:14.843Z" }, { url = "https://test-files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374", size = 5892, upload-time = "2023-01-07T11:08:14.843Z" },

View file

@ -15500,7 +15500,7 @@ fn lock_add_empty_dependency_group() -> Result<()> {
/// Use a trailing slash on the declared index. /// Use a trailing slash on the declared index.
#[test] #[test]
fn lock_trailing_slash() -> Result<()> { fn lock_trailing_slash_index_url() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml"); let pyproject_toml = context.temp_dir.child("pyproject.toml");
@ -15543,7 +15543,7 @@ fn lock_trailing_slash() -> Result<()> {
[[package]] [[package]]
name = "anyio" name = "anyio"
version = "3.7.0" version = "3.7.0"
source = { registry = "https://pypi.org/simple" } source = { registry = "https://pypi.org/simple/" }
dependencies = [ dependencies = [
{ name = "idna" }, { name = "idna" },
{ name = "sniffio" }, { name = "sniffio" },
@ -15556,7 +15556,7 @@ fn lock_trailing_slash() -> Result<()> {
[[package]] [[package]]
name = "idna" name = "idna"
version = "3.6" version = "3.6"
source = { registry = "https://pypi.org/simple" } 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, upload-time = "2023-11-25T15:40:54.902Z" } sdist = { url = "https://files.pythonhosted.org/packages/bf/3f/ea4b9117521a1e9c50344b909be7886dd00a519552724809bb1f486986c2/idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca", size = 175426, upload-time = "2023-11-25T15:40:54.902Z" }
wheels = [ wheels = [
{ url = "https://files.pythonhosted.org/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f", size = 61567, upload-time = "2023-11-25T15:40:52.604Z" }, { url = "https://files.pythonhosted.org/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f", size = 61567, upload-time = "2023-11-25T15:40:52.604Z" },
@ -15576,7 +15576,7 @@ fn lock_trailing_slash() -> Result<()> {
[[package]] [[package]]
name = "sniffio" name = "sniffio"
version = "1.3.1" version = "1.3.1"
source = { registry = "https://pypi.org/simple" } 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, upload-time = "2024-02-25T23:20:04.057Z" } sdist = { url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc", size = 20372, upload-time = "2024-02-25T23:20:04.057Z" }
wheels = [ wheels = [
{ url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2", size = 10235, upload-time = "2024-02-25T23:20:01.196Z" }, { url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2", size = 10235, upload-time = "2024-02-25T23:20:01.196Z" },
@ -28310,10 +28310,10 @@ fn lock_conflict_for_disjoint_platform() -> Result<()> {
Ok(()) Ok(())
} }
/// Add a package with an `--index` URL with no trailing slash. Run `uv lock --locked` /// Add a package with an `--index` URL with no trailing slash while an index with the same URL
/// with a `pyproject.toml` with that same URL but with a trailing slash. /// exists with a trailing slash in the `pyproject.toml`.
#[test] #[test]
fn lock_with_inconsistent_trailing_slash() -> Result<()> { fn lock_trailing_slash_index_url_in_pyproject_not_index_argument() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml"); let pyproject_toml = context.temp_dir.child("pyproject.toml");
@ -28408,20 +28408,22 @@ fn lock_with_inconsistent_trailing_slash() -> Result<()> {
// Re-run with `--locked`. // Re-run with `--locked`.
uv_snapshot!(context.filters(), context.lock().arg("--locked"), @r" uv_snapshot!(context.filters(), context.lock().arg("--locked"), @r"
success: true success: false
exit_code: 0 exit_code: 2
----- stdout ----- ----- stdout -----
----- stderr ----- ----- stderr -----
Resolved 4 packages in [TIME] Resolved 4 packages in [TIME]
error: The lockfile at `uv.lock` needs to be updated, but `--locked` was provided. To update the lockfile, run `uv lock`.
"); ");
Ok(()) Ok(())
} }
/// Run `uv lock --locked` with a lockfile with trailing slashes on index URLs. /// Run `uv lock --locked` with a lockfile with trailing slashes on the index URL but a
/// `pyproject.toml` without a trailing slash on the index URL.
#[test] #[test]
fn lock_with_index_trailing_slashes_in_lockfile() -> Result<()> { fn lock_trailing_slash_index_url_in_lockfile_not_pyproject() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml"); let pyproject_toml = context.temp_dir.child("pyproject.toml");
@ -28497,20 +28499,22 @@ fn lock_with_index_trailing_slashes_in_lockfile() -> Result<()> {
// Run `uv lock --locked`. // Run `uv lock --locked`.
uv_snapshot!(context.filters(), context.lock().arg("--locked"), @r" uv_snapshot!(context.filters(), context.lock().arg("--locked"), @r"
success: true success: false
exit_code: 0 exit_code: 2
----- stdout ----- ----- stdout -----
----- stderr ----- ----- stderr -----
Resolved 4 packages in [TIME] Resolved 4 packages in [TIME]
error: The lockfile at `uv.lock` needs to be updated, but `--locked` was provided. To update the lockfile, run `uv lock`.
"); ");
Ok(()) Ok(())
} }
/// Run `uv lock --locked` with a lockfile with trailing slashes on index URLs. /// Run `uv lock --locked` with `pyproject.toml` with trailing slashes on the index URL but a
/// lockfile without trailing slashes on the index URL.
#[test] #[test]
fn lock_with_index_trailing_slashes_in_pyproject_toml() -> Result<()> { fn lock_trailing_slash_index_url_in_pyproject_and_not_lockfile() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml"); let pyproject_toml = context.temp_dir.child("pyproject.toml");
@ -28586,20 +28590,22 @@ fn lock_with_index_trailing_slashes_in_pyproject_toml() -> Result<()> {
// Run `uv lock --locked`. // Run `uv lock --locked`.
uv_snapshot!(context.filters(), context.lock().arg("--locked"), @r" uv_snapshot!(context.filters(), context.lock().arg("--locked"), @r"
success: true success: false
exit_code: 0 exit_code: 2
----- stdout ----- ----- stdout -----
----- stderr ----- ----- stderr -----
Resolved 4 packages in [TIME] Resolved 4 packages in [TIME]
error: The lockfile at `uv.lock` needs to be updated, but `--locked` was provided. To update the lockfile, run `uv lock`.
"); ");
Ok(()) Ok(())
} }
/// Run `uv lock --locked` with a lockfile with trailing slashes on index URLs. /// Run `uv lock --locked` with a lockfile and `pyproject.toml` with trailing slashes on the index
/// URL.
#[test] #[test]
fn lock_with_index_trailing_slashes_in_lockfile_and_pyproject_toml() -> Result<()> { fn lock_trailing_slash_index_url_in_lockfile_and_pyproject_toml() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml"); let pyproject_toml = context.temp_dir.child("pyproject.toml");
@ -28686,6 +28692,152 @@ fn lock_with_index_trailing_slashes_in_lockfile_and_pyproject_toml() -> Result<(
Ok(()) Ok(())
} }
#[test]
fn lock_trailing_slash_find_links() -> Result<()> {
let context = TestContext::new("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["packaging==23.2"]
[tool.uv]
no-index = true
find-links = ["https://pypi.org/simple/packaging"]
"#,
)?;
uv_snapshot!(context.filters(), context.lock(), @r"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 2 packages in [TIME]
");
let lock = context.read("uv.lock");
insta::with_settings!({
filters => context.filters(),
}, {
assert_snapshot!(
lock, @r#"
version = 1
revision = 2
requires-python = ">=3.12"
[options]
exclude-newer = "2024-03-25T00:00:00Z"
[[package]]
name = "packaging"
version = "23.2"
source = { registry = "https://pypi.org/simple/packaging" }
sdist = { url = "https://files.pythonhosted.org/packages/fb/2b/9b9c33ffed44ee921d0967086d653047286054117d584f1b1a7c22ceaf7b/packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/ec/1a/610693ac4ee14fcdf2d9bf3c493370e4f2ef7ae2e19217d7a237ff42367d/packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7" },
]
[[package]]
name = "project"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "packaging" },
]
[package.metadata]
requires-dist = [{ name = "packaging", specifier = "==23.2" }]
"#
);
});
// Re-run with `--locked`.
uv_snapshot!(context.filters(), context.lock().arg("--locked"), @r"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 2 packages in [TIME]
");
// Add a trailing slash, which should invalidate the lockfile
let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["packaging==23.2"]
[tool.uv]
no-index = true
find-links = ["https://pypi.org/simple/packaging/"]
"#,
)?;
// Re-run with `--locked`
uv_snapshot!(context.filters(), context.lock().arg("--locked"), @r"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
Resolved 2 packages in [TIME]
error: The lockfile at `uv.lock` needs to be updated, but `--locked` was provided. To update the lockfile, run `uv lock`.
");
uv_snapshot!(context.filters(), context.lock(), @r"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 2 packages in [TIME]
");
let lock = context.read("uv.lock");
insta::with_settings!({
filters => context.filters(),
}, {
assert_snapshot!(
lock, @r#"
version = 1
revision = 2
requires-python = ">=3.12"
[options]
exclude-newer = "2024-03-25T00:00:00Z"
[[package]]
name = "packaging"
version = "23.2"
source = { registry = "https://pypi.org/simple/packaging/" }
sdist = { url = "https://files.pythonhosted.org/packages/fb/2b/9b9c33ffed44ee921d0967086d653047286054117d584f1b1a7c22ceaf7b/packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/ec/1a/610693ac4ee14fcdf2d9bf3c493370e4f2ef7ae2e19217d7a237ff42367d/packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7" },
]
[[package]]
name = "project"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "packaging" },
]
[package.metadata]
requires-dist = [{ name = "packaging", specifier = "==23.2" }]
"#
);
});
Ok(())
}
#[test] #[test]
fn lock_prefix_match() -> Result<()> { fn lock_prefix_match() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");

File diff suppressed because it is too large Load diff

View file

@ -9939,7 +9939,7 @@ fn sync_required_environment_hint() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 2 packages in [TIME] Resolved 2 packages in [TIME]
error: Distribution `no-sdist-no-wheels-with-matching-platform-a==1.0.0 @ registry+https://astral-sh.github.io/packse/PACKSE_VERSION/simple-html` can't be installed because it doesn't have a source distribution or wheel for the current platform error: Distribution `no-sdist-no-wheels-with-matching-platform-a==1.0.0 @ registry+https://astral-sh.github.io/packse/PACKSE_VERSION/simple-html/` can't be installed because it doesn't have a source distribution or wheel for the current platform
hint: You're on [PLATFORM] (`[TAG]`), but `no-sdist-no-wheels-with-matching-platform-a` (v1.0.0) only has wheels for the following platform: `macosx_10_0_ppc64`; consider adding your platform to `tool.uv.required-environments` to ensure uv resolves to a version with compatible wheels hint: You're on [PLATFORM] (`[TAG]`), but `no-sdist-no-wheels-with-matching-platform-a` (v1.0.0) only has wheels for the following platform: `macosx_10_0_ppc64`; consider adding your platform to `tool.uv.required-environments` to ensure uv resolves to a version with compatible wheels
"); ");