mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
Flag to force latest version in resolve-many (#741)
Also fixes color when redirecting puffin-dev to a log file.
This commit is contained in:
parent
35f6ea204b
commit
cd43708369
4 changed files with 62 additions and 7 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2436,6 +2436,7 @@ dependencies = [
|
|||
"install-wheel-rs",
|
||||
"itertools 0.11.0",
|
||||
"mimalloc",
|
||||
"pep440_rs 0.3.12",
|
||||
"pep508_rs",
|
||||
"petgraph",
|
||||
"platform-host",
|
||||
|
|
|
@ -18,6 +18,7 @@ distribution-filename = { path = "../distribution-filename" }
|
|||
distribution-types = { path = "../distribution-types" }
|
||||
gourgeist = { path = "../gourgeist" }
|
||||
install-wheel-rs = { path = "../install-wheel-rs" }
|
||||
pep440_rs = { path = "../pep440-rs" }
|
||||
pep508_rs = { path = "../pep508-rs" }
|
||||
platform-host = { path = "../platform-host" }
|
||||
platform-tags = { path = "../platform-tags" }
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#![allow(clippy::print_stdout, clippy::print_stderr)]
|
||||
|
||||
use std::io::IsTerminal;
|
||||
use std::process::ExitCode;
|
||||
use std::time::Instant;
|
||||
|
||||
|
@ -85,9 +86,14 @@ async fn run() -> Result<()> {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> ExitCode {
|
||||
if !std::io::stderr().is_terminal() {
|
||||
colored::control::set_override(false);
|
||||
}
|
||||
|
||||
let indicatif_layer = IndicatifLayer::new();
|
||||
let indicitif_compatible_writer_layer = tracing_subscriber::fmt::layer()
|
||||
let indicatif_compatible_writer_layer = tracing_subscriber::fmt::layer()
|
||||
.with_writer(indicatif_layer.get_stderr_writer())
|
||||
.with_ansi(std::io::stderr().is_terminal())
|
||||
.with_target(false);
|
||||
let filter_layer = EnvFilter::try_from_default_env().unwrap_or_else(|_| {
|
||||
EnvFilter::builder()
|
||||
|
@ -97,7 +103,7 @@ async fn main() -> ExitCode {
|
|||
});
|
||||
tracing_subscriber::registry()
|
||||
.with(filter_layer)
|
||||
.with(indicitif_compatible_writer_layer)
|
||||
.with(indicatif_compatible_writer_layer)
|
||||
.with(indicatif_layer)
|
||||
.init();
|
||||
|
||||
|
|
|
@ -12,10 +12,11 @@ use tracing::{info, info_span, span, Level, Span};
|
|||
use tracing_indicatif::span_ext::IndicatifSpanExt;
|
||||
|
||||
use distribution_types::IndexUrls;
|
||||
use pep508_rs::Requirement;
|
||||
use pep440_rs::{Version, VersionSpecifier, VersionSpecifiers};
|
||||
use pep508_rs::{Requirement, VersionOrUrl};
|
||||
use platform_host::Platform;
|
||||
use puffin_cache::{Cache, CacheArgs};
|
||||
use puffin_client::RegistryClientBuilder;
|
||||
use puffin_client::{RegistryClient, RegistryClientBuilder};
|
||||
use puffin_dispatch::BuildDispatch;
|
||||
use puffin_interpreter::Virtualenv;
|
||||
use puffin_normalize::PackageName;
|
||||
|
@ -31,13 +32,26 @@ pub(crate) struct ResolveManyArgs {
|
|||
/// cached wheels of already built source distributions will be reused.
|
||||
#[clap(long)]
|
||||
no_build: bool,
|
||||
/// Run this many tasks in parallel
|
||||
/// Run this many tasks in parallel.
|
||||
#[clap(long, default_value = "50")]
|
||||
num_tasks: usize,
|
||||
/// Force the latest version when no version is given.
|
||||
#[clap(long)]
|
||||
latest_version: bool,
|
||||
#[command(flatten)]
|
||||
cache_args: CacheArgs,
|
||||
}
|
||||
|
||||
/// Try to find the latest version of a package, ignoring error because we report them during resolution properly
|
||||
async fn find_latest_version(
|
||||
client: RegistryClient,
|
||||
package_name: &PackageName,
|
||||
) -> Option<Version> {
|
||||
let (_, _, simple_metadata) = client.simple(package_name).await.ok()?;
|
||||
let (version, _) = simple_metadata.into_iter().next()?;
|
||||
Some(version.clone())
|
||||
}
|
||||
|
||||
pub(crate) async fn resolve_many(args: ResolveManyArgs) -> Result<()> {
|
||||
let cache = Cache::try_from(args.cache_args)?;
|
||||
|
||||
|
@ -76,14 +90,35 @@ pub(crate) async fn resolve_many(args: ResolveManyArgs) -> Result<()> {
|
|||
header_span.pb_set_length(total as u64);
|
||||
let _header_span_enter = header_span.enter();
|
||||
|
||||
let client = RegistryClientBuilder::new(cache.clone()).build();
|
||||
|
||||
let mut tasks = futures::stream::iter(requirements)
|
||||
.map(|requirement| {
|
||||
let build_dispatch = build_dispatch.clone();
|
||||
let client = client.clone();
|
||||
async move {
|
||||
let span = span!(Level::TRACE, "fetching");
|
||||
let _enter = span.enter();
|
||||
let start = Instant::now();
|
||||
|
||||
let requirement = if args.latest_version && requirement.version_or_url.is_none() {
|
||||
if let Some(version) = find_latest_version(client, &requirement.name).await {
|
||||
let equals_version = VersionOrUrl::VersionSpecifier(
|
||||
VersionSpecifiers::from(VersionSpecifier::equals_version(version)),
|
||||
);
|
||||
Requirement {
|
||||
name: requirement.name,
|
||||
extras: requirement.extras,
|
||||
version_or_url: Some(equals_version),
|
||||
marker: None,
|
||||
}
|
||||
} else {
|
||||
requirement
|
||||
}
|
||||
} else {
|
||||
requirement
|
||||
};
|
||||
|
||||
let result = build_dispatch.resolve(&[requirement.clone()]).await;
|
||||
|
||||
(requirement.to_string(), start.elapsed(), result)
|
||||
|
@ -107,13 +142,25 @@ pub(crate) async fn resolve_many(args: ResolveManyArgs) -> Result<()> {
|
|||
success += 1;
|
||||
}
|
||||
Err(err) => {
|
||||
let err_formatted =
|
||||
if err
|
||||
.source()
|
||||
.and_then(|err| err.source())
|
||||
.is_some_and(|err| {
|
||||
err.to_string() == "Building source distributions is disabled"
|
||||
})
|
||||
{
|
||||
"Building source distributions is disabled".to_string()
|
||||
} else {
|
||||
format!("{err:?}")
|
||||
};
|
||||
info!(
|
||||
"Error for {} ({}/{}, {} ms):: {:?}",
|
||||
"Error for {} ({}/{}, {} ms): {}",
|
||||
package,
|
||||
success + errors.len(),
|
||||
total,
|
||||
duration.as_millis(),
|
||||
err,
|
||||
err_formatted
|
||||
);
|
||||
errors.push(package);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue