Add resolve from cli dev command (#272)

I don't want to create a new file for every requirement i test
This commit is contained in:
konsti 2023-11-01 16:46:37 +01:00 committed by GitHub
parent 3d5f8249ef
commit 997228f4be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 15 deletions

View file

@ -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<PathBuf> {
pub(crate) async fn build(args: BuildArgs) -> anyhow::Result<PathBuf> {
let wheel_dir = if let Some(wheel_dir) = args.wheels {
fs::create_dir_all(&wheel_dir).context("Invalid wheel directory")?;
wheel_dir

View file

@ -1,3 +0,0 @@
pub use build::{build, BuildArgs};
mod build;

View file

@ -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(())
}

View file

@ -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<Requirement>,
#[clap(long)]
limit: Option<usize>,
/// Path to the cache directory.
#[arg(global = true, long, env = "PUFFIN_CACHE_DIR")]
cache_dir: Option<PathBuf>,
}
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(())
}

View file

@ -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 {