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

Fixed a bug with locking packages with non canonical names #6057

Merged
merged 2 commits into from
Jan 17, 2024

Conversation

mangin
Copy link
Contributor

@mangin mangin commented Jan 5, 2024

The issue

Fix a bug with locking projects that contains packages with non canonical names from private indexes
More details here:
#6056

The checklist

  • [ X] Associated issue
  • [X ] 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 #.
  • [] Send a fix to pip ?

@mangin
Copy link
Contributor Author

mangin commented Jan 5, 2024

From my point of view the patch can't be send to pip.
Because they don't handle mapping between packages and indexes.
They just try to install package from ALL indexes:
https://github.com/pypa/pip/blob/e88d39ae49ab11a8b80609a018e5a36ea4ccad89/src/pip/_internal/models/search_scope.py#L112

@oz123
Copy link
Contributor

oz123 commented Jan 6, 2024

This seems like a legitimate fix, yet ... patching pip is a cause of trouble.
Your patch should be here:

tasks/vendoring/patches/patched

like other pip patches.

If @matteius is OK with this patch I can move it there.

@oz123 oz123 requested a review from matteius January 6, 2024 13:57
@mangin
Copy link
Contributor Author

mangin commented Jan 6, 2024

No problem i would move the fix there.
I would like to finish the job

@oz123
Copy link
Contributor

oz123 commented Jan 6, 2024

Please go a head and move the patch there. You will also need to apply it to check that our vendoring system understands it.

@matteius
Copy link
Member

matteius commented Jan 6, 2024

I am convinced this must be fixable in the code we use from pipenv without patching pip at all. I will try to help look more into this tonight, assuming we don't loose power in this storm.

@matteius
Copy link
Member

matteius commented Jan 6, 2024

Does this have to do with dash vs underscore in the package name? I do think I broke something there when we factored away requirementslib.

@@ -210,14 +212,14 @@ def create(
pipfile_entries[package_name] = pipfile_entry
if isinstance(pipfile_entry, dict):
if packages[package_name].get("index"):
index_lookup[package_name] = packages[package_name].get("index")
index_lookup[canonical_package_name] = packages[package_name].get("index")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's create mapping with canonical package names instead of raw package names

@@ -25,6 +25,7 @@
from pipenv.patched.pip._internal.req.req_install import InstallRequirement
from pipenv.patched.pip._internal.utils.temp_dir import global_tempdir_manager
from pipenv.patched.pip._vendor import pkg_resources, rich
from pipenv.patched.pip._vendor.packaging.utils import canonicalize_name
from pipenv.project import Project
from pipenv.utils.fileutils import create_tracked_tempdir
from pipenv.utils.requirements import normalize_name
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my point of vie we should use canonicalize_name funiction from pip instead of normalize_name function everywhere.
WDYT?

else:
index_lookup[package_name] = project.get_default_index()["name"]
index_lookup[canonical_package_name] = project.get_default_index()["name"]
if install_req.markers:
markers_lookup[package_name] = install_req.markers
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should use everywhere canonical_package_name instead of raw_package_name.
But i didn't start to do it because it would make affect on locking files => i'm a little bit afraid of it.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah you are right, I wish this is something I hadn't broke, but I think your patch makes sense as an iteration in the right direction. I will think more about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we apply my patch?

P.S. I sent it because at my team we have some issues with pipenv. And we can't migrate to the freshest version (we still use pretty old one)

@mangin
Copy link
Contributor Author

mangin commented Jan 8, 2024

@matteius can you please take a look one more time?
This change wouldn't require patching pip.

@mangin mangin force-pushed the bug-locking-uncanonical-packages branch from 62f61be to bc57956 Compare January 12, 2024 10:44
@mangin
Copy link
Contributor Author

mangin commented Jan 12, 2024

Fixed code style... i forgot to set up precommit hook. Sorry.

@mangin
Copy link
Contributor Author

mangin commented Jan 17, 2024

Hey @matteius,
Do we have any timeline about releasing the fix?

@oz123 oz123 merged commit 463d9c8 into pypa:main Jan 17, 2024
19 checks passed
@matteius
Copy link
Member

matteius commented Jan 17, 2024

@mangin I think we will get another 2023 release in (minior or patch) release within the next week and then start looking at our more major 2024 version release after that. At least that's my plan, I have to travel for work next week so if I can get it in before then,. Our goal is to adopt semver going forward.

@matteius
Copy link
Member

@mangin Your patch is in the release from 15 minutes ago -- I hope that it is helpful.

@mangin
Copy link
Contributor Author

mangin commented Jan 22, 2024

Thank you for the release ^_^

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.

3 participants