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

Canonicalize req name while doing pre-install package search #8054

Merged
merged 6 commits into from
Jul 6, 2020

Conversation

deveshks
Copy link
Contributor

Fixes and closes #5021

Package name should be normalized before we use it to search if it's already installed or not. This will avoid cases like for e.g. pip install fluent.logger running install again, if pip install fluent-logger was already run, by ensuring that fluent.logger is normalized to fluent-logger

@deveshks deveshks force-pushed the correct-package-name-while-install branch from e3b8f54 to 94cdef2 Compare April 15, 2020 15:15
@deveshks
Copy link
Contributor Author

deveshks commented Apr 15, 2020

Hi @uranusjr

I have filed this PR according to your suggestion on the ticket.

Also to write a unit test for this, is it enough to try and install two packages, one with a - and one with a ., and ensuring the second install doesn't go through? Or do we want to test some other variants, or some other commands as well with this?

@uranusjr
Copy link
Member

uranusjr commented Apr 15, 2020

I think you can just write a test to install one package, but pytest.mark.parametrize it to pip install with either dash, underscore, and dot. Those three should have identical output if this works.

@deveshks
Copy link
Contributor Author

I think you can just write a test to install one package, but pytest.mark.parametrize it to pip install with either dash, underscore, and dot. Those three should have identical output if this works.

Thanks, I have parametrized the tests in the latest commit

@deveshks deveshks requested a review from uranusjr April 15, 2020 19:21
@pradyunsg
Copy link
Member

CI isn't particularly happy with this change. :)

@deveshks
Copy link
Contributor Author

CI isn't particularly happy with this change. :)

Yep, I am having some difficulties writing a custom get_distribution, as sometimes the working_set itself increases in size as per #8054 (comment) 😞 . I am trying to work around that.

@deveshks deveshks force-pushed the correct-package-name-while-install branch from 10f0941 to d7a19f8 Compare May 14, 2020 21:51
@deveshks deveshks force-pushed the correct-package-name-while-install branch 2 times, most recently from eb1dcd6 to 5acd20b Compare May 15, 2020 08:36
Copy link
Member

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

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

LGTM, barring the clarification requested by @uranusjr.

@deveshks deveshks force-pushed the correct-package-name-while-install branch from 5acd20b to 2d0f84e Compare May 19, 2020 07:02
@deveshks
Copy link
Contributor Author

A very gentle nudge @uranusjr.

Thanks, I think this is ready to be merged.

Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

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

The difference between search_distribution and get_distribution is a bit too subtle for me, it’d probably be a good idea to change them to something like get_distribution(name) and get_distribution(name, refresh=True) or something similar (I’m terribly at naming arguments, feel free to call the flag something else).

The implementation looks good to me though, so I wouldn’t mind this being kept as-is if others find it easy to read, or do a follow-up refactoring instead.

@deveshks
Copy link
Contributor Author

deveshks commented Jun 1, 2020

The difference between search_distribution and get_distribution is a bit too subtle for me, it’d probably be a good idea to change them to something like get_distribution(name) and get_distribution(name, refresh=True) or something similar (I’m terribly at naming arguments, feel free to call the flag something else).

The implementation looks good to me though, so I wouldn’t mind this being kept as-is if others find it easy to read, or do a follow-up refactoring instead.

I thought of search_distribution to be used for looking up the package in the WorkingSet, and get_distribution to return that looked up package as a distribution.

I agree that we can address this in a follow-up refactoring as well, but I am okay to rename the function as well. I'll wait for @pradyunsg to give his thoughts on this as well, before deciding on either of them.

@deveshks
Copy link
Contributor Author

Given that I can address the follow-up comment by @uranusjr in a separate PR, may I get this PR merged?

@deveshks
Copy link
Contributor Author

Hi @pradyunsg

May I get this PR merged?

@deveshks deveshks force-pushed the correct-package-name-while-install branch 2 times, most recently from 530418d to f675874 Compare June 30, 2020 14:38
@deveshks
Copy link
Contributor Author

Rebased to remove the extra merge commits.

@BrownTruck
Copy link
Contributor

Hello!

I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the master branch into this pull request or rebase this pull request against master then it will be eligible for code review and hopefully merging!

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label Jul 6, 2020
@deveshks deveshks force-pushed the correct-package-name-while-install branch from f675874 to ac624f1 Compare July 6, 2020 08:13
@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label Jul 6, 2020
Copy link
Member

@chrahunt chrahunt left a comment

Choose a reason for hiding this comment

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

One minor comment, otherwise this LGTM

src/pip/_internal/utils/misc.py Show resolved Hide resolved
@deveshks deveshks requested a review from chrahunt July 6, 2020 13:48
@deveshks
Copy link
Contributor Author

deveshks commented Jul 6, 2020

Thanks for the review @chrahunt . I have addressed the comment, and the CI is green now, so this can be merged :)

@chrahunt chrahunt merged commit 334f06e into pypa:master Jul 6, 2020
@deveshks deveshks deleted the correct-package-name-while-install branch July 6, 2020 16:26
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Different pip install behavior depending on usage underscore/dot/dash in package name
6 participants