Commit Graph

60 Commits

Author SHA1 Message Date
Andrei Berenda 51e8da2d1c
Move parsing http retries to EnvironmentOptions (#16284)
## Summary
- Move  parsing `UV_HTTP_RETRIES` to `EnvironmentOptions`

Relates https://github.com/astral-sh/uv/issues/14720

## Test Plan

- Tests with existing tests
2025-10-21 11:14:37 +02:00
konsti 52cc3c8b94
Add missing `UV_TEST_NO_HTTP_RETRY_DELAY` check and better logging (#16313)
The `install_http_retries` test goes from 15s to 0.3s. Additionally, we
log the retry delay.
2025-10-15 20:45:21 +02:00
Charlie Marsh b770639c91
Rename `provides_extras` to `provides_extra` (#15825)
## Summary

This is now consistent with `requires_dist` (singular).
2025-09-14 13:27:45 +00:00
William Woodruff 21a92c1632
feat(publish): include blake2b hash in upload form (#15794) 2025-09-11 16:17:07 -04:00
Harsh Pratap Singh 5f2871e695
Support Gitlab CI/CD as a trusted publisher (#15583)
Co-authored-by: William Woodruff <william@astral.sh>
2025-09-11 10:35:04 -04:00
Charlie Marsh 7606f1ad3c
Add `uv publish --dry-run` (#15638)
## Summary

`uv publish --dry-run` will perform the `--check-url` validation, and
hit the `/validate` endpoint if the registry is known to support
fast-path validation (like pyx). The `/validate` endpoint lets us
validate an upload without uploading the file _contents_, which lets you
skip the expensive step for common mistakes.

In the future, my hope is that the `/validate` step will deprecated in
favor of Upload API 2.0.
2025-09-02 21:24:31 -04:00
Zanie Blue ddf2f5ed8c Remove unused dependencies from `uv auth` preview refactor (#15589) 2025-09-02 13:16:52 -05:00
Zanie Blue 4ad5ae5e6f Add preview warnings to `native-keyring` usage (#15555)
The refactor here was all done by Claude Code.
2025-09-02 13:16:52 -05:00
konsti 289ed86e63
Use a global `BaseClientBuilder` (#15548)
Alternative to #15105

Instead of building a `BaseClientBuilder` from `NetworkSettings` each
time we need a client, we instead build a single `BaseClientBuilder` and
pass it around. The `RegistryClientBuilder` then uses
`BaseClientBuilder` exclusively for configuration. This removes a chunk
of copy-and-paste code, and also moves the fallible `retries_from_env`
into a single place

Borrow vs. clone is mostly ad-hoc, we can change it in either direction
if it matters.

Closes #15105
2025-08-29 13:30:51 -05:00
konsti 59558b13c1
Respect `UV_HTTP_RETRIES` in `uv publish` (#15106)
Previously, publish would always use the default retries, now it
respects `UV_HTTP_RETRIES`

Some awkward error handling to avoid pulling anyhow into uv-publish.
2025-08-06 17:59:17 +02:00
konsti 2ad924d4cf
Use consistent workspace inheritance (#15031)
Following a CI failure in https://github.com/astral-sh/uv/pull/15028,
ensure that all workspace crates are inheriting the MSRV and other
workspace configuration from the workspace root.
2025-08-02 22:03:51 +02:00
Charlie Marsh 785595bd35
Remove retry wrapper when matching on error kind (#14996)
## Summary

We often match on `ErrorKind` to figure out how to handle an error
(e.g., to treat a 404 as "Not found" rather than aborting the program).
Unfortunately, if we retry, we wrap the error in a new kind that
includes the retry count. This PR adds an unwrapping mechanism to ensure
that callers always look at the underlying error.

Closes https://github.com/astral-sh/uv/issues/14941.

Closes https://github.com/astral-sh/uv/issues/14989.
2025-07-31 17:00:01 -04:00
Zanie Blue a701d3c447
Use workspace dependencies for crate dev-dependencies (#14903) 2025-07-25 13:57:49 -05:00
Charlie Marsh d15efb7d91
Add an `IntoIterator` for `FormMetadata` (#14351)
## Summary

Clippy would lint for this if the symbol were public as a matter of API
hygiene, so adding it.
2025-06-29 15:07:07 -04:00
Charlie Marsh 0fef253c4b
Use a dedicated type for form metadata (#14175) 2025-06-20 20:33:29 -04:00
John Mumm 62365d4ec8
Support netrc and same-origin credential propagation on index redirects (#14126)
This PR is a combination of #12920 and #13754. Prior to these changes,
following a redirect when searching indexes would bypass our
authentication middleware. This PR updates uv to support propagating
credentials through our middleware on same-origin redirects and to
support netrc credentials for both same- and cross-origin redirects. It
does not handle the case described in #11097 where the redirect location
itself includes credentials (e.g.,
`https://user:pass@redirect-location.com`). That will be addressed in
follow-up work.

This includes unit tests for the new redirect logic and integration
tests for credential propagation. The automated external registries test
is also passing for AWS CodeArtifact, Azure Artifacts, GCP Artifact
Registry, JFrog Artifactory, GitLab, Cloudsmith, and Gemfury.
2025-06-20 09:21:32 +02:00
John Mumm c19a294a48
Add `DisplaySafeUrl` newtype to prevent leaking of credentials by default (#13560)
Prior to this PR, there were numerous places where uv would leak
credentials in logs. We had a way to mask credentials by calling methods
or a recently-added `redact_url` function, but this was not secure by
default. There were a number of other types (like `GitUrl`) that would
leak credentials on display.

This PR adds a `DisplaySafeUrl` newtype to prevent leaking credentials
when logging by default. It takes a maximalist approach, replacing the
use of `Url` almost everywhere. This includes when first parsing config
files, when storing URLs in types like `GitUrl`, and also when storing
URLs in types that in practice will never contain credentials (like
`DirectorySourceUrl`). The idea is to make it easy for developers to do
the right thing and for the compiler to support this (and to minimize
ever having to manually convert back and forth). Displaying credentials
now requires an active step. Note that despite this maximalist approach,
the use of the newtype should be zero cost.

One conspicuous place this PR does not use `DisplaySafeUrl` is in the
`uv-auth` crate. That would require new clones since there are calls to
`request.url()` that return a `&Url`. One option would have been to make
`DisplaySafeUrl` wrap a `Cow`, but this would lead to lifetime
annotations all over the codebase. I've created a separate PR based on
this one (#13576) that updates `uv-auth` to use `DisplaySafeUrl` with
one new clone. We can discuss the tradeoffs there.

Most of this PR just replaces `Url` with `DisplaySafeUrl`. The core is
`uv_redacted/lib.rs`, where the newtype is implemented. To make it
easier to review the rest, here are some points of note:

* `DisplaySafeUrl` has a `Display` implementation that masks
credentials. Currently, it will still display the username when there is
both a username and password. If we think is the wrong choice, it can
now be changed in one place.
* `DisplaySafeUrl` has a `remove_credentials()` method and also a
`.to_string_with_credentials()` method. This allows us to use it in a
variety of scenarios.
* `IndexUrl::redacted()` was renamed to
`IndexUrl::removed_credentials()` to make it clearer that we are not
masking.
* We convert from a `DisplaySafeUrl` to a `Url` when calling `reqwest`
methods like `.get()` and `.head()`.
* We convert from a `DisplaySafeUrl` to a `Url` when creating a
`uv_auth::Index`. That is because, as mentioned above, I will be
updating the `uv_auth` crate to use this newtype in a separate PR.
* A number of tests (e.g., in `pip_install.rs`) that formerly used
filters to mask tokens in the test output no longer need those filters
since tokens in URLs are now masked automatically.
* The one place we are still knowingly writing credentials to
`pyproject.toml` is when a URL with credentials is passed to `uv add`
with `--raw`. Since displaying credentials is no longer automatic, I
have added a `to_string_with_credentials()` method to the `Pep508Url`
trait. This is used when `--raw` is passed. Adding it to that trait is a
bit weird, but it's the simplest way to achieve the goal. I'm open to
suggestions on how to improve this, but note that because of the way
we're using generic bounds, it's not as simple as just creating a
separate trait for that method.
2025-05-27 00:05:30 +02:00
Charlie Marsh c5032aee80
Bump MSRV to 1.85 and Edition 2024 (#13516)
## Summary

Builds on https://github.com/astral-sh/uv/pull/11724.

Closes https://github.com/astral-sh/uv/issues/13476.
2025-05-18 19:38:43 -04:00
konsti 5d37c7ecc5
Apply first set of Rustfmt edition 2024 changes (#13478)
Rustfmt introduces a lot of formatting changes in the 2024 edition. To
not break everything all at once, we split out the set of formatting
changes compatible with both the 2021 and 2024 edition by first
formatting with the 2024 style, and then again with the currently used
2021 style.

Notable changes are the formatting of derive macro attributes and lines
with overly long strings and adding trailing semicolons after statements
consistently.
2025-05-16 20:19:02 -04:00
John Mumm c73819371c
Revert fix handling of authentication when encountering redirects (#13215)
These changes to redirect handling appear to have caused #13208. This PR
reverts the redirect changes to give us time to investigate.
2025-04-30 10:53:10 +02:00
John Mumm 4ee4a8861e
Implement RFC 7231 compliant relative URI and fragment handling in redirects (#13050)
This PR restores #13041 and integrates two PRs from @zanieb:
* #13038
* #13040

It also adds tests for relative URI and fragment handling.

Closes #13037.

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2025-04-28 09:07:06 +02:00
Zanie Blue 534953290b
Revert "Properly handle authentication for 302 redirect URLs" (#13041)
This reverts commit 17ed789edb / #12920 

There's a regression reported in
https://github.com/astral-sh/uv/issues/13037 and it looks like we're
missing some important parts per #13040
2025-04-22 03:40:42 +00:00
Zanie Blue e2f400adbe
Bump version to 0.6.15 (#13034)
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2025-04-22 00:03:33 +00:00
John Mumm 17ed789edb
Properly handle authentication for 302 redirect URLs (#12920)
uv was failing to authenticate on 302 redirects when credentials were
available. This was because it was relying on `reqwest_middleware`'s
default redirect behavior which bypasses the middleware pipeline when
trying the redirect request (and hence bypasses our authentication
middleware). This PR updates uv to retrigger the middleware pipeline
when handling a 302 redirect, correctly using credentials from the URL,
the keyring, or `.netrc`.

Closes #5595
Closes #11097
2025-04-18 14:56:17 +02:00
Charlie Marsh c4fd34f063
Use `Credentials` abstraction in `uv-publish` (#12682)
## Summary

I noticed that we aren't using these here -- we have a separate username
and password situation.
2025-04-04 19:07:51 -04:00
Charlie Marsh bd9c365b92
Support `--find-links`-style "flat" indexes in `[[tool.uv.index]]` (#12407)
## Summary

This PR extends `[[tool.uv.index]]` to support `--find-links`-style
"flat" indexes, so that users can point to such indexes without using
`--find-links` _and_ get access to the full functionality of
`[[tool.uv.index]]` (e.g., they can now pin packages to
`--find-links`-style indexes).

Note that, at present, `--find-links` indexes actually have some quirky
behavior, in that we combine them into a single entity and then merge
the discovered distributions into each Simple API-style index. The
motivation here, IIRC, was to match pip's behavior quite closely. I'm
interested in _removing_ that behavior, but it'd be breaking (and may
also be inconvenient for some use-cases). So, the behavior for indexes
passed in via `--find-links` remains completely unchanged. However,
`[[tool.uv.index]]` entries with `format = "flat"` are now treated
identically to those defined with `format = "simple"` (the default), in
that we stop after we find the first-matching index, etc.

Closes https://github.com/astral-sh/uv/issues/11634.
2025-03-25 21:14:44 -04:00
Charlie Marsh 1865e0a6ee
Pass around index with associated metadata (#12406)
## Summary

This PR modifies the requirement source entities to store a (new)
container struct that wraps `IndexUrl`. This will allow us to store
user-defined metadata alongside `IndexUrl`, and propagate that metadata
throughout resolution.

Specifically, I need to store the "kind" of the index (Simple API vs.
`--find-links`), but I also ran into this problem when I tried to add
support for overriding `Cache-Control` headers on a per-index basis: at
present, we have no way to passing around metadata alongside an
`IndexUrl`.
2025-03-24 10:15:49 -04:00
konsti b4eabf9a61
Render token claims on publish permission error (#12135)
Match the official trusted publishing GitHub Action from
db8f07d387/oidc-exchange.py (L165-L184)

See
https://github.com/konstin/uv/actions/runs/13812003071/job/38635620817?pr=3
for an example of how this renders
2025-03-13 11:19:08 +01:00
Jean-Michel Rouet d660882b8d
publish with sized stream to comply with WSGI pypi server constraints. (#12111)
<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

This PR is meant to fix issue #11862 

It allows to send sized bodies during `publish`

<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan

the PR was tested on the MRE from #11862 

<!-- How was it tested? -->
2025-03-11 15:54:30 +01:00
konsti aa629c4a54
Re-add 3 retries in `uv publish` (#12041)
In the publish client, we have to set the client retries to 0 as the
retry middleware is incompatible with upload bodies. This however also
sets `client.retry_policy()` to a zero-retry policy, so we need to
construct our own policy.

Fixes #12027

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2025-03-10 12:38:08 +01:00
Charlie Marsh 8fb616b61e
Use 'Upload' instead of 'Download' in publish reporter (#12029)
## Summary

Closes https://github.com/astral-sh/uv/issues/12026.
2025-03-07 10:48:34 -05:00
Charlie Marsh 4611690745
Use `SmallString` on `Hashes` (#11756)
## Summary

We should use this consistently over `Box<str>`.
2025-02-24 10:32:00 -10:00
Charlie Marsh 7b43baf251
Use Astral-maintained `tokio-tar` fork (#11174)
## Summary

I shipped one security fix here along with several significant
performance improvements for large TAR files:

- https://github.com/astral-sh/tokio-tar/pull/2
- https://github.com/astral-sh/tokio-tar/pull/4
- https://github.com/astral-sh/tokio-tar/pull/5

I also PR'd the security fix to `edera-dev`
(https://github.com/edera-dev/tokio-tar/pull/4).
2025-02-03 17:51:35 +00:00
konsti 56684e4c24
Respect concurrency limits in parallel index fetch (#11182)
With the parallel simple index fetching, we would only acquire one
download concurrency token, meaning that we could in the worst case make
times the number of indexes more requests than the user requested limit.
We fix this by passing the semaphore down to the simple API method.
2025-02-03 16:41:17 +01:00
Charlie Marsh c306e46e1d
Remove trailing commas before brackets (#10740) 2025-01-18 19:56:46 +00:00
Charlie Marsh 24a5920739
Reduce `WheelFilename` to 48 bytes (#10583)
## Summary

Based on some advice from @konstin.
2025-01-14 14:49:17 +00:00
Charlie Marsh 5c91217488
Use structured wheel tags everywhere (#10542)
## Summary

This PR extends the thinking in #10525 to platform tags, and then uses
the structured tag enums everywhere, rather than passing around strings.
I think this is a big improvement! It means we're no longer doing ad hoc
tag parsing all over the place.
2025-01-14 01:39:39 +00:00
Charlie Marsh 2f5badddbb
Avoid enforcing URL check on initial publish (#10182)
## Summary

Closes https://github.com/astral-sh/uv/issues/10174.
2024-12-26 23:46:36 +00:00
konsti 8074917449
Upload: All metadata incl. PEP 639 (#9442)
We were previously not uploading all metadata in the formdata of an
upload request in the legacy api. Notably, we were missing the PEP 639
license-files field.

I had to switch to pdm due to https://github.com/pypa/hatch/issues/1828
2024-11-27 00:25:08 +01:00
Charlie Marsh 8ca8de8eaa
Use exponential backoff for publish retries (#9276)
## Summary

Just trying to unify the retry handling, as in
https://github.com/astral-sh/uv/pull/9274 and elsewhere. Right now, the
publish handler doesn't use any backoff and always retries three times
regardless of settings.
2024-11-20 15:02:33 +00:00
Charlie Marsh 821f3de095
Automatically retry body errors when processing response (#9213)
## Summary

The reqwest middleware doesn't retry errors that occur "after" the
request completes -- but in some cases, these do include spurious errors
that we want to retry. See https://github.com/astral-sh/uv/issues/8144
for examples. This PR adds a second retry layer during the response
_handler_, which should help with some of the spurious failures we see
in the linked issue.

Closes https://github.com/astral-sh/uv/issues/8144.
2024-11-19 04:14:58 +00:00
Charlie Marsh d08bfee718
Remove separate test files in favor of same-file `mod tests` (#9199)
## Summary

These were moved as part of a broader refactor to create a single
integration test module. That "single integration test module" did
indeed have a big impact on compile times, which is great! But we aren't
seeing any benefit from moving these tests into their own files (despite
the claim in [this blog
post](https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html),
I see the same compilation pattern regardless of where the tests are
located). Plus, we don't have many of these, and same-file tests is such
a strong Rust convention.
2024-11-18 20:11:46 +00:00
konsti 926660aea0
Publish: Ignore non-matching files (#8986)
Fixes #8944
2024-11-13 12:58:28 +01:00
konsti f5a7d70642
Check error case for skip existing (#8631) 2024-10-31 15:37:30 +00:00
konsti 082259493e
Skip existing, second iteration: Check the index before uploading (#8531)
Co-authored-by: Zanie Blue <contact@zanie.dev>
2024-10-31 16:23:12 +01:00
konsti 0044000ed3
Better trusted publishing error story (#8633) 2024-10-28 21:13:43 +01:00
konsti 635223ef00
Hint about missing trusted publishing permission (#8632) 2024-10-28 11:26:46 +00:00
konsti 3eda248ef5
Always attach URL to network errors (#8444) 2024-10-25 09:10:18 +00:00
konsti e7ae0f50d2
Respect allow insecure host in publish (#8440) 2024-10-22 13:36:18 +02:00
konsti 494a1d782d
Publish: Workaround using raw filename (#8204) 2024-10-15 14:22:52 +02:00