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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/6056.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug with locking projects that contains packages with non canonical names from private indexes
20 changes: 15 additions & 5 deletions pipenv/utils/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -200,6 +201,7 @@ def create(
for package_name, dep in deps.items(): # Build up the index and markers lookups
if not dep:
continue
canonical_package_name = canonicalize_name(package_name)
is_constraint = True
install_req, _ = expansive_install_req_from_line(dep, expand_env=True)
original_deps[package_name] = dep
Expand All @@ -210,14 +212,18 @@ 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"
)
if packages[package_name].get("skip_resolver"):
is_constraint = False
skipped[package_name] = dep
elif index:
index_lookup[package_name] = index
index_lookup[canonical_package_name] = index
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)

if is_constraint:
Expand Down Expand Up @@ -546,9 +552,13 @@ def collect_hashes(self, ireq):
return set()

sources = self.sources # Enforce index restrictions
if ireq.name in self.index_lookup:
canonical_ireq_name = canonicalize_name(ireq.name)
if canonical_ireq_name in self.index_lookup:
sources = list(
filter(lambda s: s.get("name") == self.index_lookup[ireq.name], sources)
filter(
lambda s: s.get("name") == self.index_lookup[canonical_ireq_name],
sources,
)
)
source = sources[0] if len(sources) else None
if source:
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,33 @@ def test_private_index_lock_requirements(pipenv_instance_private_pypi):
assert c.returncode == 0


@pytest.mark.lock
@pytest.mark.index
@pytest.mark.install # private indexes need to be uncached for resolution
@pytest.mark.requirements
@pytest.mark.needs_internet
def test_private_index_lock_requirements_for_not_canonical_package(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, 'w') as f:
contents = """
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[[source]]
url = "https://test.pypi.org/simple"
verify_ssl = true
name = "testpypi"

[packages]
pipenv_test_private_package = {version = "*", index = "testpypi"}
""".strip()
f.write(contents)
c = p.pipenv('lock')
assert c.returncode == 0


@pytest.mark.index
@pytest.mark.install
def test_lock_updated_source(pipenv_instance_private_pypi):
Expand Down