Skip to content

Commit

Permalink
Avoid enforcing URL check on initial publish (#10182)
Browse files Browse the repository at this point in the history
## Summary

Closes #10174.
  • Loading branch information
charliermarsh authored Dec 26, 2024
1 parent b52d489 commit 2f5badd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
20 changes: 17 additions & 3 deletions crates/uv-publish/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{env, fmt, io};
use thiserror::Error;
use tokio::io::{AsyncReadExt, BufReader};
use tokio_util::io::ReaderStream;
use tracing::{debug, enabled, trace, Level};
use tracing::{debug, enabled, trace, warn, Level};
use url::Url;
use uv_client::{BaseClient, OwnedArchive, RegistryClientBuilder, UvRetryableStrategy};
use uv_configuration::{KeyringProviderType, TrustedPublishing};
Expand Down Expand Up @@ -469,10 +469,24 @@ pub async fn check_url(
.wrap_existing(client);

debug!("Checking for {filename} in the registry");
let response = registry_client
let response = match registry_client
.simple(filename.name(), Some(index_url), index_capabilities)
.await
.map_err(PublishError::CheckUrlIndex)?;
{
Ok(response) => response,
Err(err) => {
return match err.into_kind() {
uv_client::ErrorKind::PackageNotFound(_) => {
// The package doesn't exist, so we can't have uploaded it.
warn!(
"Package not found in the registry; skipping upload check for {filename}"
);
Ok(false)
}
kind => Err(PublishError::CheckUrlIndex(kind.into())),
};
}
};
let [(_, simple_metadata)] = response.as_slice() else {
unreachable!("We queried a single index, we must get a single response");
};
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub(crate) async fn publish(
}
} else if check_url.is_none() {
warn_user_once!(
"Using `--keyring-provider` with a password or token and no check url has no effect"
"Using `--keyring-provider` with a password or token and no check URL has no effect"
);
} else {
// We may be using the keyring for the simple index.
Expand Down
14 changes: 9 additions & 5 deletions crates/uv/tests/it/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ fn check_keyring_behaviours() {
----- stderr -----
warning: `uv publish` is experimental and may change without warning
Publishing 1 file to https://test.pypi.org/legacy/?ok
error: Failed to query check URL
Caused by: Package `ok` was not found in the registry
Uploading ok-1.0.0-py3-none-any.whl ([SIZE])
error: Failed to publish `../../scripts/links/ok-1.0.0-py3-none-any.whl` to https://test.pypi.org/legacy/?ok
Caused by: Upload failed with status code 403 Forbidden. Server says: 403 Username/Password authentication is no longer supported. Migrate to API Tokens or Trusted Publishers instead. See https://test.pypi.org/help/#apitoken and https://test.pypi.org/help/#trusted-publishers
"###
);

Expand All @@ -265,7 +266,7 @@ fn check_keyring_behaviours() {
----- stderr -----
warning: `uv publish` is experimental and may change without warning
Publishing 1 file to https://test.pypi.org/legacy/?ok
warning: Using `--keyring-provider` with a password or token and no check url has no effect
warning: Using `--keyring-provider` with a password or token and no check URL has no effect
Uploading ok-1.0.0-py3-none-any.whl ([SIZE])
error: Failed to publish `../../scripts/links/ok-1.0.0-py3-none-any.whl` to https://test.pypi.org/legacy/?ok
Caused by: Upload failed with status code 403 Forbidden. Server says: 403 Username/Password authentication is no longer supported. Migrate to API Tokens or Trusted Publishers instead. See https://test.pypi.org/help/#apitoken and https://test.pypi.org/help/#trusted-publishers
Expand Down Expand Up @@ -295,8 +296,11 @@ fn check_keyring_behaviours() {
Request for dummy@https://test.pypi.org/legacy/?ok
Request for [email protected]
warning: Keyring has no password for URL `https://test.pypi.org/legacy/?ok` and username `dummy`
error: Failed to query check URL
Caused by: Package `ok` was not found in the registry
Uploading ok-1.0.0-py3-none-any.whl ([SIZE])
Request for dummy@https://test.pypi.org/legacy/?ok
Request for [email protected]
error: Failed to publish `../../scripts/links/ok-1.0.0-py3-none-any.whl` to https://test.pypi.org/legacy/?ok
Caused by: Upload failed with status code 403 Forbidden. Server says: 403 Username/Password authentication is no longer supported. Migrate to API Tokens or Trusted Publishers instead. See https://test.pypi.org/help/#apitoken and https://test.pypi.org/help/#trusted-publishers
"###
);

Expand Down

0 comments on commit 2f5badd

Please sign in to comment.