Skip to content

Add back ignore_compatibility option to pip package finder for comprehensive lock file generation #6426

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

Merged
merged 3 commits into from
Jun 26, 2025

Conversation

matteius
Copy link
Member

@matteius matteius commented Jun 26, 2025

The issue

This patch was mistakenly dropped during the last pip vendoring update, which caused #6423

Add ignore_compatibility option to pip package finder for comprehensive lock file generation

Summary

This PR restores and formalizes the ignore_compatibility patch for pip's package finder, enabling Pipenv to include all relevant package hashes in lock files regardless of platform compatibility constraints.

Problem

Currently, pip's package finder filters out packages based on platform compatibility (wheel tags, Python version requirements, etc.), which prevents Pipenv from generating comprehensive lock files that include hashes for all platforms. This creates issues when:

  • Lock files are generated on one platform but used on another
  • Cross-platform deployments require packages for different architectures
  • Complete hash verification is needed for security across all supported platforms

Solution

This patch adds an ignore_compatibility parameter to both LinkEvaluator and PackageFinder classes that:

  1. Bypasses binary format restrictions - Allows wheels even when "binary" is not in accepted formats
  2. Ignores wheel platform tags - Includes wheels regardless of platform compatibility
  3. Skips Python version checks - Includes packages that don't match the current Python version
  4. Handles unsupported wheels gracefully - Prevents crashes when sorting incompatible wheels

Changes

  • Added ignore_compatibility parameter to LinkEvaluator.__init__()
  • Modified evaluate_link() to conditionally skip compatibility checks
  • Updated _sort_key() to handle unsupported wheels without raising exceptions
  • Added ignore_compatibility parameter to PackageFinder.__init__()
  • Created formal patch file for vendoring process

Impact

This enables Pipenv to generate lock files with comprehensive hash coverage across all platforms while maintaining backward compatibility (defaults to False).

Files changed:

  • pipenv/patched/pip/_internal/index/package_finder.py
  • tasks/vendoring/patches/patched/pip_finder_ignore_compatability.patch

The checklist

  • Associated issue
  • A news fragment in the news/ directory to describe this fix with the extension .bugfix.rst, .feature.rst, .behavior.rst, .doc.rst. .vendor.rst. or .trivial.rst (this will appear in the release changelog). Use semantic line breaks and name the file after the issue number or the PR #.

@matteius matteius changed the title Restore the missing ignore compatibility finder patch Add back ignore_compatibility option to pip package finder for comprehensive lock file generation Jun 26, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR restores the lost ignore_compatibility flag in Pipenv’s vendored Pip LinkEvaluator and PackageFinder to allow lock-file generation across all platforms.

  • Adds ignore_compatibility parameter to LinkEvaluator and skips compatibility checks when enabled
  • Extends PackageFinder with the same flag, updates sorting to handle unsupported wheels, and propagates the flag to link evaluation
  • Provides a vendoring patch file and adds a news fragment

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tasks/vendoring/patches/patched/pip_finder_ignore_compatability.patch Vendoring patch adding ignore_compatibility logic
pipenv/patched/pip/_internal/index/package_finder.py Implements ignore_compatibility in evaluator and sorter
news/6426.bugfix.rst News entry for restored compatibility option
Comments suppressed due to low confidence (1)

tasks/vendoring/patches/patched/pip_finder_ignore_compatability.patch:1

  • The filename pip_finder_ignore_compatability.patch has a typo in "compatability". Rename it to pip_finder_ignore_compatibility.patch to prevent vendoring/apply-script failures.
--- a/pipenv/patched/pip/_internal/index/package_finder.py

@@ -135,6 +135,7 @@ def __init__(
target_python: TargetPython,
allow_yanked: bool,
ignore_requires_python: Optional[bool] = None,
ignore_compatibility: Optional[bool] = None,
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

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

[nitpick] For consistency with how ignore_requires_python is handled, initialize ignore_compatibility to False when it's None (e.g., if ignore_compatibility is None: ignore_compatibility = False). This avoids relying on truthiness of None.

Copilot uses AI. Check for mistakes.

@@ -473,7 +476,11 @@ def get_applicable_candidates(

return sorted(filtered_applicable_candidates, key=self._sort_key)
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

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

The new ignore_compatibility parameter on _sort_key is never passed when sorting (sorted(..., key=self._sort_key)), so it always uses the default True. Update the sort call to key=lambda c: self._sort_key(c, self._ignore_compatibility) to honor the instance flag.

Suggested change
return sorted(filtered_applicable_candidates, key=self._sort_key)
return sorted(filtered_applicable_candidates, key=lambda c: self._sort_key(c, self._ignore_compatibility))

Copilot uses AI. Check for mistakes.

@matteius matteius merged commit c3774cc into main Jun 26, 2025
18 of 19 checks passed
@matteius matteius deleted the restore-ignore-compat-finder branch June 26, 2025 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant