diff --git a/crates/puffin-build/src/lib.rs b/crates/puffin-build/src/lib.rs index fb50318a6..c7ed1aa57 100644 --- a/crates/puffin-build/src/lib.rs +++ b/crates/puffin-build/src/lib.rs @@ -436,7 +436,7 @@ async fn resolve_and_install( debug!("Installing {} build requirements", requirements.len()); let local_index = if let Some(cache) = cache { - LocalIndex::from_directory(cache).await? + LocalIndex::try_from_directory(cache)? } else { LocalIndex::default() }; diff --git a/crates/puffin-cli/src/commands/freeze.rs b/crates/puffin-cli/src/commands/freeze.rs index 011915af1..4e92148c0 100644 --- a/crates/puffin-cli/src/commands/freeze.rs +++ b/crates/puffin-cli/src/commands/freeze.rs @@ -11,7 +11,7 @@ use crate::commands::ExitStatus; use crate::printer::Printer; /// Enumerate the installed packages in the current environment. -pub(crate) async fn freeze(cache: Option<&Path>, _printer: Printer) -> Result { +pub(crate) fn freeze(cache: Option<&Path>, _printer: Printer) -> Result { // Detect the current Python interpreter. let platform = Platform::current()?; let python = PythonExecutable::from_env(platform, cache)?; @@ -21,7 +21,7 @@ pub(crate) async fn freeze(cache: Option<&Path>, _printer: Printer) -> Result, python: &PythonExecutable, ) -> Result { // Index all the already-installed packages in site-packages. - let mut site_packages = SitePackages::from_executable(python).await?; + let mut site_packages = SitePackages::try_from_executable(python)?; // Index all the already-downloaded wheels in the cache. let local_index = if let Some(cache) = cache { - LocalIndex::from_directory(cache).await? + LocalIndex::try_from_directory(cache)? } else { LocalIndex::default() }; diff --git a/crates/puffin-cli/src/commands/pip_uninstall.rs b/crates/puffin-cli/src/commands/pip_uninstall.rs index b4c0f458a..9c3f4dccb 100644 --- a/crates/puffin-cli/src/commands/pip_uninstall.rs +++ b/crates/puffin-cli/src/commands/pip_uninstall.rs @@ -39,7 +39,7 @@ pub(crate) async fn pip_uninstall( ); // Index the current `site-packages` directory. - let site_packages = puffin_installer::SitePackages::from_executable(&python).await?; + let site_packages = puffin_installer::SitePackages::try_from_executable(&python)?; // Sort and deduplicate the requirements. let packages = { diff --git a/crates/puffin-cli/src/main.rs b/crates/puffin-cli/src/main.rs index a5d6faf26..0bbced5c7 100644 --- a/crates/puffin-cli/src/main.rs +++ b/crates/puffin-cli/src/main.rs @@ -198,7 +198,6 @@ async fn main() -> ExitCode { .filter(|_| !cli.no_cache), printer, ) - .await } Commands::Venv(args) => commands::venv(&args.name, args.python.as_deref(), printer).await, Commands::Add(args) => commands::add(&args.name, printer), diff --git a/crates/puffin-installer/Cargo.toml b/crates/puffin-installer/Cargo.toml index d8136b7fc..bdfba2576 100644 --- a/crates/puffin-installer/Cargo.toml +++ b/crates/puffin-installer/Cargo.toml @@ -26,4 +26,4 @@ tokio = { workspace = true } tokio-util = { workspace = true } tracing = { workspace = true } url = { workspace = true } -zip = { workspace = true } \ No newline at end of file +zip = { workspace = true } diff --git a/crates/puffin-installer/src/cache.rs b/crates/puffin-installer/src/cache.rs index 788d6a46a..775be4040 100644 --- a/crates/puffin-installer/src/cache.rs +++ b/crates/puffin-installer/src/cache.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; -use fs_err::tokio as fs; +use fs_err as fs; static WHEEL_CACHE: &str = "wheels-v0"; @@ -23,13 +23,13 @@ impl WheelCache { } /// Initialize the wheel cache. - pub(crate) async fn init(&self) -> std::io::Result<()> { - fs::create_dir_all(&self.root).await + pub(crate) fn init(&self) -> std::io::Result<()> { + fs::create_dir_all(&self.root) } /// Returns a handle to the wheel cache directory. - pub(crate) async fn read_dir(&self) -> std::io::Result { - fs::read_dir(&self.root).await + pub(crate) fn read_dir(&self) -> std::io::Result { + fs::read_dir(&self.root) } /// Returns the cache root. diff --git a/crates/puffin-installer/src/downloader.rs b/crates/puffin-installer/src/downloader.rs index cdd1ac789..ef11e6e6b 100644 --- a/crates/puffin-installer/src/downloader.rs +++ b/crates/puffin-installer/src/downloader.rs @@ -47,7 +47,7 @@ impl<'a> Downloader<'a> { ) -> Result> { // Create the wheel cache subdirectory, if necessary. let wheel_cache = WheelCache::new(target); - wheel_cache.init().await?; + wheel_cache.init()?; // Phase 1: Fetch the wheels in parallel. let mut fetches = JoinSet::new(); diff --git a/crates/puffin-installer/src/lib.rs b/crates/puffin-installer/src/lib.rs index 4c17af430..65396a2b3 100644 --- a/crates/puffin-installer/src/lib.rs +++ b/crates/puffin-installer/src/lib.rs @@ -2,8 +2,8 @@ pub use distribution::{ CachedDistribution, Distribution, InstalledDistribution, RemoteDistribution, }; pub use downloader::{Downloader, Reporter as DownloadReporter}; -pub use index::LocalIndex; pub use installer::{Installer, Reporter as InstallReporter}; +pub use local_index::LocalIndex; pub use site_packages::SitePackages; pub use uninstall::uninstall; pub use unzipper::{Reporter as UnzipReporter, Unzipper}; @@ -11,8 +11,8 @@ pub use unzipper::{Reporter as UnzipReporter, Unzipper}; mod cache; mod distribution; mod downloader; -mod index; mod installer; +mod local_index; mod site_packages; mod uninstall; mod unzipper; diff --git a/crates/puffin-installer/src/index.rs b/crates/puffin-installer/src/local_index.rs similarity index 80% rename from crates/puffin-installer/src/index.rs rename to crates/puffin-installer/src/local_index.rs index 8e8089c9e..73fc514c3 100644 --- a/crates/puffin-installer/src/index.rs +++ b/crates/puffin-installer/src/local_index.rs @@ -14,16 +14,17 @@ pub struct LocalIndex(HashMap); impl LocalIndex { /// Build an index of cached distributions from a directory. - pub async fn from_directory(path: &Path) -> Result { + pub fn try_from_directory(path: &Path) -> Result { let mut index = HashMap::new(); let cache = WheelCache::new(path); - let Ok(mut dir) = cache.read_dir().await else { + let Ok(dir) = cache.read_dir() else { return Ok(Self(index)); }; - while let Some(entry) = dir.next_entry().await? { - if entry.file_type().await?.is_dir() { + for entry in dir { + let entry = entry?; + if entry.file_type()?.is_dir() { if let Some(dist_info) = CachedDistribution::try_from_path(&entry.path())? { index.insert(dist_info.name().clone(), dist_info); } diff --git a/crates/puffin-installer/src/site_packages.rs b/crates/puffin-installer/src/site_packages.rs index 75b1d3347..50bda7e0f 100644 --- a/crates/puffin-installer/src/site_packages.rs +++ b/crates/puffin-installer/src/site_packages.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use anyhow::Result; -use fs_err::tokio as fs; +use fs_err as fs; use puffin_interpreter::PythonExecutable; use puffin_package::package_name::PackageName; @@ -13,12 +13,12 @@ pub struct SitePackages(BTreeMap); impl SitePackages { /// Build an index of installed packages from the given Python executable. - pub async fn from_executable(python: &PythonExecutable) -> Result { + pub fn try_from_executable(python: &PythonExecutable) -> Result { let mut index = BTreeMap::new(); - let mut dir = fs::read_dir(python.site_packages()).await?; - while let Some(entry) = dir.next_entry().await? { - if entry.file_type().await?.is_dir() { + for entry in fs::read_dir(python.site_packages())? { + let entry = entry?; + if entry.file_type()?.is_dir() { if let Some(dist_info) = InstalledDistribution::try_from_path(&entry.path())? { index.insert(dist_info.name().clone(), dist_info); } diff --git a/crates/puffin-installer/src/unzipper.rs b/crates/puffin-installer/src/unzipper.rs index ae2d19449..d44e12f0f 100644 --- a/crates/puffin-installer/src/unzipper.rs +++ b/crates/puffin-installer/src/unzipper.rs @@ -1,8 +1,6 @@ use std::path::Path; use anyhow::Result; -use fs_err::tokio as fs; -use fs_err::File; use rayon::iter::ParallelBridge; use rayon::iter::ParallelIterator; use tracing::debug; @@ -38,7 +36,7 @@ impl Unzipper { ) -> Result> { // Create the wheel cache subdirectory, if necessary. let wheel_cache = WheelCache::new(target); - wheel_cache.init().await?; + wheel_cache.init()?; let staging = tempfile::tempdir_in(wheel_cache.root())?; @@ -57,7 +55,7 @@ impl Unzipper { .await??; // Write the unzipped wheel to the target directory. - fs::rename( + fs_err::tokio::rename( staging.path().join(remote.id()), wheel_cache.entry(&remote.id()), ) @@ -104,15 +102,15 @@ fn unzip_wheel(wheel: InMemoryDistribution, target: &Path) -> Result<()> { // Create necessary parent directories. let path = target.join(file_path); if file.is_dir() { - std::fs::create_dir_all(path)?; + fs_err::create_dir_all(path)?; return Ok(()); } if let Some(parent) = path.parent() { - std::fs::create_dir_all(parent)?; + fs_err::create_dir_all(parent)?; } // Write the file. - let mut outfile = File::create(&path)?; + let mut outfile = fs_err::File::create(&path)?; std::io::copy(&mut file, &mut outfile)?; // Set permissions.