bpo-40448: ensurepip: Do not use cache (GH-19812)

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.
This commit is contained in:
Krzysztof Konopko 2020-06-15 19:28:46 +02:00 committed by GitHub
parent bf69a8f99f
commit 4a3a682b12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 9 deletions

View File

@ -119,7 +119,7 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
additional_paths.append(os.path.join(tmpdir, wheel_name)) additional_paths.append(os.path.join(tmpdir, wheel_name))
# Construct the arguments to be passed to the pip command # 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: if root:
args += ["--root", root] args += ["--root", root]
if upgrade: if upgrade:

View File

@ -40,7 +40,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
self.run_pip.assert_called_once_with( 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, "setuptools", "pip",
], ],
unittest.mock.ANY, unittest.mock.ANY,
@ -54,7 +54,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
self.run_pip.assert_called_once_with( 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/", unittest.mock.ANY, "--root", "/foo/bar/",
"setuptools", "pip", "setuptools", "pip",
], ],
@ -66,7 +66,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
self.run_pip.assert_called_once_with( 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, "--user", "setuptools", "pip",
], ],
unittest.mock.ANY, unittest.mock.ANY,
@ -77,7 +77,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
self.run_pip.assert_called_once_with( 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, "--upgrade", "setuptools", "pip",
], ],
unittest.mock.ANY, unittest.mock.ANY,
@ -88,7 +88,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
self.run_pip.assert_called_once_with( 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, "-v", "setuptools", "pip",
], ],
unittest.mock.ANY, unittest.mock.ANY,
@ -99,7 +99,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
self.run_pip.assert_called_once_with( 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, "-vv", "setuptools", "pip",
], ],
unittest.mock.ANY, unittest.mock.ANY,
@ -110,7 +110,7 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
self.run_pip.assert_called_once_with( 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, "-vvv", "setuptools", "pip",
], ],
unittest.mock.ANY, unittest.mock.ANY,
@ -260,7 +260,7 @@ class TestBootstrappingMainFunction(EnsurepipMixin, unittest.TestCase):
self.run_pip.assert_called_once_with( 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, "setuptools", "pip",
], ],
unittest.mock.ANY, unittest.mock.ANY,

View File

@ -910,6 +910,7 @@ Vajrasky Kok
Guido Kollerie Guido Kollerie
Jacek Kołodziej Jacek Kołodziej
Jacek Konieczny Jacek Konieczny
Krzysztof Konopko
Arkady Koplyarov Arkady Koplyarov
Peter A. Koren Peter A. Koren
Марк Коренберг Марк Коренберг

View File

@ -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.