diff --git a/crates/puffin-cli/src/commands/pip_compile.rs b/crates/puffin-cli/src/commands/pip_compile.rs index d49c0ebc5..54aae4848 100644 --- a/crates/puffin-cli/src/commands/pip_compile.rs +++ b/crates/puffin-cli/src/commands/pip_compile.rs @@ -124,16 +124,14 @@ pub(crate) async fn pip_compile( // Determine the compatible platform tags. let tags = Tags::from_interpreter(venv.interpreter())?; + // Determine the interpreter to use for resolution. + let interpreter = venv.interpreter().clone(); + // Determine the markers to use for resolution. let markers = python_version.map_or_else( || Cow::Borrowed(venv.interpreter().markers()), |python_version| Cow::Owned(python_version.markers(venv.interpreter().markers())), ); - // Inject the fake python version if necessary - let interpreter_info = venv - .interpreter() - .clone() - .patch_markers(markers.clone().into_owned()); // Instantiate a client. let client = RegistryClientBuilder::new(cache.clone()) @@ -143,7 +141,7 @@ pub(crate) async fn pip_compile( let build_dispatch = BuildDispatch::new( client.clone(), cache.clone(), - interpreter_info, + interpreter, fs::canonicalize(venv.python_executable())?, no_build, index_urls, diff --git a/crates/puffin-interpreter/src/interpreter.rs b/crates/puffin-interpreter/src/interpreter.rs index 734f261cd..e17572263 100644 --- a/crates/puffin-interpreter/src/interpreter.rs +++ b/crates/puffin-interpreter/src/interpreter.rs @@ -95,12 +95,6 @@ impl Interpreter { pub fn sys_executable(&self) -> &Path { &self.sys_executable } - - /// Inject markers of a fake python version - #[must_use] - pub fn patch_markers(self, markers: MarkerEnvironment) -> Self { - Self { markers, ..self } - } } #[derive(Debug, Deserialize, Serialize, Clone)] diff --git a/crates/puffin-resolver/src/resolver.rs b/crates/puffin-resolver/src/resolver.rs index 5bea25b2e..13f195833 100644 --- a/crates/puffin-resolver/src/resolver.rs +++ b/crates/puffin-resolver/src/resolver.rs @@ -551,7 +551,8 @@ impl<'a, Context: BuildContext + Send + Sync> Resolver<'a, Context> { metadata, &package_name, self.tags, - self.build_context.interpreter().version(), + self.markers, + self.build_context.interpreter(), self.exclude_newer.as_ref(), ); self.index diff --git a/crates/puffin-resolver/src/version_map.rs b/crates/puffin-resolver/src/version_map.rs index b61a2f785..772f075e7 100644 --- a/crates/puffin-resolver/src/version_map.rs +++ b/crates/puffin-resolver/src/version_map.rs @@ -6,8 +6,9 @@ use chrono::{DateTime, Utc}; use tracing::warn; use distribution_filename::{SourceDistFilename, WheelFilename}; -use pep440_rs::Version; +use pep508_rs::MarkerEnvironment; use platform_tags::{TagPriority, Tags}; +use puffin_interpreter::Interpreter; use puffin_macros::warn_once; use puffin_normalize::PackageName; use pypi_types::{SimpleJson, Yanked}; @@ -25,7 +26,8 @@ impl VersionMap { metadata: SimpleJson, package_name: &PackageName, tags: &Tags, - python_version: &Version, + markers: &MarkerEnvironment, + interpreter: &Interpreter, exclude_newer: Option<&DateTime>, ) -> Self { let mut version_map: BTreeMap = @@ -38,14 +40,17 @@ impl VersionMap { // distributions which give no other indication of their compatibility and wheels which // may be tagged `py3-none-any` but have `requires-python: ">=3.9"`. // TODO(konstin): https://github.com/astral-sh/puffin/issues/406 - if !file - .requires_python - .as_ref() - .map_or(true, |requires_python| { - requires_python.contains(python_version) - }) - { - continue; + if let Some(requires_python) = file.requires_python.as_ref() { + // The interpreter and marker version are often the same, but can differ. For + // example, if the user is resolving against a target Python version passed in + // via the command-line, that version will differ from the interpreter version. + let interpreter_version = interpreter.version(); + let marker_version = &markers.python_version.version; + if !requires_python.contains(interpreter_version) + || !requires_python.contains(marker_version) + { + continue; + } } // Support resolving as if it were an earlier timestamp, at least as long files have