diff --git a/src/lock_file/resolve/pypi.rs b/src/lock_file/resolve/pypi.rs index a35560fe4..d887dbfb7 100644 --- a/src/lock_file/resolve/pypi.rs +++ b/src/lock_file/resolve/pypi.rs @@ -1,14 +1,16 @@ use std::{ + cell::RefCell, collections::HashMap, iter::once, path::{Path, PathBuf}, + rc::Rc, str::FromStr, sync::Arc, }; use distribution_types::{ - BuiltDist, Dist, FileLocation, HashPolicy, InstalledDist, InstalledRegistryDist, Name, - Resolution, ResolvedDist, SourceDist, Verbatim, + BuiltDist, Diagnostic, Dist, FileLocation, HashPolicy, InstalledDist, InstalledRegistryDist, + Name, Resolution, ResolvedDist, SourceDist, Verbatim, }; use indexmap::{IndexMap, IndexSet}; use indicatif::ProgressBar; @@ -373,9 +375,11 @@ pub async fn resolve_pypi( options.exclude_newer, &context.build_options, ); + let package_requests = Rc::new(RefCell::new(Default::default())); let provider = CondaResolverProvider { fallback: fallback_provider, conda_python_identifiers: &conda_python_packages, + package_requests: package_requests.clone(), }; let python_version = PythonVersion::from_str(&interpreter_version.to_string()) @@ -401,8 +405,25 @@ pub async fn resolve_pypi( .into_diagnostic() .context("failed to resolve pypi dependencies")?; + if package_requests.borrow().len() > 0 { + // Print package requests in form of (PackageName, NumRequest) + let package_requests = package_requests + .borrow() + .iter() + .map(|(name, value)| format!("[{name}: {value}]")) + .collect::>() + .join(","); + tracing::info!("overridden uv PyPI package requests [name: amount]: {package_requests}"); + } else { + tracing::info!("no uv PyPI package requests overridden by locked conda dependencies"); + } let resolution = Resolution::from(resolution); + // Print any diagnostics + for diagnostic in resolution.diagnostics() { + tracing::warn!("{}", diagnostic.message()); + } + // Collect resolution into locked packages lock_pypi_packages( conda_python_packages, diff --git a/src/lock_file/resolve/resolver_provider.rs b/src/lock_file/resolve/resolver_provider.rs index 193c305dd..1bdc9d95a 100644 --- a/src/lock_file/resolve/resolver_provider.rs +++ b/src/lock_file/resolve/resolver_provider.rs @@ -1,6 +1,8 @@ use std::{ + cell::RefCell, collections::{BTreeMap, HashMap}, future::ready, + rc::Rc, }; use distribution_filename::SourceDistExtension; @@ -25,6 +27,9 @@ pub(super) struct CondaResolverProvider<'a, Context: BuildContext> { pub(super) fallback: DefaultResolverProvider<'a, Context>, pub(super) conda_python_identifiers: &'a HashMap, + + /// Saves the number of requests by the uv solver per package + pub(super) package_requests: Rc>>, } impl<'a, Context: BuildContext> ResolverProvider for CondaResolverProvider<'a, Context> { @@ -74,10 +79,18 @@ impl<'a, Context: BuildContext> ResolverProvider for CondaResolverProvider<'a, C SourceDistCompatibility::Compatible(HashComparison::Matched), ); + self.package_requests + .borrow_mut() + .entry(package_name.clone()) + .and_modify(|e| *e += 1) + .or_insert(1); + return ready(Ok(VersionsResponse::Found(vec![VersionMap::from( BTreeMap::from_iter([(identifier.version.clone(), prioritized_dist)]), )]))) .right_future(); + + // Record that we got a request for this package so we can track the number of requests } // Otherwise use the default implementation