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

[master] Fix the installation of pip modules with special characters in the module name #66989

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

avelin
Copy link

@avelin avelin commented Oct 23, 2024

What does this PR do?

This pull request implements the changes described in #66988 to
make the pip.installed state handle correctly Python modules that
differ in their "user-friendly" PyPI name and the name that is
actually listed in the package metadata (and reported as installed by
the pip tool).

There are three user-visible changes:

  • add the pip.normalize function that implements the normalization
    algorithm descrined in
    PEP 503
  • make the pip.list function normalize the returned package names and
    also normalize the supplied prefix before using it to filter the names
  • make the pip.installed state normalize the user-supplied package names
    before checking whether they are already installed and, later, checking
    whether they have been successfully installed or upgraded

As noted in the issue, this will change the behavior of pip.list;
however, I believe that packages with e.g. dashes in their names are
already handled incorrectly, so this will be an improvement.

There was another pull request (#66880) that attempted to fix
the warning reported by the pip.installed state when handling
package names with dashes; I have since come to believe that the solution
there was incomplete and it would be better to use the PEP 503
normalization algorithm in several places instead.

What issues does this PR fix or reference?

Fixes #66988

Previous Behavior

The pip.installed state is unable to verify the successful installation of some modules.

New Behavior

The pip.installed state finds the modules.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

No

@avelin avelin requested a review from a team as a code owner October 23, 2024 13:28
@salt-project-bot-prod-environment salt-project-bot-prod-environment bot changed the title Fix the installation of pip modules with special characters in the module name [master] Fix the installation of pip modules with special characters in the module name Oct 23, 2024
twangboy
twangboy previously approved these changes Oct 25, 2024
Fix the handling of Python modules with non-standard characters in
either the package name or the name of the installed module.
Passing the module name through the normalize() function
recommended by the Python packaging guidelines allows us to
correctly match them, so that e.g. the consumers do not falsely
report that a package was not installed correctly or needs to
be installed.

NB: this commit CHANGES the dictionary returned by `pip.list`;
the package names will be normalized, so any consumers that look for
specific names MUST also normalize the latter.
Similarly to `pip.list`, normalize package names before
processing them. In this case most of the work is already done -
most functions invoke `_check_package_version_format` and use
the processed package name that it returns. Thus, to use the same
normalization algorithm everywhere, make that function use
`pip.normalize`, too.

This, among other things, deals with some "There was no error
installing package... although it does not show..." warnings when
the package name contains underscores, since now we look for
the correctly normalized name and we can find it.

Fixes saltstack#66988
@ppentchev
Copy link

TBH, I don't think the failing integration tests have much to do with this particular change; I think I saw them fail on the master branch, too.

@twangboy
Copy link
Contributor

If you rebase against 3006.x you'll get this change in sooner... and tests should pass, assuming the bug exists in 3006.

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.

[BUG] pip.installed: handles incorrectly modules with special characters in the name
3 participants