Skip to content

Commit bce2ea4

Browse files
authored
Escape requires version for built_by_uv test (#14706)
This keeps the hash stable across uv releases. Fixes #14695
1 parent e724ddc commit bce2ea4

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/uv-build-backend/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ schemars = ["dep:schemars", "uv-pypi-types/schemars"]
5757
[dev-dependencies]
5858
indoc = { workspace = true }
5959
insta = { version = "1.40.0", features = ["filters"] }
60+
regex = { workspace = true }
6061
tempfile = { workspace = true }

crates/uv-build-backend/src/lib.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,16 @@ mod tests {
355355
use indoc::indoc;
356356
use insta::assert_snapshot;
357357
use itertools::Itertools;
358+
use regex::Regex;
358359
use sha2::Digest;
359360
use std::io::{BufReader, Read};
360361
use std::iter;
361362
use tempfile::TempDir;
362363
use uv_distribution_filename::{SourceDistFilename, WheelFilename};
363364
use uv_fs::{copy_dir_all, relative_to};
364365

366+
const MOCK_UV_VERSION: &str = "1.0.0+test";
367+
365368
fn format_err(err: &Error) -> String {
366369
let context = iter::successors(std::error::Error::source(&err), |&err| err.source())
367370
.map(|err| format!(" Caused by: {err}"))
@@ -388,19 +391,19 @@ mod tests {
388391
fn build(source_root: &Path, dist: &Path) -> Result<BuildResults, Error> {
389392
// Build a direct wheel, capture all its properties to compare it with the indirect wheel
390393
// latest and remove it since it has the same filename as the indirect wheel.
391-
let (_name, direct_wheel_list_files) = list_wheel(source_root, "1.0.0+test")?;
392-
let direct_wheel_filename = build_wheel(source_root, dist, None, "1.0.0+test")?;
394+
let (_name, direct_wheel_list_files) = list_wheel(source_root, MOCK_UV_VERSION)?;
395+
let direct_wheel_filename = build_wheel(source_root, dist, None, MOCK_UV_VERSION)?;
393396
let direct_wheel_path = dist.join(direct_wheel_filename.to_string());
394397
let direct_wheel_contents = wheel_contents(&direct_wheel_path);
395398
let direct_wheel_hash = sha2::Sha256::digest(fs_err::read(&direct_wheel_path)?);
396399
fs_err::remove_file(&direct_wheel_path)?;
397400

398401
// Build a source distribution.
399-
let (_name, source_dist_list_files) = list_source_dist(source_root, "1.0.0+test")?;
402+
let (_name, source_dist_list_files) = list_source_dist(source_root, MOCK_UV_VERSION)?;
400403
// TODO(konsti): This should run in the unpacked source dist tempdir, but we need to
401404
// normalize the path.
402-
let (_name, wheel_list_files) = list_wheel(source_root, "1.0.0+test")?;
403-
let source_dist_filename = build_source_dist(source_root, dist, "1.0.0+test")?;
405+
let (_name, wheel_list_files) = list_wheel(source_root, MOCK_UV_VERSION)?;
406+
let source_dist_filename = build_source_dist(source_root, dist, MOCK_UV_VERSION)?;
404407
let source_dist_path = dist.join(source_dist_filename.to_string());
405408
let source_dist_contents = sdist_contents(&source_dist_path);
406409

@@ -414,7 +417,7 @@ mod tests {
414417
source_dist_filename.name.as_dist_info_name(),
415418
source_dist_filename.version
416419
));
417-
let wheel_filename = build_wheel(&sdist_top_level_directory, dist, None, "1.0.0+test")?;
420+
let wheel_filename = build_wheel(&sdist_top_level_directory, dist, None, MOCK_UV_VERSION)?;
418421
let wheel_contents = wheel_contents(&dist.join(wheel_filename.to_string()));
419422

420423
// Check that direct and indirect wheels are identical.
@@ -515,14 +518,14 @@ mod tests {
515518
] {
516519
copy_dir_all(built_by_uv.join(dir), src.path().join(dir)).unwrap();
517520
}
518-
for dir in [
521+
for filename in [
519522
"pyproject.toml",
520523
"README.md",
521524
"uv.lock",
522525
"LICENSE-APACHE",
523526
"LICENSE-MIT",
524527
] {
525-
fs_err::copy(built_by_uv.join(dir), src.path().join(dir)).unwrap();
528+
fs_err::copy(built_by_uv.join(filename), src.path().join(filename)).unwrap();
526529
}
527530

528531
// Clear executable bit on Unix to build the same archive between Unix and Windows.
@@ -539,6 +542,14 @@ mod tests {
539542
fs_err::set_permissions(&path, perms).unwrap();
540543
}
541544

545+
// Redact the uv_build version to keep the hash stable across releases
546+
let pyproject_toml = fs_err::read_to_string(src.path().join("pyproject.toml")).unwrap();
547+
let current_requires =
548+
Regex::new(r#"requires = \["uv_build>=[0-9.]+,<[0-9.]+"\]"#).unwrap();
549+
let mocked_requires = r#"requires = ["uv_build>=1,<2"]"#;
550+
let pyproject_toml = current_requires.replace(pyproject_toml.as_str(), mocked_requires);
551+
fs_err::write(src.path().join("pyproject.toml"), pyproject_toml.as_bytes()).unwrap();
552+
542553
// Add some files to be excluded
543554
let module_root = src.path().join("src").join("built_by_uv");
544555
fs_err::create_dir_all(module_root.join("__pycache__")).unwrap();
@@ -557,7 +568,7 @@ mod tests {
557568
// Check that the source dist is reproducible across platforms.
558569
assert_snapshot!(
559570
format!("{:x}", sha2::Sha256::digest(fs_err::read(&source_dist_path).unwrap())),
560-
@"9a7f7181c5e69ac14e411a2500fed153a1e6ea41cd5da6f24f226c4cddacf6b7"
571+
@"871d1f859140721b67cbeaca074e7a2740c88c38028d0509eba87d1285f1da9e"
561572
);
562573
// Check both the files we report and the actual files
563574
assert_snapshot!(format_file_list(build.source_dist_list_files, src.path()), @r"

0 commit comments

Comments
 (0)