From 9766c738eca7bb9d76a7096c34d575d9c9274c08 Mon Sep 17 00:00:00 2001 From: Krzysztof Konopko Date: Thu, 30 Apr 2020 10:45:05 +0200 Subject: [PATCH 1/3] bpo-40448: ensurepip: Do not use cache ensurepip optionally installs or upgrades 'pip' and 'setuptools' using the version of those modules bundled with Python. The internal PIP installation routine by default temporarily uses its cache, if it exists. This is undesirable as Python builds and installations may be independent of the user running the build, whilst PIP cache location is dependent on the user's environment and outside of the build environment. At the same time, there's no value in using the cache while installing bundled modules. This change disables PIP caching when used in ensurepip. --- Lib/ensurepip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py index 545fce656fd6f5..d62b1187f90d60 100644 --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -119,7 +119,7 @@ def _bootstrap(*, root=None, upgrade=False, user=False, additional_paths.append(os.path.join(tmpdir, wheel_name)) # Construct the arguments to be passed to the pip command - args = ["install", "--no-index", "--find-links", tmpdir] + args = ["install", "--no-cache-dir", "--no-index", "--find-links", tmpdir] if root: args += ["--root", root] if upgrade: From fd658640a196382f54d00371e69e571f49f50ffa Mon Sep 17 00:00:00 2001 From: Krzysztof Konopko Date: Thu, 30 Apr 2020 11:58:50 +0200 Subject: [PATCH 2/3] fixup! bpo-40448: ensurepip: Do not use cache --- Lib/test/test_ensurepip.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_ensurepip.py b/Lib/test/test_ensurepip.py index 89966893092851..4786d28f39a3d0 100644 --- a/Lib/test/test_ensurepip.py +++ b/Lib/test/test_ensurepip.py @@ -40,7 +40,7 @@ def test_basic_bootstrapping(self): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "setuptools", "pip", ], unittest.mock.ANY, @@ -54,7 +54,7 @@ def test_bootstrapping_with_root(self): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "--root", "/foo/bar/", "setuptools", "pip", ], @@ -66,7 +66,7 @@ def test_bootstrapping_with_user(self): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "--user", "setuptools", "pip", ], unittest.mock.ANY, @@ -77,7 +77,7 @@ def test_bootstrapping_with_upgrade(self): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "--upgrade", "setuptools", "pip", ], unittest.mock.ANY, @@ -88,7 +88,7 @@ def test_bootstrapping_with_verbosity_1(self): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "-v", "setuptools", "pip", ], unittest.mock.ANY, @@ -99,7 +99,7 @@ def test_bootstrapping_with_verbosity_2(self): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "-vv", "setuptools", "pip", ], unittest.mock.ANY, @@ -110,7 +110,7 @@ def test_bootstrapping_with_verbosity_3(self): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "-vvv", "setuptools", "pip", ], unittest.mock.ANY, @@ -260,7 +260,7 @@ def test_basic_bootstrapping(self): self.run_pip.assert_called_once_with( [ - "install", "--no-index", "--find-links", + "install", "--no-cache-dir", "--no-index", "--find-links", unittest.mock.ANY, "setuptools", "pip", ], unittest.mock.ANY, From 81e22301e1ca023fcd650702a87d3a371cec887f Mon Sep 17 00:00:00 2001 From: Ned Deily Date: Mon, 15 Jun 2020 12:29:47 -0400 Subject: [PATCH 3/3] Add NEWS and ACKS entries. --- Misc/ACKS | 1 + .../next/Library/2020-06-15-12-22-53.bpo-40448.1dk8Bu.rst | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2020-06-15-12-22-53.bpo-40448.1dk8Bu.rst diff --git a/Misc/ACKS b/Misc/ACKS index 21822dd7524cfa..9712217a310173 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -907,6 +907,7 @@ Vajrasky Kok Guido Kollerie Jacek Kołodziej Jacek Konieczny +Krzysztof Konopko Arkady Koplyarov Peter A. Koren Марк Коренберг diff --git a/Misc/NEWS.d/next/Library/2020-06-15-12-22-53.bpo-40448.1dk8Bu.rst b/Misc/NEWS.d/next/Library/2020-06-15-12-22-53.bpo-40448.1dk8Bu.rst new file mode 100644 index 00000000000000..a755c5faa671c3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-15-12-22-53.bpo-40448.1dk8Bu.rst @@ -0,0 +1,2 @@ +:mod:`ensurepip` now disables the use of `pip` cache when installing the +bundled versions of `pip` and `setuptools`. Patch by Krzysztof Konopko.