Skip to content

Fix pip release equality and comparison state - #9590

Open
agammann wants to merge 1 commit into
puppetlabs:mainfrom
agammann:fix/pip-pep440-release-comparison
Open

agammann wants to merge 1 commit into
puppetlabs:mainfrom
agammann:fix/pip-pep440-release-comparison

Conversation

@agammann

Copy link
Copy Markdown

Problem

The pip provider treats installed version 1 as out of sync with ensure => '1.0'. Its version comparator reports 1 < 1.0, although PEP 440 pads shorter release segments with zeroes. Comparing parsed versions of different lengths also appends a sentinel to a version's stored key, so later equality checks can change depending on whether the version was compared earlier.

Change

Normalize trailing zeroes in a copy of the release comparison key, and pad array copies while comparing. The original release spelling remains available for to_s. The pip provider now accepts an already satisfied package without reinstalling it.

Verification

  • On the unmodified base, four focused regression examples failed: release equality, equality-range membership, comparison key stability, and pip provider insync?.
  • On the patch, bundle exec rspec spec/unit/util/package/version/pip_spec.rb spec/unit/util/package/version/range_spec.rb spec/unit/provider/package/pip_spec.rb passed 3,209 examples with no failures on Ruby 3.3.
  • A standalone Ruby reproduction changed from [-1, false, false] to [0, true, true] for comparison, equality, and equality-range membership; comparing parsed versions no longer changes the stored key.
  • ruby -c passed for all three changed Ruby files; git diff --check passed.

RuboCop could not inspect files in this container: the currently resolved RuboCop 1.92.0 and rubocop-rspec 2.31.0 combination aborts while loading rubocop-rspec_rails, before checking source files.

PEP 440 reference: https://peps.python.org/pep-0440/

PEP 440 treats release segments with trailing zeros as equal, but the
pip provider considered 1 and 1.0 different and reinstalled a package
that already met its requested version. Comparison also modified parsed
version keys when their arrays had different lengths.

Normalize a copied release key and pad copies during comparison. Cover
equality, range membership, key stability, and provider convergence.
@agammann
agammann requested a review from a team as a code owner October 17, 2026 04:32
@CLAassistant

CLAassistant commented Oct 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

2 participants