Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce target and interpreter requires-python versions #532

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions crates/puffin-cli/src/commands/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions crates/puffin-interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Comment on lines -101 to -103
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to see this gone

}

#[derive(Debug, Deserialize, Serialize, Clone)]
Expand Down
3 changes: 2 additions & 1 deletion crates/puffin-resolver/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 15 additions & 10 deletions crates/puffin-resolver/src/version_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -25,7 +26,8 @@ impl VersionMap {
metadata: SimpleJson,
package_name: &PackageName,
tags: &Tags,
python_version: &Version,
markers: &MarkerEnvironment,
interpreter: &Interpreter,
exclude_newer: Option<&DateTime<Utc>>,
) -> Self {
let mut version_map: BTreeMap<PubGrubVersion, PrioritizedDistribution> =
Expand All @@ -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)
Comment on lines +49 to +50
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, but i will make it harder having python as a dependency. I think we need separate python and python$build (or something else that's banned on any index) dependencies. CC @zanieb

{
continue;
}
}

// Support resolving as if it were an earlier timestamp, at least as long files have
Expand Down