Skip to content

Commit

Permalink
Apply patch for install_search_all_sources = True (#5895)
Browse files Browse the repository at this point in the history
* Apply patch for install_search_all_sources = True
* patch the patch
* Add news fragment
* add back test of install_search_all_sources
  • Loading branch information
matteius authored Sep 1, 2023
1 parent bf542b1 commit 4cf36f8
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
1 change: 1 addition & 0 deletions news/5895.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Apply patch for install_search_all_sources = True functionality.
8 changes: 6 additions & 2 deletions pipenv/patched/pip/_internal/models/search_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SearchScope:
Encapsulates the locations that pip is configured to search.
"""

__slots__ = ["find_links", "index_urls", "no_index", "index_lookup"]
__slots__ = ["find_links", "index_urls", "no_index", "index_lookup", "index_restricted"]

@classmethod
def create(
Expand All @@ -29,6 +29,7 @@ def create(
index_urls: List[str],
no_index: bool,
index_lookup: Optional[Dict[str, List[str]]] = None,
index_restricted: bool = False,
) -> "SearchScope":
"""
Create a SearchScope object after normalizing the `find_links`.
Expand Down Expand Up @@ -64,6 +65,7 @@ def create(
index_urls=index_urls,
no_index=no_index,
index_lookup=index_lookup,
index_restricted=index_restricted,
)

def __init__(
Expand All @@ -72,11 +74,13 @@ def __init__(
index_urls: List[str],
no_index: bool,
index_lookup: Optional[Dict[str, List[str]]] = None,
index_restricted: bool = False,
) -> None:
self.find_links = find_links
self.index_urls = index_urls
self.no_index = no_index
self.index_lookup = index_lookup if index_lookup else {}
self.index_restricted = index_restricted

def get_formatted_locations(self) -> str:
lines = []
Expand Down Expand Up @@ -136,6 +140,6 @@ def mkurl_pypi_url(url: str) -> str:
index_urls = self.index_urls
if project_name in self.index_lookup:
index_urls = [self.index_lookup[project_name]]
elif self.index_urls:
elif self.index_restricted and self.index_urls:
index_urls = [self.index_urls[0]]
return [mkurl_pypi_url(url) for url in index_urls]
2 changes: 1 addition & 1 deletion pipenv/utils/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ def create(
resolver.skipped[package_name] = dep
resolver.initial_constraints = constraints
resolver.index_lookup = index_lookup
resolver.finder.index_lookup = index_lookup
resolver.markers_lookup = markers_lookup
return resolver

Expand Down Expand Up @@ -340,6 +339,7 @@ def finder(self):
finder = self.package_finder
index_lookup = self.prepare_index_lookup()
finder._link_collector.index_lookup = index_lookup
finder._link_collector.search_scope.index_restricted = True
finder._link_collector.search_scope.index_lookup = index_lookup
return finder

Expand Down
20 changes: 12 additions & 8 deletions tasks/vendoring/patches/patched/pip_index_safety.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/pipenv/patched/pip/_internal/index/collector.py b/pipenv/patched/pip/_internal/index/collector.py
index 0120610c..ead5227e 100644
index b3e293ea3..f27a88725 100644
--- a/pipenv/patched/pip/_internal/index/collector.py
+++ b/pipenv/patched/pip/_internal/index/collector.py
@@ -412,9 +412,11 @@ class LinkCollector:
Expand Down Expand Up @@ -36,7 +36,7 @@ index 0120610c..ead5227e 100644
return link_collector

diff --git a/pipenv/patched/pip/_internal/models/search_scope.py b/pipenv/patched/pip/_internal/models/search_scope.py
index fe61e8116..dab85fbb9 100644
index fe61e8116..98a2cc97f 100644
--- a/pipenv/patched/pip/_internal/models/search_scope.py
+++ b/pipenv/patched/pip/_internal/models/search_scope.py
@@ -3,7 +3,7 @@ import logging
Expand All @@ -53,47 +53,51 @@ index fe61e8116..dab85fbb9 100644
"""

- __slots__ = ["find_links", "index_urls", "no_index"]
+ __slots__ = ["find_links", "index_urls", "no_index", "index_lookup"]
+ __slots__ = ["find_links", "index_urls", "no_index", "index_lookup", "index_restricted"]

@classmethod
def create(
@@ -28,6 +28,7 @@ class SearchScope:
@@ -28,6 +28,8 @@ class SearchScope:
find_links: List[str],
index_urls: List[str],
no_index: bool,
+ index_lookup: Optional[Dict[str, List[str]]] = None,
+ index_restricted: bool = False,
) -> "SearchScope":
"""
Create a SearchScope object after normalizing the `find_links`.
@@ -62,6 +63,7 @@ class SearchScope:
@@ -62,6 +64,8 @@ class SearchScope:
find_links=built_find_links,
index_urls=index_urls,
no_index=no_index,
+ index_lookup=index_lookup,
+ index_restricted=index_restricted,
)

def __init__(
@@ -69,10 +71,12 @@ class SearchScope:
@@ -69,10 +73,14 @@ class SearchScope:
find_links: List[str],
index_urls: List[str],
no_index: bool,
+ index_lookup: Optional[Dict[str, List[str]]] = None,
+ index_restricted: bool = False,
) -> None:
self.find_links = find_links
self.index_urls = index_urls
self.no_index = no_index
+ self.index_lookup = index_lookup if index_lookup else {}
+ self.index_restricted = index_restricted

def get_formatted_locations(self) -> str:
lines = []
@@ -129,4 +133,9 @@ class SearchScope:
@@ -129,4 +137,9 @@ class SearchScope:
loc = loc + "/"
return loc

- return [mkurl_pypi_url(url) for url in self.index_urls]
+ index_urls = self.index_urls
+ if project_name in self.index_lookup:
+ index_urls = [self.index_lookup[project_name]]
+ elif self.index_urls:
+ elif self.index_restricted and self.index_urls:
+ index_urls = [self.index_urls[0]]
+ return [mkurl_pypi_url(url) for url in index_urls]
6 changes: 4 additions & 2 deletions tests/integration/test_install_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def test_install_named_index_alias(pipenv_instance_private_pypi):
@pytest.mark.install
@pytest.mark.needs_internet
@pytest.mark.skipif(sys.version_info >= (3, 12), reason="Package does not work with Python 3.12")
def test_install_specifying_index_url(pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
def test_install_specifying_index_url(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[[source]]
Expand All @@ -153,6 +153,8 @@ def test_install_specifying_index_url(pipenv_instance_pypi):
[dev-packages]
[pipenv]
install_search_all_sources = true
""".strip()
f.write(contents)
c = p.pipenv("install pipenv-test-private-package --index https://test.pypi.org/simple")
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,31 @@ def test_pinned_pipfile_no_null_markers_when_extras(pipenv_instance_pypi):
assert "dataclasses-json" in p.pipfile["packages"]
assert "dataclasses-json" in p.lockfile["default"]
assert p.lockfile["default"]["dataclasses-json"].get("markers", "") is not None

@pytest.mark.index
@pytest.mark.install # private indexes need to be uncached for resolution
@pytest.mark.skip_lock
@pytest.mark.needs_internet
def test_private_index_skip_lock(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"}
[pipenv]
install_search_all_sources = true
""".strip()
f.write(contents)
c = p.pipenv('install --skip-lock')
assert c.returncode == 0

0 comments on commit 4cf36f8

Please sign in to comment.