fix(pip): normalize names in list_freeze_parse and detect modern pip …#68784
Open
cdalvaro wants to merge 1 commit intosaltstack:masterfrom
Open
fix(pip): normalize names in list_freeze_parse and detect modern pip …#68784cdalvaro wants to merge 1 commit intosaltstack:masterfrom
cdalvaro wants to merge 1 commit intosaltstack:masterfrom
Conversation
…satisfied message
25fdad8 to
201df65
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Two related bugs in the pip state and module cause a Python package to be "installed" (and reported as changed) on every Salt state run, even when the package is already at the correct version.
Bug 1 —
list_freeze_parsedoes not normalize package namesCommit 68728e6 updated
list_()to return normalized package names (lowercase, hyphens) vianormalize(). However,list_freeze_parse, which is the fallback used for pip < 9.0, was not updated. It still returns names exactly as they appear inpip freezeoutput (e.g."requests_oauthlib"with an underscore).Because
_check_if_installednow receives a normalizedprefix(e.g."requests-oauthlib") and compares it against aCaseInsensitiveDictthat only handles case — not underscore vs. hyphen — the lookup always fails. The package is added totarget_pkgsand pip is called on every run.Bug 2 — Post-install detection uses an outdated pip message
After calling
pip.install, the state checks pip's stdout to determine whether a package was already present, to avoid reporting it as a change.The check was:
Modern pip (≥ 10.0) outputs "Requirement already satisfied: ..." instead.
Because the message never matched,
already_installed_packagesstayed empty and every pip call resulted in the package being reported as "Installed" in the state changes dict.Fix
list_freeze_parsenow computes anormal_prefixand stores each package under its normalized name (normalize(name)), consistent withlist_().re.split, then normalized withpip.normalizebefore being stored inalready_installed_packages. The comparison withprefix(already normalized) no longer calls.lower()unnecessarily.Merge requirements satisfied?
Commits signed with GPG?
Yes