Skip to content

Commit

Permalink
Use a single package
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jan 3, 2024
1 parent ff9374a commit 6a0aa4f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 46 deletions.
10 changes: 6 additions & 4 deletions crates/puffin-cli/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,15 @@ fn compile_numpy_py38() -> Result<()> {
.arg("--no-build")
.env("VIRTUAL_ENV", venv.as_os_str())
.current_dir(&temp_dir), @r###"
success: false
exit_code: 2
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by Puffin v0.0.1 via the following command:
# puffin pip-compile requirements.in --cache-dir [CACHE_DIR]
numpy==1.24.4
----- stderr -----
error: Failed to download and build: numpy==1.26.2
Caused by: Building source distributions is disabled
Resolved 1 package in [TIME]
"###);
});

Expand Down
7 changes: 2 additions & 5 deletions crates/puffin-resolver/src/pubgrub/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,8 @@ fn merge_package(
// Either package is `root`.
(PubGrubPackage::Root(_), _) | (_, PubGrubPackage::Root(_)) => Ok(None),

// Either package is the installed Python.
(PubGrubPackage::InstalledPython, _) | (_, PubGrubPackage::InstalledPython) => Ok(None),

// Either package is the target Python.
(PubGrubPackage::TargetPython, _) | (_, PubGrubPackage::TargetPython) => Ok(None),
// Either package is the Python installation.
(PubGrubPackage::Python, _) | (_, PubGrubPackage::Python) => Ok(None),

// Left package has a URL. Propagate the URL.
(PubGrubPackage::Package(name, extra, Some(url)), PubGrubPackage::Package(.., None)) => {
Expand Down
9 changes: 3 additions & 6 deletions crates/puffin-resolver/src/pubgrub/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ use puffin_normalize::{ExtraName, PackageName};
pub enum PubGrubPackage {
/// The root package, which is used to start the resolution process.
Root(Option<PackageName>),
/// The installed Python version.
InstalledPython,
/// The target Python version.
TargetPython,
/// The current Python version.
Python,
/// A Python package.
Package(
PackageName,
Expand Down Expand Up @@ -86,8 +84,7 @@ impl std::fmt::Display for PubGrubPackage {
write!(f, "root")
}
}
PubGrubPackage::InstalledPython => write!(f, "Python"),
PubGrubPackage::TargetPython => write!(f, "Python"),
PubGrubPackage::Python => write!(f, "Python"),
PubGrubPackage::Package(name, None, ..) => write!(f, "{name}"),
PubGrubPackage::Package(name, Some(extra), ..) => {
write!(f, "{name}[{extra}]")
Expand Down
3 changes: 1 addition & 2 deletions crates/puffin-resolver/src/pubgrub/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ impl PubGrubPriorities {
pub(crate) fn get(&self, package: &PubGrubPackage) -> Option<PubGrubPriority> {
match package {
PubGrubPackage::Root(_) => Some(Reverse(0)),
PubGrubPackage::InstalledPython => Some(Reverse(0)),
PubGrubPackage::TargetPython => Some(Reverse(0)),
PubGrubPackage::Python => Some(Reverse(0)),
PubGrubPackage::Package(name, _, _) => self
.0
.get(name)
Expand Down
45 changes: 16 additions & 29 deletions crates/puffin-resolver/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,7 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
) -> Result<(), ResolveError> {
match package {
PubGrubPackage::Root(_) => {}
PubGrubPackage::InstalledPython => {}
PubGrubPackage::TargetPython => {}
PubGrubPackage::Python => {}
PubGrubPackage::Package(package_name, _extra, None) => {
// Emit a request to fetch the metadata for this package.
if index.packages.register(package_name) {
Expand Down Expand Up @@ -516,24 +515,21 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
return match package {
PubGrubPackage::Root(_) => Ok(Some(MIN_VERSION.clone())),

PubGrubPackage::InstalledPython => {
let interpreter_version = self.interpreter.version();
let version = PubGrubVersion::from(interpreter_version.clone());
if range.contains(&version) {
Ok(Some(version))
} else {
Ok(None)
PubGrubPackage::Python => {
// The version used in the current Python interpreter.
let interpreter_version = PubGrubVersion::from(self.interpreter.version().clone());
if !range.contains(&interpreter_version) {
return Ok(None);
}
}

PubGrubPackage::TargetPython => {
let marker_version = &self.markers.python_version.version;
let version = PubGrubVersion::from(marker_version.clone());
if range.contains(&version) {
Ok(Some(version))
} else {
Ok(None)
// The version against which we're resolving.
let marker_version =
PubGrubVersion::from(self.markers.python_version.version.clone());
if !range.contains(&marker_version) {
return Ok(None);
}

Ok(Some(marker_version))
}

PubGrubPackage::Package(package_name, extra, Some(url)) => {
Expand Down Expand Up @@ -680,13 +676,7 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
Ok(Dependencies::Known(constraints.into()))
}

PubGrubPackage::InstalledPython => {
Ok(Dependencies::Known(DependencyConstraints::default()))
}

PubGrubPackage::TargetPython => {
Ok(Dependencies::Known(DependencyConstraints::default()))
}
PubGrubPackage::Python => Ok(Dependencies::Known(DependencyConstraints::default())),

PubGrubPackage::Package(package_name, extra, url) => {
// Wait for the metadata to be available.
Expand Down Expand Up @@ -722,9 +712,7 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
.fold_ok(Range::full(), |range, specifier| {
range.intersection(&specifier.into())
})?;

constraints.insert(PubGrubPackage::InstalledPython, version.clone());
constraints.insert(PubGrubPackage::TargetPython, version.clone());
constraints.insert(PubGrubPackage::Python, version.clone());
}

// If a package has an extra, insert a constraint on the base package.
Expand Down Expand Up @@ -824,8 +812,7 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
if let Some(reporter) = self.reporter.as_ref() {
match package {
PubGrubPackage::Root(_) => {}
PubGrubPackage::InstalledPython => {}
PubGrubPackage::TargetPython => {}
PubGrubPackage::Python => {}
PubGrubPackage::Package(package_name, _extra, Some(url)) => {
reporter.on_progress(package_name, VersionOrUrl::Url(url));
}
Expand Down

0 comments on commit 6a0aa4f

Please sign in to comment.