Skip to content

Commit dfbb3ae

Browse files
committed
Add test for uv pip compile --python-platform
1 parent be1c4e4 commit dfbb3ae

2 files changed

Lines changed: 148 additions & 1 deletion

File tree

crates/uv-distribution/src/source/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2575,7 +2575,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
25752575
.await
25762576
.map_err(Error::CacheWrite)?;
25772577

2578-
debug!("Finished building: {source}");
2578+
debug!("Built `{source}` into `{disk_filename}`");
25792579
Ok((disk_filename, filename, metadata))
25802580
}
25812581

crates/uv/tests/it/pip_compile.rs

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17921,3 +17921,150 @@ fn post_release_less_than() -> Result<()> {
1792117921

1792217922
Ok(())
1792317923
}
17924+
17925+
/// When using `uv pip compile --python-platform`, it should not matter what platform the built
17926+
/// wheel is for. We want to ensure that uv accepts both wheels for the host platform and wheels for
17927+
/// the target platform in `uv pip compile`. This is unlike `uv pip install --python-platform`,
17928+
/// where a wheel for the target platform is required.
17929+
///
17930+
/// The main test (first snapshot) builds a Windows wheel, and targets macOS. If we run this test on
17931+
/// Linux, the wheel tag is neither host nor target, but we don't have a reason to reject the
17932+
/// Windows tag either.
17933+
#[test]
17934+
fn compile_with_python_platform_and_built_wheel_for_different_platform() -> Result<()> {
17935+
let context = TestContext::new("3.12");
17936+
let requirements_in = context.temp_dir.child("requirements.in");
17937+
requirements_in.write_str("./project")?;
17938+
17939+
let project = context.temp_dir.child("project");
17940+
// This pyproject.toml uses dynamic versioning to prevent uv from reading static metadata.
17941+
project.child("pyproject.toml").write_str(indoc! {r#"
17942+
[project]
17943+
name = "project"
17944+
requires-python = ">=3.12"
17945+
dependencies = [
17946+
"sniffio; sys_platform == 'linux'",
17947+
"tqdm; sys_platform == 'darwin'"
17948+
]
17949+
dynamic = ["version"]
17950+
17951+
[build-system]
17952+
requires = ["hatchling"]
17953+
backend-path = ["."]
17954+
build-backend = "build"
17955+
17956+
[tool.hatch.version]
17957+
path = "src/project/__init__.py"
17958+
"#})?;
17959+
// Rename the built wheel to a Windows wheel
17960+
project.child("build.py").write_str(indoc! {r#"
17961+
import os
17962+
17963+
import hatchling.build
17964+
17965+
__all__ = ["build_sdist", "build_wheel"]
17966+
17967+
17968+
def build_sdist(
17969+
sdist_directory: str, config_settings: "Mapping[Any, Any] | None" = None
17970+
) -> str:
17971+
hatchling.build.build_sdist(sdist_directory, config_settings)
17972+
17973+
17974+
def build_wheel(
17975+
wheel_directory: str,
17976+
config_settings: "Mapping[Any, Any] | None" = None,
17977+
metadata_directory: "str | None" = None,
17978+
) -> str:
17979+
name = hatchling.build.build_wheel(
17980+
wheel_directory, config_settings, metadata_directory
17981+
)
17982+
# Don't do this at home, ask your build backend instead so it also changes the
17983+
# `WHEEL` file.
17984+
new_name = "project-0.1.0-cp312-abi3-win_amd64.whl"
17985+
os.rename(
17986+
os.path.join(wheel_directory, name), os.path.join(wheel_directory, new_name)
17987+
)
17988+
return new_name
17989+
"#})?;
17990+
project
17991+
.child("src/project/__init__.py")
17992+
.write_str(r#"__version__ = "0.1.0"\n"#)?;
17993+
17994+
uv_snapshot!(context
17995+
.pip_compile()
17996+
.arg("requirements.in")
17997+
.arg("--python-platform")
17998+
.arg("macos"), @r"
17999+
success: true
18000+
exit_code: 0
18001+
----- stdout -----
18002+
# This file was autogenerated by uv via the following command:
18003+
# uv pip compile --cache-dir [CACHE_DIR] requirements.in --python-platform macos
18004+
./project
18005+
# via -r requirements.in
18006+
tqdm==4.66.2
18007+
# via project
18008+
18009+
----- stderr -----
18010+
Resolved 2 packages in [TIME]
18011+
");
18012+
18013+
uv_snapshot!(context
18014+
.pip_compile()
18015+
.arg("requirements.in")
18016+
.arg("--python-platform")
18017+
.arg("linux"), @r"
18018+
success: true
18019+
exit_code: 0
18020+
----- stdout -----
18021+
# This file was autogenerated by uv via the following command:
18022+
# uv pip compile --cache-dir [CACHE_DIR] requirements.in --python-platform linux
18023+
./project
18024+
# via -r requirements.in
18025+
sniffio==1.3.1
18026+
# via project
18027+
18028+
----- stderr -----
18029+
Resolved 2 packages in [TIME]
18030+
");
18031+
18032+
uv_snapshot!(context
18033+
.pip_compile()
18034+
.arg("requirements.in")
18035+
.arg("--python-platform")
18036+
.arg("windows"), @r"
18037+
success: true
18038+
exit_code: 0
18039+
----- stdout -----
18040+
# This file was autogenerated by uv via the following command:
18041+
# uv pip compile --cache-dir [CACHE_DIR] requirements.in --python-platform windows
18042+
./project
18043+
# via -r requirements.in
18044+
18045+
----- stderr -----
18046+
Resolved 1 package in [TIME]
18047+
");
18048+
18049+
uv_snapshot!(context
18050+
.pip_compile()
18051+
.arg("requirements.in")
18052+
.arg("--universal"), @r"
18053+
success: true
18054+
exit_code: 0
18055+
----- stdout -----
18056+
# This file was autogenerated by uv via the following command:
18057+
# uv pip compile --cache-dir [CACHE_DIR] requirements.in --universal
18058+
./project
18059+
# via -r requirements.in
18060+
sniffio==1.3.1 ; sys_platform == 'linux'
18061+
# via project
18062+
tqdm==4.66.2 ; sys_platform == 'darwin'
18063+
# via project
18064+
18065+
----- stderr -----
18066+
Resolved 3 packages in [TIME]
18067+
");
18068+
18069+
Ok(())
18070+
}

0 commit comments

Comments
 (0)