Skip to content

Commit

Permalink
feat: add some logging for when packages are actually overriden by co…
Browse files Browse the repository at this point in the history
  • Loading branch information
tdejager authored Aug 22, 2024
1 parent 487c0a1 commit 7c5909a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/lock_file/resolve/pypi.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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())
Expand All @@ -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::<Vec<_>>()
.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,
Expand Down
13 changes: 13 additions & 0 deletions src/lock_file/resolve/resolver_provider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::{
cell::RefCell,
collections::{BTreeMap, HashMap},
future::ready,
rc::Rc,
};

use distribution_filename::SourceDistExtension;
Expand All @@ -25,6 +27,9 @@ pub(super) struct CondaResolverProvider<'a, Context: BuildContext> {
pub(super) fallback: DefaultResolverProvider<'a, Context>,
pub(super) conda_python_identifiers:
&'a HashMap<PackageName, (RepoDataRecord, PypiPackageIdentifier)>,

/// Saves the number of requests by the uv solver per package
pub(super) package_requests: Rc<RefCell<HashMap<PackageName, u32>>>,
}

impl<'a, Context: BuildContext> ResolverProvider for CondaResolverProvider<'a, Context> {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7c5909a

Please sign in to comment.