From dd26cfa0cca36c375e740d4781125e66f1a567cc Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 6 Oct 2023 16:31:03 -0400 Subject: [PATCH] Migrate to `tokio` (#27) Closes https://github.com/astral-sh/puffin/issues/26. --- Cargo.toml | 7 ++----- README.md | 4 ++-- crates/puffin-cli/Cargo.toml | 2 +- crates/puffin-cli/src/logging.rs | 3 +-- crates/puffin-cli/src/main.rs | 2 +- crates/puffin-installer/Cargo.toml | 3 ++- crates/puffin-installer/src/lib.rs | 6 +++--- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ff4b2095b..3f3410d2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,11 +13,6 @@ license = "MIT OR Apache-2.0" [workspace.dependencies] anyhow = { version = "1.0.75" } -async-std = { version = "1.12.0", features = [ - "attributes", - "tokio1", - "unstable", -] } bitflags = { version = "2.4.0" } clap = { version = "4.4.6" } colored = { version = "2.0.4" } @@ -44,6 +39,8 @@ serde_json = { version = "1.0.107" } target-lexicon = { version = "0.12.11" } tempfile = { version = "3.8.0" } thiserror = { version = "1.0.49" } +tokio = { version = "1.16.1", features = ["rt-multi-thread"] } +tokio-util = { version = "0.7.9", features = ["compat"] } tracing = { version = "0.1.37" } tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } tracing-tree = { version = "0.2.5" } diff --git a/README.md b/README.md index 209e19e1e..584fdafb5 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ To compare a warm run of `puffin` to `pip`: ```shell hyperfine --runs 10 --warmup 3 \ - "./target/release/puffin-cli install requirements.txt" \ + "./target/release/puffin-cli sync requirements.txt" \ "pip install -r requirements.txt" ``` @@ -30,7 +30,7 @@ To compare a cold run of `puffin` to `pip`: ```shell hyperfine --runs 10 --warmup 3 \ - "./target/release/puffin-cli install requirements.txt --no-cache" \ + "./target/release/puffin-cli sync requirements.txt --no-cache" \ "pip install -r requirements.txt --ignore-installed --no-cache-dir" ``` diff --git a/crates/puffin-cli/Cargo.toml b/crates/puffin-cli/Cargo.toml index 70c0c9702..63b02d1bd 100644 --- a/crates/puffin-cli/Cargo.toml +++ b/crates/puffin-cli/Cargo.toml @@ -12,7 +12,6 @@ puffin-package = { path = "../puffin-package" } puffin-resolver = { path = "../puffin-resolver" } anyhow = { workspace = true } -async-std = { workspace = true } clap = { workspace = true, features = ["derive"] } colored = { workspace = true } directories = { workspace = true } @@ -25,3 +24,4 @@ tracing-tree = { workspace = true } tracing-subscriber = { workspace = true } url = { workspace = true } tempfile = { workspace = true } +tokio = { workspace = true } diff --git a/crates/puffin-cli/src/logging.rs b/crates/puffin-cli/src/logging.rs index 6e1f1dc88..2449b0400 100644 --- a/crates/puffin-cli/src/logging.rs +++ b/crates/puffin-cli/src/logging.rs @@ -9,8 +9,7 @@ pub(crate) fn setup_logging() -> Result<()> { let targets = Targets::new() .with_target("hyper", LevelFilter::WARN) .with_target("reqwest", LevelFilter::WARN) - .with_target("async_io", LevelFilter::WARN) - .with_target("async_std", LevelFilter::WARN) + .with_target("tokio", LevelFilter::WARN) .with_target("blocking", LevelFilter::OFF) .with_default(LevelFilter::TRACE); diff --git a/crates/puffin-cli/src/main.rs b/crates/puffin-cli/src/main.rs index 0838e06f4..37db96f80 100644 --- a/crates/puffin-cli/src/main.rs +++ b/crates/puffin-cli/src/main.rs @@ -46,7 +46,7 @@ struct SyncArgs { no_cache: bool, } -#[async_std::main] +#[tokio::main] async fn main() -> ExitCode { let cli = Cli::parse(); diff --git a/crates/puffin-installer/Cargo.toml b/crates/puffin-installer/Cargo.toml index cd3769522..724fecfca 100644 --- a/crates/puffin-installer/Cargo.toml +++ b/crates/puffin-installer/Cargo.toml @@ -14,8 +14,9 @@ puffin-client = { path = "../puffin-client" } puffin-interpreter = { path = "../puffin-interpreter" } anyhow = { workspace = true } -async-std = { workspace = true } install-wheel-rs = { workspace = true } tempfile = { workspace = true } tracing = { workspace = true } url = { workspace = true } +tokio = { workspace = true } +tokio-util = { workspace = true } diff --git a/crates/puffin-installer/src/lib.rs b/crates/puffin-installer/src/lib.rs index 61f1cf5b7..a801ab800 100644 --- a/crates/puffin-installer/src/lib.rs +++ b/crates/puffin-installer/src/lib.rs @@ -2,6 +2,7 @@ use std::str::FromStr; use anyhow::Result; use install_wheel_rs::{install_wheel, InstallLocation}; +use tokio_util::compat::FuturesAsyncReadCompatExt; use url::Url; use puffin_client::{File, PypiClient}; @@ -24,9 +25,8 @@ pub async fn install( let reader = client.stream_external(&url).await?; // TODO(charlie): Stream the unzip. - let mut writer = - async_std::fs::File::create(tmp_dir.path().join(&wheel.hashes.sha256)).await?; - async_std::io::copy(reader, &mut writer).await?; + let mut writer = tokio::fs::File::create(tmp_dir.path().join(&wheel.hashes.sha256)).await?; + tokio::io::copy(&mut reader.compat(), &mut writer).await?; } // Install each wheel.