Skip to content

Commit f44012f

Browse files
committed
Pass the resolved tar implementation through archive operations
1 parent daa0537 commit f44012f

20 files changed

Lines changed: 168 additions & 86 deletions

File tree

‎Cargo.lock‎

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

‎crates/uv-bench/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ uv-preview = { workspace = true }
6969
uv-pypi-types = { workspace = true }
7070
uv-python = { workspace = true }
7171
uv-resolver = { workspace = true }
72+
uv-static = { workspace = true }
7273
uv-types = { workspace = true }
7374
uv-workspace = { workspace = true }
7475

‎crates/uv-bench/benches/uv.rs‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ use uv_distribution_types::Requirement;
3333
use uv_extract::dirhash::UnhashedFile;
3434
use uv_extract::hash::{HashReader, Hasher};
3535
use uv_install_wheel::{InstallState, Layout, LinkMode};
36-
use uv_preview::{MaybePreviewFeature, Preview, PreviewFeature};
36+
use uv_preview::Preview;
3737
use uv_pypi_types::{HashAlgorithm, Scheme};
3838
use uv_python::PythonEnvironment;
3939
use uv_resolver::Manifest;
40+
use uv_static::TarBackend;
4041

4142
const MANY_FILES_WHEEL_FILENAME: &str = "manyfiles-0.0.0-py3-none-any.whl";
4243
const MANY_FILES_WHEEL_FILE_COUNT: usize = 10_000;
@@ -234,11 +235,6 @@ fn unpack_sdist_many_files(c: &mut Criterion<WallTime>) {
234235
.build()
235236
.expect("Failed to create Tokio runtime");
236237

237-
uv_preview::set(Preview::from_feature_names(&[MaybePreviewFeature::Known(
238-
PreviewFeature::TarCodec,
239-
)]))
240-
.expect("Failed to configure tar backend preview features");
241-
242238
c.bench_function("unpack_sdist_many_files", |b| {
243239
b.iter_batched(
244240
|| {
@@ -255,6 +251,7 @@ fn unpack_sdist_many_files(c: &mut Criterion<WallTime>) {
255251
archive,
256252
SourceDistExtension::TarGz,
257253
extracted_sdist,
254+
TarBackend::default(),
258255
))
259256
.expect("Failed to unpack sdist");
260257
let source_tree = uv_extract::strip_component(extracted_sdist.path())

‎crates/uv-bin-install/src/lib.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ use url::Url;
2323
use uv_client::retryable_on_request_failure;
2424
use uv_distribution_filename::LegacySourceDistExtension;
2525
use uv_distribution_filename::SourceDistExtension;
26-
use uv_static::{astral_mirror_base_url, astral_mirror_url_from_env, custom_astral_mirror_url};
26+
use uv_static::{
27+
TarBackend, astral_mirror_base_url, astral_mirror_url_from_env, custom_astral_mirror_url,
28+
};
2729

2830
use uv_cache::{Cache, CacheBucket, CacheEntry, Error as CacheError};
2931
use uv_client::{BaseClient, RetriableError, fetch_with_url_fallback};
@@ -701,6 +703,7 @@ pub async fn bin_install(
701703
retry_policy,
702704
cache,
703705
reporter,
706+
TarBackend::from_env(),
704707
)
705708
.await
706709
}
@@ -716,6 +719,7 @@ async fn bin_install_from_urls(
716719
retry_policy: &ExponentialBackoff,
717720
cache: &Cache,
718721
reporter: &dyn Reporter,
722+
tar_backend: TarBackend,
719723
) -> Result<PathBuf, Error> {
720724
let cache_entry = CacheEntry::new(
721725
cache
@@ -750,6 +754,7 @@ async fn bin_install_from_urls(
750754
format,
751755
url,
752756
&cache_entry,
757+
tar_backend,
753758
)
754759
},
755760
)
@@ -786,6 +791,7 @@ async fn download_and_unpack(
786791
format: ArchiveFormat,
787792
download_url: DisplaySafeUrl,
788793
cache_entry: &CacheEntry,
794+
tar_backend: TarBackend,
789795
) -> Result<PathBuf, Error> {
790796
// Create a temporary directory for extraction
791797
let temp_dir = tempfile::tempdir_in(cache.bucket(CacheBucket::Binaries))?;
@@ -842,7 +848,7 @@ async fn download_and_unpack(
842848

843849
let id = reporter.on_download_start(binary.name(), version, size);
844850
let mut progress_reader = ProgressReader::new(reader, id, reporter);
845-
let (temp_dir, _) = stream::archive(&mut progress_reader, format.into(), temp_dir)
851+
let (temp_dir, _) = stream::archive(&mut progress_reader, format.into(), temp_dir, tar_backend)
846852
.await
847853
.map_err(|e| Error::Extract { source: e })?;
848854
reporter.on_download_complete(id);

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

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ mod tests {
499499
use uv_preview::PreviewFeature;
500500
use uv_static::TarBackend;
501501

502-
use crate::source_dist::{SyncReader, build_source_dist_with_backend};
502+
use crate::source_dist::SyncReader;
503503

504504
const MOCK_UV_VERSION: &str = "1.0.0+test";
505505

@@ -570,7 +570,7 @@ mod tests {
570570
// normalize the path.
571571
let (_name, wheel_list_files) = list_wheel(source_root, MOCK_UV_VERSION, false)?;
572572
let source_dist_filename =
573-
build_source_dist_with_backend(source_root, dist, MOCK_UV_VERSION, false, tar_backend)?;
573+
build_source_dist(source_root, dist, MOCK_UV_VERSION, false, tar_backend)?;
574574
let source_dist_path = dist.join(source_dist_filename.to_string());
575575
let source_dist_contents = sdist_contents(&source_dist_path);
576576

@@ -1001,7 +1001,14 @@ mod tests {
10011001

10021002
// Build a wheel from a source distribution
10031003
let output_dir = TempDir::new().unwrap();
1004-
build_source_dist(src.path(), output_dir.path(), "0.5.15", false).unwrap();
1004+
build_source_dist(
1005+
src.path(),
1006+
output_dir.path(),
1007+
"0.5.15",
1008+
false,
1009+
TarBackend::default(),
1010+
)
1011+
.unwrap();
10051012
let sdist_tree = TempDir::new().unwrap();
10061013
let source_dist_path = output_dir.path().join("pep_pep639_license-1.0.0.tar.gz");
10071014
unpack_sdist(&source_dist_path, sdist_tree.path()).unwrap();
@@ -1232,7 +1239,13 @@ mod tests {
12321239
let dist = TempDir::new().unwrap();
12331240

12341241
// Source dist build should fail
1235-
let sdist_result = build_source_dist(src.path(), dist.path(), MOCK_UV_VERSION, false);
1242+
let sdist_result = build_source_dist(
1243+
src.path(),
1244+
dist.path(),
1245+
MOCK_UV_VERSION,
1246+
false,
1247+
TarBackend::default(),
1248+
);
12361249
assert!(sdist_result.is_err());
12371250

12381251
// Wheel build should fail
@@ -1278,7 +1291,13 @@ mod tests {
12781291
fs_err::write(&wheel_path, old_content).unwrap();
12791292

12801293
// Build should fail and delete existing files
1281-
let sdist_result = build_source_dist(src.path(), dist.path(), MOCK_UV_VERSION, false);
1294+
let sdist_result = build_source_dist(
1295+
src.path(),
1296+
dist.path(),
1297+
MOCK_UV_VERSION,
1298+
false,
1299+
TarBackend::default(),
1300+
);
12821301
assert!(sdist_result.is_err());
12831302

12841303
let wheel_result = build_wheel(src.path(), dist.path(), None, MOCK_UV_VERSION, false);
@@ -1334,7 +1353,14 @@ mod tests {
13341353
fs_err::write(&wheel_path, old_content).unwrap();
13351354

13361355
// Build should succeed and overwrite existing files
1337-
build_source_dist(src.path(), dist.path(), MOCK_UV_VERSION, false).unwrap();
1356+
build_source_dist(
1357+
src.path(),
1358+
dist.path(),
1359+
MOCK_UV_VERSION,
1360+
false,
1361+
TarBackend::default(),
1362+
)
1363+
.unwrap();
13381364
build_wheel(src.path(), dist.path(), None, MOCK_UV_VERSION, false).unwrap();
13391365

13401366
// Verify files were overwritten (content should be different)
@@ -2005,8 +2031,14 @@ mod tests {
20052031
.unwrap();
20062032

20072033
let dist = TempDir::new().unwrap();
2008-
let source_dist_filename =
2009-
build_source_dist(tmp_dir.path(), dist.path(), MOCK_UV_VERSION, false).unwrap();
2034+
let source_dist_filename = build_source_dist(
2035+
tmp_dir.path(),
2036+
dist.path(),
2037+
MOCK_UV_VERSION,
2038+
false,
2039+
TarBackend::default(),
2040+
)
2041+
.unwrap();
20102042
let source_dist_path = dist.path().join(source_dist_filename.to_string());
20112043
let contents = sdist_contents(&source_dist_path);
20122044

‎crates/uv-build-backend/src/source_dist.rs‎

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,6 @@ pub fn build_source_dist(
3636
source_dist_directory: &Path,
3737
uv_version: &str,
3838
show_warnings: bool,
39-
) -> Result<SourceDistFilename, Error> {
40-
build_source_dist_with_backend(
41-
source_tree,
42-
source_dist_directory,
43-
uv_version,
44-
show_warnings,
45-
TarBackend::from_env(),
46-
)
47-
}
48-
49-
pub(crate) fn build_source_dist_with_backend(
50-
source_tree: &Path,
51-
source_dist_directory: &Path,
52-
uv_version: &str,
53-
show_warnings: bool,
5439
tar_backend: TarBackend,
5540
) -> Result<SourceDistFilename, Error> {
5641
let pyproject_toml = PyProjectToml::parse(&source_tree.join("pyproject.toml"))?;
@@ -66,12 +51,15 @@ pub(crate) fn build_source_dist_with_backend(
6651
}
6752

6853
let temp_file = uv_fs::tempfile_in(source_dist_directory)?;
69-
if tar_backend == TarBackend::TarCodec {
70-
let writer = TarCodecGzWriter::new(temp_file.as_file(), &source_dist_path);
71-
write_source_dist(source_tree, writer, uv_version, show_warnings)?;
72-
} else {
73-
let writer = TokioTarGzWriter::new(temp_file.as_file(), &source_dist_path);
74-
write_source_dist(source_tree, writer, uv_version, show_warnings)?;
54+
match tar_backend {
55+
TarBackend::TarCodec => {
56+
let writer = TarCodecGzWriter::new(temp_file.as_file(), &source_dist_path);
57+
write_source_dist(source_tree, writer, uv_version, show_warnings)?;
58+
}
59+
TarBackend::TokioTar => {
60+
let writer = TokioTarGzWriter::new(temp_file.as_file(), &source_dist_path);
61+
write_source_dist(source_tree, writer, uv_version, show_warnings)?;
62+
}
7563
}
7664
temp_file
7765
.persist(&source_dist_path)

‎crates/uv-build/src/main.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::io::Write;
33
use std::path::PathBuf;
44
use std::str::FromStr;
55
use uv_preview::Preview;
6-
use uv_static::{EnvVars, parse_boolish_environment_variable};
6+
use uv_static::{EnvVars, TarBackend, parse_boolish_environment_variable};
77

88
use anyhow::{Context, Result, bail};
99
use tracing::debug;
@@ -76,6 +76,7 @@ fn main() -> Result<()> {
7676
&sdist_directory,
7777
uv_version::version(),
7878
false,
79+
TarBackend::from_env(),
7980
)?;
8081
// Tell the build frontend about the name of the artifact we built
8182
writeln!(&mut std::io::stdout(), "{filename}").context("stdout is closed")?;

‎crates/uv-dispatch/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ uv-pypi-types = { workspace = true }
3535
uv-python = { workspace = true }
3636
uv-requirements = { workspace = true }
3737
uv-resolver = { workspace = true }
38+
uv-static = { workspace = true }
3839
uv-types = { workspace = true }
3940
uv-version = { workspace = true }
4041
uv-workspace = { workspace = true }

‎crates/uv-dispatch/src/lib.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use uv_resolver::{
3838
ExcludeNewer, FlatIndex, Flexibility, InMemoryIndex, Manifest, OptionsBuilder,
3939
PythonRequirement, Resolver, ResolverEnvironment,
4040
};
41+
use uv_static::TarBackend;
4142
use uv_types::{
4243
AnyErrorBuild, BuildArena, BuildContext, BuildIsolation, BuildStack, EmptyInstalledPackages,
4344
HashStrategy, InFlight, ResolvedRequirements, SourceTreeEditablePolicy,
@@ -148,6 +149,7 @@ pub struct BuildDispatch<'a> {
148149
workspace_cache: WorkspaceCache,
149150
concurrency: Concurrency,
150151
preview: Preview,
152+
tar_backend: TarBackend,
151153
}
152154

153155
impl<'a> BuildDispatch<'a> {
@@ -202,6 +204,7 @@ impl<'a> BuildDispatch<'a> {
202204
workspace_cache,
203205
concurrency,
204206
preview,
207+
tar_backend: TarBackend::from_env(),
205208
}
206209
}
207210

@@ -244,6 +247,10 @@ impl<'a> BuildDispatch<'a> {
244247
impl BuildContext for BuildDispatch<'_> {
245248
type SourceDistBuilder = SourceBuild;
246249

250+
fn tar_backend(&self) -> TarBackend {
251+
self.tar_backend
252+
}
253+
247254
fn interpreter(&self) -> impl Future<Output = &Interpreter> + '_ {
248255
future::ready(self.interpreter)
249256
}
@@ -629,6 +636,7 @@ impl BuildContext for BuildDispatch<'_> {
629636
debug!("Performing direct build for {identifier}");
630637

631638
let output_dir = output_dir.to_path_buf();
639+
let tar_backend = self.tar_backend;
632640
let filename = tokio::task::spawn_blocking(move || -> Result<_> {
633641
let filename = match build_kind {
634642
BuildKind::Wheel => {
@@ -647,6 +655,7 @@ impl BuildContext for BuildDispatch<'_> {
647655
&output_dir,
648656
uv_version::version(),
649657
sources.is_none(),
658+
tar_backend,
650659
)?;
651660
DistFilename::SourceDistFilename(source_dist)
652661
}

‎crates/uv-distribution/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ uv-preview = { workspace = true }
4040
uv-pypi-types = { workspace = true }
4141
uv-python = { workspace = true }
4242
uv-redacted = { workspace = true }
43+
uv-static = { workspace = true }
4344
uv-threads = { workspace = true }
4445
uv-types = { workspace = true }
4546
uv-workspace = { workspace = true }

0 commit comments

Comments
 (0)
⌂ 换网址