Migrate to tokio (#27)

Closes https://github.com/astral-sh/puffin/issues/26.
This commit is contained in:
Charlie Marsh 2023-10-06 16:31:03 -04:00 committed by GitHub
parent ca6aa207ff
commit dd26cfa0cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 12 additions and 15 deletions

View file

@ -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 }

View file

@ -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);

View file

@ -46,7 +46,7 @@ struct SyncArgs {
no_cache: bool,
}
#[async_std::main]
#[tokio::main]
async fn main() -> ExitCode {
let cli = Cli::parse();

View file

@ -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 }

View file

@ -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.