Start puffin-dev (#193)

Currently, this is only the source distribution building feature moved.
It's intended that we can add development and test commands there
without affecting the main cli surface
This commit is contained in:
konsti 2023-10-26 11:17:22 +02:00 committed by GitHub
parent 862c1654a0
commit 216b6c41c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 93 additions and 71 deletions

54
Cargo.lock generated
View file

@ -2037,33 +2037,6 @@ dependencies = [
"zip", "zip",
] ]
[[package]]
name = "puffin-build-cli"
version = "0.0.1"
dependencies = [
"anyhow",
"clap",
"colored",
"directories",
"fs-err",
"futures",
"gourgeist",
"itertools",
"pep508_rs",
"platform-host",
"platform-tags",
"puffin-build",
"puffin-client",
"puffin-dispatch",
"puffin-interpreter",
"puffin-package",
"tempfile",
"tokio",
"tracing",
"tracing-subscriber",
"which",
]
[[package]] [[package]]
name = "puffin-cli" name = "puffin-cli"
version = "0.0.1" version = "0.0.1"
@ -2128,6 +2101,33 @@ dependencies = [
"url", "url",
] ]
[[package]]
name = "puffin-dev"
version = "0.0.1"
dependencies = [
"anyhow",
"clap",
"colored",
"directories",
"fs-err",
"futures",
"gourgeist",
"itertools",
"pep508_rs",
"platform-host",
"platform-tags",
"puffin-build",
"puffin-client",
"puffin-dispatch",
"puffin-interpreter",
"puffin-package",
"tempfile",
"tokio",
"tracing",
"tracing-subscriber",
"which",
]
[[package]] [[package]]
name = "puffin-dispatch" name = "puffin-dispatch"
version = "0.1.0" version = "0.1.0"

View file

@ -1,5 +1,5 @@
[package] [package]
name = "puffin-build-cli" name = "puffin-dev"
version = "0.0.1" version = "0.0.1"
description = "Build wheels from source distributions" description = "Build wheels from source distributions"
edition = { workspace = true } edition = { workspace = true }

View file

@ -1,29 +1,17 @@
#![allow(clippy::print_stdout, clippy::print_stderr)] use anyhow::Context;
use std::env;
use std::path::PathBuf;
use std::process::ExitCode;
use std::time::Instant;
use anyhow::{Context, Result};
use clap::Parser; use clap::Parser;
use colored::Colorize;
use directories::ProjectDirs; use directories::ProjectDirs;
use fs_err as fs; use fs_err as fs;
use tracing::debug;
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{fmt, EnvFilter};
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)]
struct Args { pub 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)]
@ -34,8 +22,8 @@ struct Args {
sdist: PathBuf, sdist: PathBuf,
} }
async fn run() -> Result<()> { /// Build a source distribution to a wheel
let args = Args::parse(); pub 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
@ -61,27 +49,5 @@ async fn run() -> Result<()> {
SourceDistributionBuilder::setup(&args.sdist, venv.interpreter_info(), &build_dispatch) SourceDistributionBuilder::setup(&args.sdist, venv.interpreter_info(), &build_dispatch)
.await?; .await?;
let wheel = builder.build(&wheel_dir)?; let wheel = builder.build(&wheel_dir)?;
println!("Wheel built to {}", wheel_dir.join(wheel).display()); Ok(wheel_dir.join(wheel))
Ok(())
}
#[tokio::main]
async fn main() -> ExitCode {
tracing_subscriber::registry()
.with(fmt::layer().with_span_events(FmtSpan::CLOSE))
.with(EnvFilter::from_default_env())
.init();
let start = Instant::now();
let result = run().await;
debug!("Took {}ms", start.elapsed().as_millis());
if let Err(err) = result {
eprintln!("{}", "puffin-build failed".red().bold());
for err in err.chain() {
eprintln!(" {}: {}", "Caused by".red().bold(), err);
}
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
}
} }

View file

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

View file

@ -0,0 +1,53 @@
#![allow(clippy::print_stdout, clippy::print_stderr)]
use std::process::ExitCode;
use std::time::Instant;
use anyhow::Result;
use clap::Parser;
use colored::Colorize;
use tracing::debug;
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{fmt, EnvFilter};
use puffin_dev::{build, BuildArgs};
#[derive(Parser)]
enum Cli {
/// Build a source distribution into a wheel
Build(BuildArgs),
}
async fn run() -> Result<()> {
let cli = Cli::parse();
match cli {
Cli::Build(args) => {
let target = build(args).await?;
println!("Wheel built to {}", target.display());
}
}
Ok(())
}
#[tokio::main]
async fn main() -> ExitCode {
tracing_subscriber::registry()
.with(fmt::layer().with_span_events(FmtSpan::CLOSE))
.with(EnvFilter::from_default_env())
.init();
let start = Instant::now();
let result = run().await;
debug!("Took {}ms", start.elapsed().as_millis());
if let Err(err) = result {
eprintln!("{}", "puffin-dev failed".red().bold());
for err in err.chain() {
eprintln!(" {}: {}", "Caused by".red().bold(), err);
}
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
}
}

View file

@ -12,8 +12,8 @@ if [ ! -f sdist_building_test_data/sdist/geoextract-0.3.1.tar.gz ]; then
wget https://files.pythonhosted.org/packages/c4/00/9d9826a6e1c9139cc7183647f47f6b7acb290fa4c572140aa84a12728e60/geoextract-0.3.1.tar.gz -O sdist_building_test_data/sdist/geoextract-0.3.1.tar.gz wget https://files.pythonhosted.org/packages/c4/00/9d9826a6e1c9139cc7183647f47f6b7acb290fa4c572140aa84a12728e60/geoextract-0.3.1.tar.gz -O sdist_building_test_data/sdist/geoextract-0.3.1.tar.gz
fi fi
rm -rf sdist_building_test_data/wheels rm -rf sdist_building_test_data/wheels
RUST_LOG=puffin_build=debug cargo run -p puffin-build-cli --bin puffin-build-cli -- --wheels sdist_building_test_data/wheels sdist_building_test_data/sdist/tqdm-4.66.1.tar.gz RUST_LOG=puffin_build=debug cargo run --bin puffin-dev -- build --wheels sdist_building_test_data/wheels sdist_building_test_data/sdist/tqdm-4.66.1.tar.gz
RUST_LOG=puffin_build=debug cargo run -p puffin-build-cli --bin puffin-build-cli -- --wheels sdist_building_test_data/wheels sdist_building_test_data/sdist/geoextract-0.3.1.tar.gz RUST_LOG=puffin_build=debug cargo run --bin puffin-dev -- build --wheels sdist_building_test_data/wheels sdist_building_test_data/sdist/geoextract-0.3.1.tar.gz
# Check that pip accepts the wheels. It would be better to do functional checks # Check that pip accepts the wheels. It would be better to do functional checks
virtualenv -p 3.8 -q --clear sdist_building_test_data/.venv virtualenv -p 3.8 -q --clear sdist_building_test_data/.venv