From b99e082b003788f2e8abbad47d461f495faad892 Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Sat, 1 Jul 2023 14:42:10 +0100
Subject: [PATCH 1/4] Record download of completed partial requirements
---
src/pip/_internal/operations/prepare.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py
index 130b9737742..8d7151353f0 100644
--- a/src/pip/_internal/operations/prepare.py
+++ b/src/pip/_internal/operations/prepare.py
@@ -471,6 +471,7 @@ def _complete_partial_requirements(
logger.debug("Downloading link %s to %s", link, filepath)
req = links_to_fully_download[link]
req.local_file_path = filepath
+ self._downloaded[req.link.url] = filepath
# This step is necessary to ensure all lazy wheels are processed
# successfully by the 'download', 'wheel', and 'install' commands.
From cb25bf3731d46697586fc72a24ba1f8e57311377 Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Sat, 1 Jul 2023 14:51:10 +0100
Subject: [PATCH 2/4] Add a news file
---
news/11847.bugfix.rst | 1 +
1 file changed, 1 insertion(+)
create mode 100644 news/11847.bugfix.rst
diff --git a/news/11847.bugfix.rst b/news/11847.bugfix.rst
new file mode 100644
index 00000000000..1cad477eaa2
--- /dev/null
+++ b/news/11847.bugfix.rst
@@ -0,0 +1 @@
+Prevent downloading files twice when PEP 658 metadata is present
From 647ba8d07e7832ea69d93f9a686d8f276e669a14 Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Mon, 3 Jul 2023 10:35:01 +0100
Subject: [PATCH 3/4] Limit the double download fix to wheels
---
src/pip/_internal/operations/prepare.py | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py
index 8d7151353f0..5d9bedc031a 100644
--- a/src/pip/_internal/operations/prepare.py
+++ b/src/pip/_internal/operations/prepare.py
@@ -471,7 +471,19 @@ def _complete_partial_requirements(
logger.debug("Downloading link %s to %s", link, filepath)
req = links_to_fully_download[link]
req.local_file_path = filepath
- self._downloaded[req.link.url] = filepath
+ # TODO: This needs fixing for sdists
+ # This is an emergency fix for #11847, which reports that
+ # distributions get downloaded twice when metadata is loaded
+ # from a PEP 658 standalone metadata file. Setting _downloaded
+ # fixes this for wheels, but breaks the sdist case (tests
+ # test_download_metadata). As PyPI is currently not serving
+ # metadata for wheels, this is not an immediate issue.
+ # Fixing the problem properly looks like it will require a
+ # complete refactoring of the `prepare_linked_requirements_more`
+ # logic, and I haven't a clue where to start on that, so for now
+ # I have fixed the issue *just* for wheels.
+ if req.is_wheel:
+ self._downloaded[req.link.url] = filepath
# This step is necessary to ensure all lazy wheels are processed
# successfully by the 'download', 'wheel', and 'install' commands.
From 8e80a3ad9a5b80de72efad6cbad3bebf2328642b Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Mon, 3 Jul 2023 10:45:01 +0100
Subject: [PATCH 4/4] Fix typo
---
src/pip/_internal/operations/prepare.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py
index 5d9bedc031a..49d86268a3b 100644
--- a/src/pip/_internal/operations/prepare.py
+++ b/src/pip/_internal/operations/prepare.py
@@ -476,7 +476,7 @@ def _complete_partial_requirements(
# distributions get downloaded twice when metadata is loaded
# from a PEP 658 standalone metadata file. Setting _downloaded
# fixes this for wheels, but breaks the sdist case (tests
- # test_download_metadata). As PyPI is currently not serving
+ # test_download_metadata). As PyPI is currently only serving
# metadata for wheels, this is not an immediate issue.
# Fixing the problem properly looks like it will require a
# complete refactoring of the `prepare_linked_requirements_more`