diff --git a/crates/puffin-dev/src/build.rs b/crates/puffin-dev/src/build.rs index 50041c8d7..d86635f57 100644 --- a/crates/puffin-dev/src/build.rs +++ b/crates/puffin-dev/src/build.rs @@ -1,17 +1,19 @@ +use std::env; +use std::path::PathBuf; + use anyhow::Context; use clap::Parser; use directories::ProjectDirs; use fs_err as fs; + use platform_host::Platform; use puffin_build::SourceDistributionBuilder; use puffin_client::RegistryClientBuilder; use puffin_dispatch::BuildDispatch; use puffin_interpreter::Virtualenv; -use std::env; -use std::path::PathBuf; #[derive(Parser)] -pub struct BuildArgs { +pub(crate) struct BuildArgs { /// Base python in a way that can be found with `which` /// TODO(konstin): Also use proper python parsing here #[clap(short, long)] @@ -23,7 +25,7 @@ pub struct BuildArgs { } /// Build a source distribution to a wheel -pub async fn build(args: BuildArgs) -> anyhow::Result { +pub(crate) async fn build(args: BuildArgs) -> anyhow::Result { let wheel_dir = if let Some(wheel_dir) = args.wheels { fs::create_dir_all(&wheel_dir).context("Invalid wheel directory")?; wheel_dir diff --git a/crates/puffin-dev/src/lib.rs b/crates/puffin-dev/src/lib.rs deleted file mode 100644 index a83e9d7af..000000000 --- a/crates/puffin-dev/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub use build::{build, BuildArgs}; - -mod build; diff --git a/crates/puffin-dev/src/main.rs b/crates/puffin-dev/src/main.rs index 8e7d49044..eb63e7b91 100644 --- a/crates/puffin-dev/src/main.rs +++ b/crates/puffin-dev/src/main.rs @@ -12,9 +12,13 @@ use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::EnvFilter; -use puffin_dev::{build, BuildArgs}; use resolve_many::ResolveManyArgs; +use crate::build::{build, BuildArgs}; +use crate::resolve_cli::ResolveCliArgs; + +mod build; +mod resolve_cli; mod resolve_many; #[derive(Parser)] @@ -28,6 +32,8 @@ enum Cli { /// cargo run --bin puffin-dev -- resolve-many scripts/resolve/pypi_top_8k_flat.txt /// ``` ResolveMany(ResolveManyArgs), + /// Resolve requirements passed on the CLI + ResolveCli(ResolveCliArgs), } async fn run() -> Result<()> { @@ -40,6 +46,9 @@ async fn run() -> Result<()> { Cli::ResolveMany(args) => { resolve_many::resolve_many(args).await?; } + Cli::ResolveCli(args) => { + resolve_cli::resolve_cli(args).await?; + } } Ok(()) } diff --git a/crates/puffin-dev/src/resolve_cli.rs b/crates/puffin-dev/src/resolve_cli.rs new file mode 100644 index 000000000..e74e14311 --- /dev/null +++ b/crates/puffin-dev/src/resolve_cli.rs @@ -0,0 +1,40 @@ +use std::fs; +use std::path::{Path, PathBuf}; + +use clap::Parser; +use directories::ProjectDirs; + +use pep508_rs::Requirement; +use platform_host::Platform; +use puffin_client::RegistryClientBuilder; +use puffin_dispatch::BuildDispatch; +use puffin_interpreter::Virtualenv; +use puffin_traits::BuildContext; + +#[derive(Parser)] +pub(crate) struct ResolveCliArgs { + requirements: Vec, + #[clap(long)] + limit: Option, + /// Path to the cache directory. + #[arg(global = true, long, env = "PUFFIN_CACHE_DIR")] + cache_dir: Option, +} + +pub(crate) async fn resolve_cli(args: ResolveCliArgs) -> anyhow::Result<()> { + let project_dirs = ProjectDirs::from("", "", "puffin"); + let cache = project_dirs.as_ref().map(ProjectDirs::cache_dir); + + let platform = Platform::current()?; + let venv = Virtualenv::from_env(platform, cache)?; + let build_dispatch = BuildDispatch::new( + RegistryClientBuilder::default().cache(cache).build(), + cache.map(Path::to_path_buf), + venv.interpreter_info().clone(), + fs::canonicalize(venv.python_executable())?, + ); + + build_dispatch.resolve(&args.requirements).await?; + + Ok(()) +} diff --git a/crates/puffin-dev/src/resolve_many.rs b/crates/puffin-dev/src/resolve_many.rs index 1c0f3a218..a81ecdfb9 100644 --- a/crates/puffin-dev/src/resolve_many.rs +++ b/crates/puffin-dev/src/resolve_many.rs @@ -1,21 +1,23 @@ +use std::fs; +use std::path::{Path, PathBuf}; +use std::str::FromStr; +use std::sync::Arc; + use clap::Parser; use directories::ProjectDirs; use futures::stream::FuturesUnordered; use futures::StreamExt; use indicatif::ProgressStyle; +use tokio::sync::Semaphore; +use tracing::{info, info_span, span, Level, Span}; +use tracing_indicatif::span_ext::IndicatifSpanExt; + use pep508_rs::Requirement; use platform_host::Platform; use puffin_client::RegistryClientBuilder; use puffin_dispatch::BuildDispatch; use puffin_interpreter::Virtualenv; use puffin_traits::BuildContext; -use std::fs; -use std::path::{Path, PathBuf}; -use std::str::FromStr; -use std::sync::Arc; -use tokio::sync::Semaphore; -use tracing::{info, info_span, span, Level, Span}; -use tracing_indicatif::span_ext::IndicatifSpanExt; #[derive(Parser)] pub(crate) struct ResolveManyArgs {