mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25:00 +00:00

This PR modifies the `install-wheel-rs` (and a few other crates) to get everything playing nicely. Specifically, CI should pass, and all these crates now use workspace dependencies between one another. As part of this change, I split out the wheel name parsing into its own `wheel-filename` crate, and the compatibility tag parsing into its own `platform-tags` crate.
63 lines
1.7 KiB
Rust
63 lines
1.7 KiB
Rust
use std::path::Path;
|
|
use std::str::FromStr;
|
|
|
|
use anyhow::Result;
|
|
use tracing::debug;
|
|
|
|
use platform_host::Platform;
|
|
use platform_tags::Tags;
|
|
use puffin_client::PypiClientBuilder;
|
|
use puffin_interpreter::PythonExecutable;
|
|
|
|
use crate::commands::ExitStatus;
|
|
|
|
/// Resolve a set of requirements into a set of pinned versions.
|
|
pub(crate) async fn compile(src: &Path, cache: Option<&Path>) -> Result<ExitStatus> {
|
|
// Read the `requirements.txt` from disk.
|
|
let requirements_txt = std::fs::read_to_string(src)?;
|
|
|
|
// Parse the `requirements.txt` into a list of requirements.
|
|
let requirements = puffin_package::requirements::Requirements::from_str(&requirements_txt)?;
|
|
|
|
// Detect the current Python interpreter.
|
|
let platform = Platform::current()?;
|
|
let python = PythonExecutable::from_env(&platform)?;
|
|
debug!(
|
|
"Using Python interpreter: {}",
|
|
python.executable().display()
|
|
);
|
|
|
|
// Determine the current environment markers.
|
|
let markers = python.markers();
|
|
|
|
// Determine the compatible platform tags.
|
|
let tags = Tags::from_env(&platform, python.simple_version())?;
|
|
|
|
// Instantiate a client.
|
|
let client = {
|
|
let mut pypi_client = PypiClientBuilder::default();
|
|
if let Some(cache) = cache {
|
|
pypi_client = pypi_client.cache(cache);
|
|
}
|
|
pypi_client.build()
|
|
};
|
|
|
|
// Resolve the dependencies.
|
|
let resolution = puffin_resolver::resolve(
|
|
&requirements,
|
|
markers,
|
|
&tags,
|
|
&client,
|
|
puffin_resolver::Flags::default(),
|
|
)
|
|
.await?;
|
|
|
|
for (name, package) in resolution.iter() {
|
|
#[allow(clippy::print_stdout)]
|
|
{
|
|
println!("{}=={}", name, package.version());
|
|
}
|
|
}
|
|
|
|
Ok(ExitStatus::Success)
|
|
}
|