Skip to content

Commit 802329d

Browse files
committed
Avoid enforcing URL check on initial publish
1 parent 1807088 commit 802329d

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

crates/uv-publish/src/lib.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::{env, fmt, io};
2121
use thiserror::Error;
2222
use tokio::io::{AsyncReadExt, BufReader};
2323
use tokio_util::io::ReaderStream;
24-
use tracing::{debug, enabled, trace, Level};
24+
use tracing::{debug, enabled, trace, warn, Level};
2525
use url::Url;
2626
use uv_client::{BaseClient, OwnedArchive, RegistryClientBuilder, UvRetryableStrategy};
2727
use uv_configuration::{KeyringProviderType, TrustedPublishing};
@@ -469,10 +469,24 @@ pub async fn check_url(
469469
.wrap_existing(client);
470470

471471
debug!("Checking for {filename} in the registry");
472-
let response = registry_client
472+
let response = match registry_client
473473
.simple(filename.name(), Some(index_url), index_capabilities)
474474
.await
475-
.map_err(PublishError::CheckUrlIndex)?;
475+
{
476+
Ok(response) => response,
477+
Err(err) => {
478+
return match err.into_kind() {
479+
uv_client::ErrorKind::PackageNotFound(_) => {
480+
// The package doesn't exist, so we can't have uploaded it.
481+
warn!(
482+
"Package not found in the registry; skipping upload check for {filename}"
483+
);
484+
Ok(false)
485+
}
486+
kind => Err(PublishError::CheckUrlIndex(kind.into())),
487+
};
488+
}
489+
};
476490
let [(_, simple_metadata)] = response.as_slice() else {
477491
unreachable!("We queried a single index, we must get a single response");
478492
};

crates/uv/src/commands/publish.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub(crate) async fn publish(
173173
}
174174
} else if check_url.is_none() {
175175
warn_user_once!(
176-
"Using `--keyring-provider` with a password or token and no check url has no effect"
176+
"Using `--keyring-provider` with a password or token and no check URL has no effect"
177177
);
178178
} else {
179179
// We may be using the keyring for the simple index.

crates/uv/tests/it/publish.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ fn check_keyring_behaviours() {
241241
----- stderr -----
242242
warning: `uv publish` is experimental and may change without warning
243243
Publishing 1 file to https://test.pypi.org/legacy/?ok
244-
error: Failed to query check URL
245-
Caused by: Package `ok` was not found in the registry
244+
Uploading ok-1.0.0-py3-none-any.whl ([SIZE])
245+
error: Failed to publish `../../scripts/links/ok-1.0.0-py3-none-any.whl` to https://test.pypi.org/legacy/?ok
246+
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
246247
"###
247248
);
248249

@@ -265,7 +266,7 @@ fn check_keyring_behaviours() {
265266
----- stderr -----
266267
warning: `uv publish` is experimental and may change without warning
267268
Publishing 1 file to https://test.pypi.org/legacy/?ok
268-
warning: Using `--keyring-provider` with a password or token and no check url has no effect
269+
warning: Using `--keyring-provider` with a password or token and no check URL has no effect
269270
Uploading ok-1.0.0-py3-none-any.whl ([SIZE])
270271
error: Failed to publish `../../scripts/links/ok-1.0.0-py3-none-any.whl` to https://test.pypi.org/legacy/?ok
271272
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
@@ -295,8 +296,11 @@ fn check_keyring_behaviours() {
295296
Request for dummy@https://test.pypi.org/legacy/?ok
296297
Request for [email protected]
297298
warning: Keyring has no password for URL `https://test.pypi.org/legacy/?ok` and username `dummy`
298-
error: Failed to query check URL
299-
Caused by: Package `ok` was not found in the registry
299+
Uploading ok-1.0.0-py3-none-any.whl ([SIZE])
300+
Request for dummy@https://test.pypi.org/legacy/?ok
301+
Request for [email protected]
302+
error: Failed to publish `../../scripts/links/ok-1.0.0-py3-none-any.whl` to https://test.pypi.org/legacy/?ok
303+
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
300304
"###
301305
);
302306

0 commit comments

Comments
 (0)