mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 10:58:28 +00:00
Mock uv version in build backend tests (#8205)
This commit is contained in:
parent
dda91d443c
commit
7c5d94030d
8 changed files with 67 additions and 53 deletions
|
@ -20,7 +20,6 @@ uv-pep440 = { workspace = true }
|
|||
uv-pep508 = { workspace = true }
|
||||
uv-pubgrub = { workspace = true }
|
||||
uv-pypi-types = { workspace = true }
|
||||
uv-version = { workspace = true }
|
||||
uv-warnings = { workspace = true }
|
||||
|
||||
csv = { workspace = true}
|
||||
|
@ -41,5 +40,5 @@ workspace = true
|
|||
|
||||
[dev-dependencies]
|
||||
indoc = { version = "2.0.5" }
|
||||
insta = { version = "1.40.0", features = ["filters"] }
|
||||
insta = { version = "1.40.0" }
|
||||
tempfile = { version = "3.12.0" }
|
||||
|
|
|
@ -280,10 +280,11 @@ pub fn build(
|
|||
source_tree: &Path,
|
||||
wheel_dir: &Path,
|
||||
metadata_directory: Option<&Path>,
|
||||
uv_version: &str,
|
||||
) -> Result<WheelFilename, Error> {
|
||||
let contents = fs_err::read_to_string(source_tree.join("pyproject.toml"))?;
|
||||
let pyproject_toml = PyProjectToml::parse(&contents)?;
|
||||
pyproject_toml.check_build_system();
|
||||
pyproject_toml.check_build_system("1.0.0+test");
|
||||
|
||||
check_metadata_directory(source_tree, metadata_directory, &pyproject_toml)?;
|
||||
|
||||
|
@ -329,18 +330,27 @@ pub fn build(
|
|||
}
|
||||
|
||||
debug!("Adding metadata files to {}", wheel_path.user_display());
|
||||
let dist_info_dir =
|
||||
write_dist_info(&mut wheel_writer, &pyproject_toml, &filename, source_tree)?;
|
||||
let dist_info_dir = write_dist_info(
|
||||
&mut wheel_writer,
|
||||
&pyproject_toml,
|
||||
&filename,
|
||||
source_tree,
|
||||
uv_version,
|
||||
)?;
|
||||
wheel_writer.close(&dist_info_dir)?;
|
||||
|
||||
Ok(filename)
|
||||
}
|
||||
|
||||
/// Write the dist-info directory to the output directory without building the wheel.
|
||||
pub fn metadata(source_tree: &Path, metadata_directory: &Path) -> Result<String, Error> {
|
||||
pub fn metadata(
|
||||
source_tree: &Path,
|
||||
metadata_directory: &Path,
|
||||
uv_version: &str,
|
||||
) -> Result<String, Error> {
|
||||
let contents = fs_err::read_to_string(source_tree.join("pyproject.toml"))?;
|
||||
let pyproject_toml = PyProjectToml::parse(&contents)?;
|
||||
pyproject_toml.check_build_system();
|
||||
pyproject_toml.check_build_system("1.0.0+test");
|
||||
|
||||
let filename = WheelFilename {
|
||||
name: pyproject_toml.name().clone(),
|
||||
|
@ -356,8 +366,13 @@ pub fn metadata(source_tree: &Path, metadata_directory: &Path) -> Result<String,
|
|||
metadata_directory.user_display()
|
||||
);
|
||||
let mut wheel_writer = FilesystemWrite::new(metadata_directory);
|
||||
let dist_info_dir =
|
||||
write_dist_info(&mut wheel_writer, &pyproject_toml, &filename, source_tree)?;
|
||||
let dist_info_dir = write_dist_info(
|
||||
&mut wheel_writer,
|
||||
&pyproject_toml,
|
||||
&filename,
|
||||
source_tree,
|
||||
uv_version,
|
||||
)?;
|
||||
wheel_writer.close(&dist_info_dir)?;
|
||||
|
||||
Ok(dist_info_dir)
|
||||
|
@ -419,6 +434,7 @@ fn write_dist_info(
|
|||
pyproject_toml: &PyProjectToml,
|
||||
filename: &WheelFilename,
|
||||
root: &Path,
|
||||
uv_version: &str,
|
||||
) -> Result<String, Error> {
|
||||
let dist_info_dir = format!(
|
||||
"{}-{}.dist-info",
|
||||
|
@ -429,7 +445,7 @@ fn write_dist_info(
|
|||
writer.write_directory(&dist_info_dir)?;
|
||||
|
||||
// Add `WHEEL`.
|
||||
let wheel_info = wheel_info(filename);
|
||||
let wheel_info = wheel_info(filename, uv_version);
|
||||
writer.write_bytes(&format!("{dist_info_dir}/WHEEL"), wheel_info.as_bytes())?;
|
||||
|
||||
// Add `entry_points.txt`.
|
||||
|
@ -450,11 +466,11 @@ fn write_dist_info(
|
|||
}
|
||||
|
||||
/// Returns the `WHEEL` file contents.
|
||||
fn wheel_info(filename: &WheelFilename) -> String {
|
||||
fn wheel_info(filename: &WheelFilename, uv_version: &str) -> String {
|
||||
// https://packaging.python.org/en/latest/specifications/binary-distribution-format/#file-contents
|
||||
let mut wheel_info = vec![
|
||||
("Wheel-Version", "1.0".to_string()),
|
||||
("Generator", format!("uv {}", uv_version::version())),
|
||||
("Generator", format!("uv {uv_version}")),
|
||||
("Root-Is-Purelib", "true".to_string()),
|
||||
];
|
||||
for python_tag in &filename.python_tag {
|
||||
|
|
|
@ -85,7 +85,7 @@ impl PyProjectToml {
|
|||
/// ```
|
||||
///
|
||||
/// Returns whether all checks passed.
|
||||
pub(crate) fn check_build_system(&self) -> bool {
|
||||
pub(crate) fn check_build_system(&self, uv_version: &str) -> bool {
|
||||
let mut passed = true;
|
||||
if self.build_system.build_backend.as_deref() != Some("uv") {
|
||||
warn_user_once!(
|
||||
|
@ -95,8 +95,8 @@ impl PyProjectToml {
|
|||
passed = false;
|
||||
}
|
||||
|
||||
let uv_version = Version::from_str(uv_version::version())
|
||||
.expect("uv's own version is not PEP 440 compliant");
|
||||
let uv_version =
|
||||
Version::from_str(uv_version).expect("uv's own version is not PEP 440 compliant");
|
||||
let next_minor = uv_version.release().get(1).copied().unwrap_or_default() + 1;
|
||||
let next_breaking = Version::new([0, next_minor]);
|
||||
|
||||
|
@ -131,8 +131,7 @@ impl PyProjectToml {
|
|||
// This is allowed to happen when testing prereleases, but we should still warn.
|
||||
warn_user_once!(
|
||||
r#"`build_system.requires = ["{uv_requirement}"]` does not contain the
|
||||
current uv version {}"#,
|
||||
uv_version::version()
|
||||
current uv version {uv_version}"#,
|
||||
);
|
||||
passed = false;
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ fn valid() {
|
|||
fn build_system_valid() {
|
||||
let contents = extend_project("");
|
||||
let pyproject_toml = PyProjectToml::parse(&contents).unwrap();
|
||||
assert!(pyproject_toml.check_build_system());
|
||||
assert!(pyproject_toml.check_build_system("1.0.0+test"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -166,7 +166,7 @@ fn build_system_no_bound() {
|
|||
build-backend = "uv"
|
||||
"#};
|
||||
let pyproject_toml = PyProjectToml::parse(contents).unwrap();
|
||||
assert!(!pyproject_toml.check_build_system());
|
||||
assert!(!pyproject_toml.check_build_system("1.0.0+test"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -181,7 +181,7 @@ fn build_system_multiple_packages() {
|
|||
build-backend = "uv"
|
||||
"#};
|
||||
let pyproject_toml = PyProjectToml::parse(contents).unwrap();
|
||||
assert!(!pyproject_toml.check_build_system());
|
||||
assert!(!pyproject_toml.check_build_system("1.0.0+test"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -196,7 +196,7 @@ fn build_system_no_requires_uv() {
|
|||
build-backend = "uv"
|
||||
"#};
|
||||
let pyproject_toml = PyProjectToml::parse(contents).unwrap();
|
||||
assert!(!pyproject_toml.check_build_system());
|
||||
assert!(!pyproject_toml.check_build_system("1.0.0+test"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -211,7 +211,7 @@ fn build_system_not_uv() {
|
|||
build-backend = "setuptools"
|
||||
"#};
|
||||
let pyproject_toml = PyProjectToml::parse(contents).unwrap();
|
||||
assert!(!pyproject_toml.check_build_system());
|
||||
assert!(!pyproject_toml.check_build_system("1.0.0+test"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::*;
|
||||
use insta::{assert_snapshot, with_settings};
|
||||
use insta::assert_snapshot;
|
||||
use std::str::FromStr;
|
||||
use tempfile::TempDir;
|
||||
use uv_normalize::PackageName;
|
||||
|
@ -16,17 +16,13 @@ fn test_wheel() {
|
|||
platform_tag: vec!["any".to_string()],
|
||||
};
|
||||
|
||||
with_settings!({
|
||||
filters => [(uv_version::version(), "[VERSION]")],
|
||||
}, {
|
||||
assert_snapshot!(wheel_info(&filename), @r"
|
||||
Wheel-Version: 1.0
|
||||
Generator: uv [VERSION]
|
||||
Root-Is-Purelib: true
|
||||
Tag: py2-none-any
|
||||
Tag: py3-none-any
|
||||
");
|
||||
});
|
||||
assert_snapshot!(wheel_info(&filename, "1.0.0+test"), @r"
|
||||
Wheel-Version: 1.0
|
||||
Generator: uv 1.0.0+test
|
||||
Root-Is-Purelib: true
|
||||
Tag: py2-none-any
|
||||
Tag: py3-none-any
|
||||
");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -50,7 +46,7 @@ fn test_record() {
|
|||
fn test_determinism() {
|
||||
let temp1 = TempDir::new().unwrap();
|
||||
let uv_backend = Path::new("../../scripts/packages/uv_backend");
|
||||
build(uv_backend, temp1.path(), None).unwrap();
|
||||
build(uv_backend, temp1.path(), None, "1.0.0+test").unwrap();
|
||||
|
||||
// Touch the file to check that we don't serialize the last modified date.
|
||||
fs_err::write(
|
||||
|
@ -60,7 +56,7 @@ fn test_determinism() {
|
|||
.unwrap();
|
||||
|
||||
let temp2 = TempDir::new().unwrap();
|
||||
build(uv_backend, temp2.path(), None).unwrap();
|
||||
build(uv_backend, temp2.path(), None, "1.0.0+test").unwrap();
|
||||
|
||||
let wheel_filename = "uv_backend-0.1.0-py3-none-any.whl";
|
||||
assert_eq!(
|
||||
|
@ -74,7 +70,7 @@ fn test_determinism() {
|
|||
fn test_prepare_metadata() {
|
||||
let metadata_dir = TempDir::new().unwrap();
|
||||
let uv_backend = Path::new("../../scripts/packages/uv_backend");
|
||||
metadata(uv_backend, metadata_dir.path()).unwrap();
|
||||
metadata(uv_backend, metadata_dir.path(), "1.0.0+test").unwrap();
|
||||
|
||||
let mut files: Vec<_> = WalkDir::new(metadata_dir.path())
|
||||
.into_iter()
|
||||
|
@ -117,21 +113,16 @@ fn test_prepare_metadata() {
|
|||
.path()
|
||||
.join("uv_backend-0.1.0.dist-info/RECORD");
|
||||
assert_snapshot!(fs_err::read_to_string(record_file).unwrap(), @r###"
|
||||
uv_backend-0.1.0.dist-info/WHEEL,sha256=1889a32410898a395359e85de53e3063be35d9113130eaf23659cb84740c0c6c,79
|
||||
uv_backend-0.1.0.dist-info/WHEEL,sha256=3da1bfa0e8fd1b6cc246aa0b2b44a35815596c600cb485c39a6f8c106c3d5a8d,83
|
||||
uv_backend-0.1.0.dist-info/METADATA,sha256=e4a0d390317d7182f65ea978254c71ed283e0a4242150cf1c99a694b113ff68d,224
|
||||
uv_backend-0.1.0.dist-info/RECORD,,
|
||||
"###);
|
||||
|
||||
let wheel_file = metadata_dir.path().join("uv_backend-0.1.0.dist-info/WHEEL");
|
||||
let filters = vec![(uv_version::version(), "[VERSION]")];
|
||||
with_settings!({
|
||||
filters => filters
|
||||
}, {
|
||||
assert_snapshot!(fs_err::read_to_string(wheel_file).unwrap(), @r###"
|
||||
Wheel-Version: 1.0
|
||||
Generator: uv [VERSION]
|
||||
Root-Is-Purelib: true
|
||||
Tag: py3-none-any
|
||||
"###);
|
||||
});
|
||||
assert_snapshot!(fs_err::read_to_string(wheel_file).unwrap(), @r###"
|
||||
Wheel-Version: 1.0
|
||||
Generator: uv 1.0.0+test
|
||||
Root-Is-Purelib: true
|
||||
Tag: py3-none-any
|
||||
"###);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue