From 508ee14f6ef188288ef652dfee3ea857bc880436 Mon Sep 17 00:00:00 2001 From: konstin Date: Tue, 24 Sep 2024 11:57:31 +0200 Subject: [PATCH] Review --- Cargo.lock | 1 + crates/uv-cli/src/lib.rs | 2 ++ crates/uv-configuration/src/preview.rs | 1 - crates/uv-publish/Cargo.toml | 1 + crates/uv-publish/src/lib.rs | 32 +++++++++++++------------- crates/uv/src/commands/publish.rs | 4 ++-- crates/uv/src/settings.rs | 2 +- crates/uv/tests/publish.rs | 8 +++---- docs/reference/cli.md | 12 +++++++--- 9 files changed, 36 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 413bd6a65abf2..1f01dfffb8848 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5114,6 +5114,7 @@ dependencies = [ "python-pkginfo", "reqwest", "reqwest-middleware", + "rustc-hash", "serde", "serde_json", "sha2", diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index c673cbeddbec6..7b63a3b34d23d 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -4297,6 +4297,8 @@ pub struct DisplayTreeArgs { #[derive(Args, Debug)] pub struct PublishArgs { /// Paths to the files to upload. Accepts glob expressions. + /// + /// Defaults to the `dist` directory. #[arg(default_value = "dist/*")] pub files: Vec, diff --git a/crates/uv-configuration/src/preview.rs b/crates/uv-configuration/src/preview.rs index 39fffa649265a..38572589b667c 100644 --- a/crates/uv-configuration/src/preview.rs +++ b/crates/uv-configuration/src/preview.rs @@ -1,7 +1,6 @@ use std::fmt::{Display, Formatter}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] -#[cfg_attr(feature = "clap", derive(clap::ValueEnum))] pub enum PreviewMode { #[default] Disabled, diff --git a/crates/uv-publish/Cargo.toml b/crates/uv-publish/Cargo.toml index 4f762d65ef1c4..8f27b030ff191 100644 --- a/crates/uv-publish/Cargo.toml +++ b/crates/uv-publish/Cargo.toml @@ -25,6 +25,7 @@ krata-tokio-tar = { workspace = true } python-pkginfo = { workspace = true } reqwest = { workspace = true } reqwest-middleware = { workspace = true } +rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } sha2 = { workspace = true } diff --git a/crates/uv-publish/src/lib.rs b/crates/uv-publish/src/lib.rs index 02b9113dd9ccd..00f18ba408ab8 100644 --- a/crates/uv-publish/src/lib.rs +++ b/crates/uv-publish/src/lib.rs @@ -10,9 +10,9 @@ use reqwest::header::AUTHORIZATION; use reqwest::multipart::Part; use reqwest::{Body, Response, StatusCode}; use reqwest_middleware::RequestBuilder; +use rustc_hash::FxHashSet; use serde::Deserialize; use sha2::{Digest, Sha256}; -use std::collections::HashSet; use std::io::BufReader; use std::path::{Path, PathBuf}; use std::{fmt, io}; @@ -39,7 +39,7 @@ pub enum PublishError { InvalidFilename(PathBuf), #[error("Failed to publish: `{}`", _0.user_display())] PublishPrepare(PathBuf, #[source] PublishPrepareError), - #[error("Failed to publish `{}` to `{}`", _0.user_display(), _1)] + #[error("Failed to publish `{}` to {}", _0.user_display(), _1)] PublishSend(PathBuf, Url, #[source] PublishSendError), } @@ -71,11 +71,11 @@ pub enum PublishSendError { StatusNoBody(StatusCode, #[source] reqwest::Error), #[error("Upload failed with status code {0}: {1}")] Status(StatusCode, String), - /// The registry returned a "403 Forbidden" - #[error("Incorrect credentials (status code {0}): {1}")] - IncorrectCredentials(StatusCode, String), - /// See inline comment - #[error("The request was redirected, but publishing doesn't support redirect, please use the canonical URL: `{0}`")] + /// The registry returned a "403 Forbidden". + #[error("Permission denied (status code {0}): {1}")] + PermissionDenied(StatusCode, String), + /// See inline comment. + #[error("The request was redirected, but redirects are not allowed when publishing, please use the canonical URL: `{0}`")] RedirectError(Url), } @@ -177,23 +177,23 @@ impl PublishSendError { pub fn files_for_publishing( paths: Vec, ) -> Result, PublishError> { - let mut seen = HashSet::new(); + let mut seen = FxHashSet::default(); let mut files = Vec::new(); for path in paths { - for entry in glob(&path).map_err(|err| PublishError::Pattern(path, err))? { - let entry = entry?; - if !seen.insert(entry.clone()) { + for dist in glob(&path).map_err(|err| PublishError::Pattern(path, err))? { + let dist = dist?; + if !dist.is_file() { continue; } - if !entry.is_file() { + if !seen.insert(dist.clone()) { continue; } - let Some(filename) = entry.file_name().and_then(|filename| filename.to_str()) else { + let Some(filename) = dist.file_name().and_then(|filename| filename.to_str()) else { continue; }; let filename = DistFilename::try_from_normalized_filename(filename) - .ok_or_else(|| PublishError::InvalidFilename(entry.clone()))?; - files.push((entry, filename)); + .ok_or_else(|| PublishError::InvalidFilename(dist.clone()))?; + files.push((dist, filename)); } } // TODO(konsti): Should we sort those files, e.g. wheels before sdists because they are more @@ -495,7 +495,7 @@ async fn handle_response(registry: &Url, response: Response) -> ResultArguments -
FILES

The paths to the files to uploads, as glob expressions

+
FILES

Paths to the files to upload. Accepts glob expressions.

+ +

Defaults to the dist directory.

@@ -6615,7 +6617,11 @@ uv publish [OPTIONS] [FILES]...
--password, -p password

The password for the upload

May also be set with the UV_PUBLISH_PASSWORD environment variable.

-
--publish-url publish-url

The URL to the upload endpoint. Note: This is usually not the same as the index URL.

+
--publish-url publish-url

The URL of the upload endpoint.

+ +

Note that this typically differs from the index URL.

+ +

Defaults to PyPI’s publish URL (<https://upload.pypi.org/legacy/>).

The default value is publish URL for PyPI (<https://upload.pypi.org/legacy/>).

@@ -6640,7 +6646,7 @@ uv publish [OPTIONS] [FILES]...
--token, -t token

The token for the upload.

-

Using a token is equivalent to using __token__ as username and using the token as password.

+

Using a token is equivalent to passing __token__ as --username and the token as --password. password.

May also be set with the UV_PUBLISH_TOKEN environment variable.

--username, -u username

The username for the upload