mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
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:
parent
3d5f8249ef
commit
997228f4be
5 changed files with 65 additions and 15 deletions
|
@ -1,17 +1,19 @@
|
||||||
|
use std::env;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use fs_err as fs;
|
use fs_err as fs;
|
||||||
|
|
||||||
use platform_host::Platform;
|
use platform_host::Platform;
|
||||||
use puffin_build::SourceDistributionBuilder;
|
use puffin_build::SourceDistributionBuilder;
|
||||||
use puffin_client::RegistryClientBuilder;
|
use puffin_client::RegistryClientBuilder;
|
||||||
use puffin_dispatch::BuildDispatch;
|
use puffin_dispatch::BuildDispatch;
|
||||||
use puffin_interpreter::Virtualenv;
|
use puffin_interpreter::Virtualenv;
|
||||||
use std::env;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
pub struct BuildArgs {
|
pub(crate) struct BuildArgs {
|
||||||
/// Base python in a way that can be found with `which`
|
/// Base python in a way that can be found with `which`
|
||||||
/// TODO(konstin): Also use proper python parsing here
|
/// TODO(konstin): Also use proper python parsing here
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
|
@ -23,7 +25,7 @@ pub struct BuildArgs {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build a source distribution to a wheel
|
/// 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 {
|
let wheel_dir = if let Some(wheel_dir) = args.wheels {
|
||||||
fs::create_dir_all(&wheel_dir).context("Invalid wheel directory")?;
|
fs::create_dir_all(&wheel_dir).context("Invalid wheel directory")?;
|
||||||
wheel_dir
|
wheel_dir
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
pub use build::{build, BuildArgs};
|
|
||||||
|
|
||||||
mod build;
|
|
|
@ -12,9 +12,13 @@ use tracing_subscriber::layer::SubscriberExt;
|
||||||
use tracing_subscriber::util::SubscriberInitExt;
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
use puffin_dev::{build, BuildArgs};
|
|
||||||
use resolve_many::ResolveManyArgs;
|
use resolve_many::ResolveManyArgs;
|
||||||
|
|
||||||
|
use crate::build::{build, BuildArgs};
|
||||||
|
use crate::resolve_cli::ResolveCliArgs;
|
||||||
|
|
||||||
|
mod build;
|
||||||
|
mod resolve_cli;
|
||||||
mod resolve_many;
|
mod resolve_many;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
@ -28,6 +32,8 @@ enum Cli {
|
||||||
/// cargo run --bin puffin-dev -- resolve-many scripts/resolve/pypi_top_8k_flat.txt
|
/// cargo run --bin puffin-dev -- resolve-many scripts/resolve/pypi_top_8k_flat.txt
|
||||||
/// ```
|
/// ```
|
||||||
ResolveMany(ResolveManyArgs),
|
ResolveMany(ResolveManyArgs),
|
||||||
|
/// Resolve requirements passed on the CLI
|
||||||
|
ResolveCli(ResolveCliArgs),
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run() -> Result<()> {
|
async fn run() -> Result<()> {
|
||||||
|
@ -40,6 +46,9 @@ async fn run() -> Result<()> {
|
||||||
Cli::ResolveMany(args) => {
|
Cli::ResolveMany(args) => {
|
||||||
resolve_many::resolve_many(args).await?;
|
resolve_many::resolve_many(args).await?;
|
||||||
}
|
}
|
||||||
|
Cli::ResolveCli(args) => {
|
||||||
|
resolve_cli::resolve_cli(args).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
40
crates/puffin-dev/src/resolve_cli.rs
Normal file
40
crates/puffin-dev/src/resolve_cli.rs
Normal 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(())
|
||||||
|
}
|
|
@ -1,21 +1,23 @@
|
||||||
|
use std::fs;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::str::FromStr;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use futures::stream::FuturesUnordered;
|
use futures::stream::FuturesUnordered;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use indicatif::ProgressStyle;
|
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 pep508_rs::Requirement;
|
||||||
use platform_host::Platform;
|
use platform_host::Platform;
|
||||||
use puffin_client::RegistryClientBuilder;
|
use puffin_client::RegistryClientBuilder;
|
||||||
use puffin_dispatch::BuildDispatch;
|
use puffin_dispatch::BuildDispatch;
|
||||||
use puffin_interpreter::Virtualenv;
|
use puffin_interpreter::Virtualenv;
|
||||||
use puffin_traits::BuildContext;
|
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)]
|
#[derive(Parser)]
|
||||||
pub(crate) struct ResolveManyArgs {
|
pub(crate) struct ResolveManyArgs {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue