Skip to content

Commit ac41abc

Browse files
Turn reqwest_blocking_get into download_to_disk
1 parent 36cc197 commit ac41abc

6 files changed

Lines changed: 62 additions & 49 deletions

File tree

crates/uv/tests/common/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ use assert_fs::assert::PathAssert;
1414
use assert_fs::fixture::{ChildPath, PathChild, PathCopy, PathCreateDir, SymlinkToFile};
1515
use base64::{prelude::BASE64_STANDARD as base64, Engine};
1616
use etcetera::BaseStrategy;
17+
use futures::StreamExt;
1718
use indoc::formatdoc;
1819
use itertools::Itertools;
1920
use predicates::prelude::predicate;
2021
use regex::Regex;
2122

23+
use tokio::io::AsyncWriteExt;
2224
use uv_cache::Cache;
2325
use uv_fs::Simplified;
2426
use uv_python::managed::ManagedPythonInstallations;
@@ -1282,7 +1284,7 @@ pub fn decode_token(content: &[&str]) -> String {
12821284
/// Simulates `reqwest::blocking::get` but returns bytes directly, and disables
12831285
/// certificate verification, passing through the `BaseClient`
12841286
#[tokio::main(flavor = "current_thread")]
1285-
pub async fn reqwest_blocking_get(url: &str) -> Vec<u8> {
1287+
pub async fn download_to_disk(url: &str, path: &Path) {
12861288
let trusted_hosts: Vec<_> = std::env::var("UV_INSECURE_HOST")
12871289
.unwrap_or_default()
12881290
.split(' ')
@@ -1295,7 +1297,13 @@ pub async fn reqwest_blocking_get(url: &str) -> Vec<u8> {
12951297
let url: reqwest::Url = url.parse().unwrap();
12961298
let client = client.for_host(&url);
12971299
let response = client.request(http::Method::GET, url).send().await.unwrap();
1298-
response.bytes().await.unwrap().to_vec()
1300+
1301+
let mut file = tokio::fs::File::create(path).await.unwrap();
1302+
let mut stream = response.bytes_stream();
1303+
while let Some(chunk) = stream.next().await {
1304+
file.write_all(&chunk.unwrap()).await.unwrap();
1305+
}
1306+
file.sync_all().await.unwrap();
12991307
}
13001308

13011309
/// Utility macro to return the name of the current function.

crates/uv/tests/lock.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use insta::assert_snapshot;
88
use std::io::BufReader;
99
use url::Url;
1010

11-
use common::{reqwest_blocking_get, uv_snapshot, TestContext};
11+
use common::{download_to_disk, uv_snapshot, TestContext};
1212
use uv_fs::Simplified;
1313

1414
use crate::common::{build_vendor_links_url, decode_token, packse_index_url};
@@ -7881,11 +7881,11 @@ fn lock_sources_archive() -> Result<()> {
78817881
let context = TestContext::new("3.12");
78827882

78837883
// Download the source.
7884-
let bytes =
7885-
reqwest_blocking_get("https://github.com/user-attachments/files/16592193/workspace.zip");
78867884
let workspace_archive = context.temp_dir.child("workspace.zip");
7887-
let mut workspace_archive_file = fs_err::File::create(&*workspace_archive)?;
7888-
std::io::copy(&mut &bytes[..], &mut workspace_archive_file)?;
7885+
download_to_disk(
7886+
"https://github.com/user-attachments/files/16592193/workspace.zip",
7887+
&workspace_archive,
7888+
);
78897889

78907890
let pyproject_toml = context.temp_dir.child("pyproject.toml");
78917891
pyproject_toml.write_str(&formatdoc! {
@@ -8020,11 +8020,11 @@ fn lock_sources_source_tree() -> Result<()> {
80208020
let context = TestContext::new("3.12");
80218021

80228022
// Download the source.
8023-
let bytes =
8024-
reqwest_blocking_get("https://github.com/user-attachments/files/16592193/workspace.zip");
80258023
let workspace_archive = context.temp_dir.child("workspace.zip");
8026-
let mut workspace_archive_file = fs_err::File::create(&*workspace_archive)?;
8027-
std::io::copy(&mut &bytes[..], &mut workspace_archive_file)?;
8024+
download_to_disk(
8025+
"https://github.com/user-attachments/files/16592193/workspace.zip",
8026+
&workspace_archive,
8027+
);
80288028

80298029
// Unzip the file.
80308030
let file = fs_err::File::open(&*workspace_archive)?;

crates/uv/tests/pip_compile.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use assert_fs::prelude::*;
1010
use indoc::indoc;
1111
use url::Url;
1212

13-
use common::{reqwest_blocking_get, uv_snapshot, TestContext};
13+
use common::{download_to_disk, uv_snapshot, TestContext};
1414
use uv_fs::Simplified;
1515

1616
mod common;
@@ -2596,10 +2596,11 @@ fn compile_wheel_path_dependency() -> Result<()> {
25962596
let context = TestContext::new("3.12");
25972597

25982598
// Download a wheel.
2599-
let bytes = reqwest_blocking_get("https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl");
26002599
let flask_wheel = context.temp_dir.child("flask-3.0.0-py3-none-any.whl");
2601-
let mut flask_wheel_file = fs::File::create(&flask_wheel)?;
2602-
std::io::copy(&mut &bytes[..], &mut flask_wheel_file)?;
2600+
download_to_disk(
2601+
"https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl",
2602+
&flask_wheel,
2603+
);
26032604

26042605
let requirements_in = context.temp_dir.child("requirements.in");
26052606
requirements_in.write_str(&format!(
@@ -2846,10 +2847,11 @@ fn compile_wheel_path_dependency() -> Result<()> {
28462847
fn compile_source_distribution_path_dependency() -> Result<()> {
28472848
let context = TestContext::new("3.12");
28482849
// Download a source distribution.
2849-
let bytes = reqwest_blocking_get("https://files.pythonhosted.org/packages/d8/09/c1a7354d3925a3c6c8cfdebf4245bae67d633ffda1ba415add06ffc839c5/flask-3.0.0.tar.gz");
28502850
let flask_wheel = context.temp_dir.child("flask-3.0.0.tar.gz");
2851-
let mut flask_wheel_file = std::fs::File::create(&flask_wheel)?;
2852-
std::io::copy(&mut &bytes[..], &mut flask_wheel_file)?;
2851+
download_to_disk(
2852+
"https://files.pythonhosted.org/packages/d8/09/c1a7354d3925a3c6c8cfdebf4245bae67d633ffda1ba415add06ffc839c5/flask-3.0.0.tar.gz",
2853+
&flask_wheel,
2854+
);
28532855

28542856
let requirements_in = context.temp_dir.child("requirements.in");
28552857
requirements_in.write_str(&format!(
@@ -3521,10 +3523,11 @@ fn preserve_url() -> Result<()> {
35213523
fn preserve_project_root() -> Result<()> {
35223524
let context = TestContext::new("3.12");
35233525
// Download a wheel.
3524-
let bytes = reqwest_blocking_get("https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl");
35253526
let flask_wheel = context.temp_dir.child("flask-3.0.0-py3-none-any.whl");
3526-
let mut flask_wheel_file = std::fs::File::create(flask_wheel)?;
3527-
std::io::copy(&mut &bytes[..], &mut flask_wheel_file)?;
3527+
download_to_disk(
3528+
"https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl",
3529+
&flask_wheel,
3530+
);
35283531

35293532
let requirements_in = context.temp_dir.child("requirements.in");
35303533
requirements_in.write_str("flask @ file://${PROJECT_ROOT}/flask-3.0.0-py3-none-any.whl")?;
@@ -3674,10 +3677,11 @@ fn error_missing_unnamed_env_var() -> Result<()> {
36743677
fn respect_file_env_var() -> Result<()> {
36753678
let context = TestContext::new("3.12");
36763679
// Download a wheel.
3677-
let bytes = reqwest_blocking_get("https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl");
36783680
let flask_wheel = context.temp_dir.child("flask-3.0.0-py3-none-any.whl");
3679-
let mut flask_wheel_file = std::fs::File::create(flask_wheel)?;
3680-
std::io::copy(&mut &bytes[..], &mut flask_wheel_file)?;
3681+
download_to_disk(
3682+
"https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl",
3683+
&flask_wheel,
3684+
);
36813685

36823686
let requirements_in = context.temp_dir.child("requirements.in");
36833687
requirements_in.write_str("flask @ ${FILE_PATH}")?;

crates/uv/tests/pip_sync.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use indoc::indoc;
1313
use predicates::Predicate;
1414
use url::Url;
1515

16-
use common::{reqwest_blocking_get, uv_snapshot, venv_to_interpreter};
16+
use common::{download_to_disk, uv_snapshot, venv_to_interpreter};
1717
use uv_fs::Simplified;
1818

1919
use crate::common::{copy_dir_all, site_packages_path, TestContext};
@@ -1073,10 +1073,8 @@ fn install_local_wheel() -> Result<()> {
10731073
let context = TestContext::new("3.12");
10741074

10751075
// Download a wheel.
1076-
let response = reqwest_blocking_get("https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl");
10771076
let archive = context.temp_dir.child("tomli-2.0.1-py3-none-any.whl");
1078-
let mut archive_file = fs_err::File::create(archive.path())?;
1079-
std::io::copy(&mut &response[..], &mut archive_file)?;
1077+
download_to_disk("https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl", &archive);
10801078

10811079
let requirements_txt = context.temp_dir.child("requirements.txt");
10821080
requirements_txt.write_str(&format!(
@@ -1212,10 +1210,8 @@ fn mismatched_version() -> Result<()> {
12121210
let context = TestContext::new("3.12");
12131211

12141212
// Download a wheel.
1215-
let bytes = reqwest_blocking_get("https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl");
12161213
let archive = context.temp_dir.child("tomli-3.7.2-py3-none-any.whl");
1217-
let mut archive_file = fs_err::File::create(archive.path())?;
1218-
std::io::copy(&mut &bytes[..], &mut archive_file)?;
1214+
download_to_disk("https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl", &archive);
12191215

12201216
let requirements_txt = context.temp_dir.child("requirements.txt");
12211217
requirements_txt.write_str(&format!(
@@ -1247,10 +1243,11 @@ fn mismatched_name() -> Result<()> {
12471243
let context = TestContext::new("3.12");
12481244

12491245
// Download a wheel.
1250-
let bytes = reqwest_blocking_get("https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl");
12511246
let archive = context.temp_dir.child("foo-2.0.1-py3-none-any.whl");
1252-
let mut archive_file = fs_err::File::create(archive.path())?;
1253-
std::io::copy(&mut &bytes[..], &mut archive_file)?;
1247+
download_to_disk(
1248+
"https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl",
1249+
&archive,
1250+
);
12541251

12551252
let requirements_txt = context.temp_dir.child("requirements.txt");
12561253
requirements_txt.write_str(&format!(
@@ -1283,10 +1280,11 @@ fn install_local_source_distribution() -> Result<()> {
12831280
let context = TestContext::new("3.12");
12841281

12851282
// Download a source distribution.
1286-
let bytes = reqwest_blocking_get("https://files.pythonhosted.org/packages/b0/b4/bc2baae3970c282fae6c2cb8e0f179923dceb7eaffb0e76170628f9af97b/wheel-0.42.0.tar.gz");
12871283
let archive = context.temp_dir.child("wheel-0.42.0.tar.gz");
1288-
let mut archive_file = fs_err::File::create(archive.path())?;
1289-
std::io::copy(&mut &bytes[..], &mut archive_file)?;
1284+
download_to_disk(
1285+
"https://files.pythonhosted.org/packages/b0/b4/bc2baae3970c282fae6c2cb8e0f179923dceb7eaffb0e76170628f9af97b/wheel-0.42.0.tar.gz",
1286+
&archive,
1287+
);
12901288

12911289
let requirements_txt = context.temp_dir.child("requirements.txt");
12921290
requirements_txt.write_str(&format!(
@@ -1643,10 +1641,11 @@ fn install_path_source_dist_cached() -> Result<()> {
16431641
let context = TestContext::new("3.12");
16441642

16451643
// Download a source distribution.
1646-
let bytes = reqwest_blocking_get("https://files.pythonhosted.org/packages/10/1f/57aa4cce1b1abf6b433106676e15f9fa2c92ed2bd4cf77c3b50a9e9ac773/source_distribution-0.0.1.tar.gz");
16471644
let archive = context.temp_dir.child("source_distribution-0.0.1.tar.gz");
1648-
let mut archive_file = fs_err::File::create(archive.path())?;
1649-
std::io::copy(&mut &bytes[..], &mut archive_file)?;
1645+
download_to_disk(
1646+
"https://files.pythonhosted.org/packages/10/1f/57aa4cce1b1abf6b433106676e15f9fa2c92ed2bd4cf77c3b50a9e9ac773/source_distribution-0.0.1.tar.gz",
1647+
&archive,
1648+
);
16501649

16511650
let requirements_txt = context.temp_dir.child("requirements.txt");
16521651
requirements_txt.write_str(&format!(
@@ -1738,10 +1737,11 @@ fn install_path_built_dist_cached() -> Result<()> {
17381737
let context = TestContext::new("3.12");
17391738

17401739
// Download a wheel.
1741-
let bytes = reqwest_blocking_get("https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl");
17421740
let archive = context.temp_dir.child("tomli-2.0.1-py3-none-any.whl");
1743-
let mut archive_file = fs_err::File::create(archive.path())?;
1744-
std::io::copy(&mut &bytes[..], &mut archive_file)?;
1741+
download_to_disk(
1742+
"https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl",
1743+
&archive,
1744+
);
17451745

17461746
let requirements_txt = context.temp_dir.child("requirements.txt");
17471747
let url = Url::from_file_path(archive.path()).unwrap();

crates/uv/tests/show_settings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,12 +3557,12 @@ fn allow_insecure_host() -> anyhow::Result<()> {
35573557
index_strategy: FirstIndex,
35583558
keyring_provider: Disabled,
35593559
allow_insecure_host: [
3560-
TrustedHost {
3560+
Host {
35613561
scheme: None,
35623562
host: "google.com",
35633563
port: None,
35643564
},
3565-
TrustedHost {
3565+
Host {
35663566
scheme: None,
35673567
host: "example.com",
35683568
port: None,

crates/uv/tests/sync.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use assert_cmd::prelude::*;
55
use assert_fs::{fixture::ChildPath, prelude::*};
66
use insta::assert_snapshot;
77

8-
use common::{reqwest_blocking_get, uv_snapshot, venv_bin_path, TestContext};
8+
use common::{download_to_disk, uv_snapshot, venv_bin_path, TestContext};
99
use predicates::prelude::predicate;
1010
use tempfile::tempdir_in;
1111

@@ -2313,12 +2313,13 @@ fn sync_wheel_path_source_error() -> Result<()> {
23132313
let context = TestContext::new("3.12");
23142314

23152315
// Download a wheel.
2316-
let bytes = reqwest_blocking_get( "https://files.pythonhosted.org/packages/08/fd/cc2fedbd887223f9f5d170c96e57cbf655df9831a6546c1727ae13fa977a/cffi-1.17.1-cp310-cp310-macosx_11_0_arm64.whl");
23172316
let archive = context
23182317
.temp_dir
23192318
.child("cffi-1.17.1-cp310-cp310-macosx_11_0_arm64.whl");
2320-
let mut archive_file = fs_err::File::create(archive.path())?;
2321-
std::io::copy(&mut &bytes[..], &mut archive_file)?;
2319+
download_to_disk(
2320+
"https://files.pythonhosted.org/packages/08/fd/cc2fedbd887223f9f5d170c96e57cbf655df9831a6546c1727ae13fa977a/cffi-1.17.1-cp310-cp310-macosx_11_0_arm64.whl",
2321+
&archive,
2322+
);
23222323

23232324
let pyproject_toml = context.temp_dir.child("pyproject.toml");
23242325
pyproject_toml.write_str(

0 commit comments

Comments
 (0)