|
2 | 2 |
|
3 | 3 | use std::env::current_dir; |
4 | 4 | use std::fs; |
| 5 | +use std::io::Cursor; |
5 | 6 | use std::path::PathBuf; |
6 | 7 |
|
7 | 8 | use anyhow::{bail, Context, Result}; |
8 | 9 | use assert_fs::prelude::*; |
| 10 | +use flate2::write::GzEncoder; |
| 11 | +use fs_err::File; |
9 | 12 | use indoc::indoc; |
10 | 13 | use url::Url; |
11 | 14 |
|
@@ -13858,3 +13861,70 @@ fn compile_lowest_extra_unpinned_warning() -> Result<()> { |
13858 | 13861 |
|
13859 | 13862 | Ok(()) |
13860 | 13863 | } |
| 13864 | + |
| 13865 | +/// Test that we use the version in the source distribution filename for compiling, even if the |
| 13866 | +/// version is declared as dynamic. |
| 13867 | +/// |
| 13868 | +/// `test_dynamic_version_sdist_wrong_version` checks that this version must be correct. |
| 13869 | +#[test] |
| 13870 | +fn dynamic_version_source_dist() -> Result<()> { |
| 13871 | + let context = TestContext::new("3.12"); |
| 13872 | + |
| 13873 | + // Write a source dist that has a version in its name, a dynamic version in pyproject.toml |
| 13874 | + // and check that we don't build it when compiling. |
| 13875 | + let pyproject_toml = r#" |
| 13876 | + [project] |
| 13877 | + name = "foo" |
| 13878 | + requires-python = ">=3.9" |
| 13879 | + dependencies = [] |
| 13880 | + dynamic = ["version"] |
| 13881 | + "#; |
| 13882 | + |
| 13883 | + let setup_py = "boom()"; |
| 13884 | + |
| 13885 | + let source_dist = context.temp_dir.child("foo-1.2.3.tar.gz"); |
| 13886 | + // Flush the file after we're done. |
| 13887 | + { |
| 13888 | + let file = File::create(source_dist.path())?; |
| 13889 | + let enc = GzEncoder::new(file, flate2::Compression::default()); |
| 13890 | + let mut tar = tar::Builder::new(enc); |
| 13891 | + |
| 13892 | + for (path, contents) in [ |
| 13893 | + ("foo-1.2.3/pyproject.toml", pyproject_toml), |
| 13894 | + ("foo-1.2.3/setup.py", setup_py), |
| 13895 | + ] { |
| 13896 | + let mut header = tar::Header::new_gnu(); |
| 13897 | + header.set_size(contents.len() as u64); |
| 13898 | + header.set_mode(0o644); |
| 13899 | + header.set_cksum(); |
| 13900 | + tar.append_data(&mut header, path, Cursor::new(contents))?; |
| 13901 | + } |
| 13902 | + tar.finish()?; |
| 13903 | + } |
| 13904 | + |
| 13905 | + let requirements_in = context.temp_dir.child("requirements.in"); |
| 13906 | + requirements_in.write_str(indoc::indoc! {r" |
| 13907 | + foo |
| 13908 | + "})?; |
| 13909 | + |
| 13910 | + uv_snapshot!(context.filters(), context |
| 13911 | + .pip_compile() |
| 13912 | + .arg(requirements_in.path()) |
| 13913 | + .arg("--no-index") |
| 13914 | + .arg("--find-links") |
| 13915 | + .arg(context.temp_dir.path()), @r###" |
| 13916 | + success: true |
| 13917 | + exit_code: 0 |
| 13918 | + ----- stdout ----- |
| 13919 | + # This file was autogenerated by uv via the following command: |
| 13920 | + # uv pip compile --cache-dir [CACHE_DIR] [TEMP_DIR]/requirements.in --no-index |
| 13921 | + foo==1.2.3 |
| 13922 | + # via -r requirements.in |
| 13923 | +
|
| 13924 | + ----- stderr ----- |
| 13925 | + Resolved 1 package in [TIME] |
| 13926 | + "### |
| 13927 | + ); |
| 13928 | + |
| 13929 | + Ok(()) |
| 13930 | +} |
0 commit comments