-
Notifications
You must be signed in to change notification settings - Fork 966
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build source distributions in the resolver
- Loading branch information
Showing
23 changed files
with
392 additions
and
111 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
downloads | ||
wheels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[package] | ||
name = "puffin-build-cli" | ||
version = "0.0.1" | ||
description = "Build wheels from source distributions" | ||
edition = { workspace = true } | ||
rust-version = { workspace = true } | ||
homepage = { workspace = true } | ||
documentation = { workspace = true } | ||
repository = { workspace = true } | ||
authors = { workspace = true } | ||
license = { workspace = true } | ||
|
||
[dependencies] | ||
gourgeist = { path = "../gourgeist" } | ||
pep508_rs = { path = "../pep508-rs" } | ||
platform-host = { path = "../platform-host" } | ||
platform-tags = { path = "../platform-tags" } | ||
puffin-build = { path = "../puffin-build" } | ||
puffin-client = { path = "../puffin-client" } | ||
puffin-installer = { path = "../puffin-installer" } | ||
puffin-interpreter = { path = "../puffin-interpreter" } | ||
puffin-package = { path = "../puffin-package" } | ||
puffin-resolver = { path = "../puffin-resolver" } | ||
puffin-workspace = { path = "../puffin-workspace" } | ||
|
||
anyhow = { workspace = true } | ||
clap = { workspace = true, features = ["derive"] } | ||
directories = { workspace = true } | ||
fs-err = { workspace = true } | ||
futures = { workspace = true } | ||
itertools = { workspace = true } | ||
owo-colors = { workspace = true } | ||
tempfile = { workspace = true } | ||
tokio = { workspace = true } | ||
tracing = { workspace = true } | ||
tracing-subscriber = { workspace = true } | ||
which = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod sdist; | ||
|
||
pub use sdist::resolve_and_install; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use anyhow::Context; | ||
use futures::FutureExt; | ||
use itertools::{Either, Itertools}; | ||
use pep508_rs::Requirement; | ||
use platform_host::Platform; | ||
use platform_tags::Tags; | ||
use puffin_client::PypiClientBuilder; | ||
use puffin_installer::{CachedDistribution, Downloader, LocalIndex, RemoteDistribution, Unzipper}; | ||
use puffin_interpreter::PythonExecutable; | ||
use puffin_package::package_name::PackageName; | ||
use puffin_resolver::WheelFinder; | ||
use std::future::Future; | ||
use std::path::Path; | ||
use std::pin::Pin; | ||
use tempfile::tempdir; | ||
use tracing::{debug, instrument}; | ||
|
||
#[instrument(skip_all)] | ||
pub async fn resolve_and_install_impl( | ||
venv: &Path, | ||
requirements: &[Requirement], | ||
cache: Option<&Path>, | ||
) -> anyhow::Result<()> { | ||
debug!("Installing {} build requirements", requirements.len()); | ||
|
||
let local_index = if let Some(cache) = cache { | ||
LocalIndex::from_directory(cache).await? | ||
} else { | ||
LocalIndex::default() | ||
}; | ||
let (cached, uncached): (Vec<CachedDistribution>, Vec<Requirement>) = | ||
requirements.iter().partition_map(|requirement| { | ||
let package = PackageName::normalize(&requirement.name); | ||
if let Some(distribution) = local_index | ||
.get(&package) | ||
.filter(|dist| requirement.is_satisfied_by(dist.version())) | ||
{ | ||
Either::Left(distribution.clone()) | ||
} else { | ||
Either::Right(requirement.clone()) | ||
} | ||
}); | ||
|
||
let client = PypiClientBuilder::default().cache(cache).build(); | ||
|
||
let platform = Platform::current()?; | ||
let python = PythonExecutable::from_venv(platform, venv, cache)?; | ||
let tags = Tags::from_env(python.platform(), python.simple_version())?; | ||
let resolution = WheelFinder::new(&tags, &client).resolve(&uncached).await?; | ||
let uncached = resolution | ||
.into_files() | ||
.map(RemoteDistribution::from_file) | ||
.collect::<anyhow::Result<Vec<_>>>()?; | ||
let staging = tempdir()?; | ||
let downloads = Downloader::new(&client, cache) | ||
.download(&uncached, cache.unwrap_or(staging.path())) | ||
.await?; | ||
let unzips = Unzipper::default() | ||
.download(downloads, cache.unwrap_or(staging.path())) | ||
.await | ||
.context("Failed to download and unpack wheels")?; | ||
let wheels = unzips.into_iter().chain(cached).collect::<Vec<_>>(); | ||
puffin_installer::Installer::new(&python).install(&wheels)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn resolve_and_install<'a>( | ||
venv: &'a Path, | ||
requirements: &'a [Requirement], | ||
cache: Option<&'a Path>, | ||
) -> Pin<Box<dyn Future<Output = anyhow::Result<()>> + Send + 'a>> { | ||
resolve_and_install_impl(venv, requirements, cache).boxed() | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.