2023-11-01 16:46:37 +01:00
|
|
|
use std::fs;
|
|
|
|
|
|
2023-11-13 12:00:12 -08:00
|
|
|
use anstream::println;
|
2023-11-01 16:46:37 +01:00
|
|
|
use clap::Parser;
|
2023-11-01 16:54:47 +01:00
|
|
|
use itertools::Itertools;
|
2023-11-01 16:46:37 +01:00
|
|
|
|
|
|
|
|
use pep508_rs::Requirement;
|
|
|
|
|
use platform_host::Platform;
|
2023-11-16 21:49:48 +01:00
|
|
|
use puffin_cache::{CacheArgs, CacheDir};
|
2023-11-01 16:46:37 +01:00
|
|
|
use puffin_client::RegistryClientBuilder;
|
|
|
|
|
use puffin_dispatch::BuildDispatch;
|
|
|
|
|
use puffin_interpreter::Virtualenv;
|
|
|
|
|
use puffin_traits::BuildContext;
|
|
|
|
|
|
|
|
|
|
#[derive(Parser)]
|
|
|
|
|
pub(crate) struct ResolveCliArgs {
|
|
|
|
|
requirements: Vec<Requirement>,
|
|
|
|
|
#[clap(long)]
|
|
|
|
|
limit: Option<usize>,
|
2023-11-08 16:05:15 +01:00
|
|
|
/// Don't build source distributions. This means resolving will not run arbitrary code. The
|
|
|
|
|
/// cached wheels of already built source distributions will be reused.
|
|
|
|
|
#[clap(long)]
|
|
|
|
|
no_build: bool,
|
2023-11-16 21:49:48 +01:00
|
|
|
#[command(flatten)]
|
|
|
|
|
cache_args: CacheArgs,
|
2023-11-01 16:46:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) async fn resolve_cli(args: ResolveCliArgs) -> anyhow::Result<()> {
|
2023-11-16 21:49:48 +01:00
|
|
|
let cache_dir = CacheDir::try_from(args.cache_args)?;
|
2023-11-01 16:46:37 +01:00
|
|
|
|
|
|
|
|
let platform = Platform::current()?;
|
2023-11-16 21:49:48 +01:00
|
|
|
let venv = Virtualenv::from_env(platform, Some(cache_dir.path()))?;
|
2023-11-01 16:46:37 +01:00
|
|
|
let build_dispatch = BuildDispatch::new(
|
2023-11-16 21:49:48 +01:00
|
|
|
RegistryClientBuilder::new(cache_dir.path().clone()).build(),
|
|
|
|
|
cache_dir.path().clone(),
|
2023-11-01 16:46:37 +01:00
|
|
|
venv.interpreter_info().clone(),
|
|
|
|
|
fs::canonicalize(venv.python_executable())?,
|
2023-11-08 16:05:15 +01:00
|
|
|
args.no_build,
|
2023-11-01 16:46:37 +01:00
|
|
|
);
|
|
|
|
|
|
2023-11-01 16:54:47 +01:00
|
|
|
let mut resolution = build_dispatch.resolve(&args.requirements).await?;
|
|
|
|
|
resolution.sort_unstable_by(|a, b| a.name.cmp(&b.name));
|
2023-11-13 12:00:12 -08:00
|
|
|
|
2023-11-01 16:54:47 +01:00
|
|
|
// Concise format for dev
|
2023-11-13 12:00:12 -08:00
|
|
|
#[allow(clippy::print_stderr, clippy::ignored_unit_patterns)]
|
|
|
|
|
{
|
|
|
|
|
println!("{}", resolution.iter().map(ToString::to_string).join(" "));
|
|
|
|
|
}
|
2023-11-01 16:46:37 +01:00
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|