Skip to content

Commit ac78909

Browse files
committed
Add warnings for dubious filenames
1 parent ecccfa0 commit ac78909

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

crates/uv-publish/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,19 @@ pub fn files_for_publishing(
253253
};
254254
let Some(dist_filename) = DistFilename::try_from_normalized_filename(&filename) else {
255255
debug!("Not a distribution filename: `{filename}`");
256+
if filename.ends_with(".whl")
257+
|| filename.ends_with(".zip")
258+
// Example: `tar.gz`
259+
|| filename
260+
.split_once(".tar.")
261+
.is_some_and(|(_, ext)| ext.chars().all(|c| c.is_alphanumeric()))
262+
{
263+
warn_user!(
264+
"Skipping file that looks like a distribution, \
265+
but is not a valid distribution filename: `{}`",
266+
dist.user_display()
267+
);
268+
}
256269
continue;
257270
};
258271
files.push((dist, filename, dist_filename));

crates/uv/tests/it/publish.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::common::{uv_snapshot, TestContext};
2+
use assert_fs::fixture::{FileTouch, PathChild};
23
use uv_static::EnvVars;
34

45
#[test]
@@ -162,3 +163,37 @@ fn skip_existing_redirect() {
162163
"###
163164
);
164165
}
166+
167+
#[test]
168+
fn dubious_filenames() {
169+
let context = TestContext::new("3.12");
170+
171+
context.temp_dir.child("not-a-wheel.whl").touch().unwrap();
172+
context.temp_dir.child("data.tar.gz").touch().unwrap();
173+
context
174+
.temp_dir
175+
.child("not-sdist-1-2-3-asdf.zip")
176+
.touch()
177+
.unwrap();
178+
179+
uv_snapshot!(context.filters(), context.publish()
180+
.arg("-u")
181+
.arg("dummy")
182+
.arg("-p")
183+
.arg("dummy")
184+
.arg("--publish-url")
185+
.arg("https://test.pypi.org/legacy/")
186+
.arg(context.temp_dir.join("*")), @r###"
187+
success: false
188+
exit_code: 2
189+
----- stdout -----
190+
191+
----- stderr -----
192+
warning: `uv publish` is experimental and may change without warning
193+
warning: Skipping file that looks like a distribution, but is not a valid distribution filename: `[TEMP_DIR]/data.tar.gz`
194+
warning: Skipping file that looks like a distribution, but is not a valid distribution filename: `[TEMP_DIR]/not-a-wheel.whl`
195+
warning: Skipping file that looks like a distribution, but is not a valid distribution filename: `[TEMP_DIR]/not-sdist-1-2-3-asdf.zip`
196+
error: No files found to publish
197+
"###
198+
);
199+
}

0 commit comments

Comments
 (0)