Skip to content

Commit b46beb2

Browse files
miss-islingtonKrzysztof Konopko
andauthored
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. (cherry picked from commit 4a3a682) Co-authored-by: Krzysztof Konopko <kkonopko@users.noreply.github.com>
1 parent aa83935 commit b46beb2

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

Lib/ensurepip/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
114114
additional_paths.append(os.path.join(tmpdir, wheel_name))
115115

116116
# Construct the arguments to be passed to the pip command
117-
args = ["install", "--no-index", "--find-links", tmpdir]
117+
args = ["install", "--no-cache-dir", "--no-index", "--find-links", tmpdir]
118118
if root:
119119
args += ["--root", root]
120120
if upgrade:

Lib/test/test_ensurepip.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_basic_bootstrapping(self):
4040

4141
self.run_pip.assert_called_once_with(
4242
[
43-
"install", "--no-index", "--find-links",
43+
"install", "--no-cache-dir", "--no-index", "--find-links",
4444
unittest.mock.ANY, "setuptools", "pip",
4545
],
4646
unittest.mock.ANY,
@@ -54,7 +54,7 @@ def test_bootstrapping_with_root(self):
5454

5555
self.run_pip.assert_called_once_with(
5656
[
57-
"install", "--no-index", "--find-links",
57+
"install", "--no-cache-dir", "--no-index", "--find-links",
5858
unittest.mock.ANY, "--root", "/foo/bar/",
5959
"setuptools", "pip",
6060
],
@@ -66,7 +66,7 @@ def test_bootstrapping_with_user(self):
6666

6767
self.run_pip.assert_called_once_with(
6868
[
69-
"install", "--no-index", "--find-links",
69+
"install", "--no-cache-dir", "--no-index", "--find-links",
7070
unittest.mock.ANY, "--user", "setuptools", "pip",
7171
],
7272
unittest.mock.ANY,
@@ -77,7 +77,7 @@ def test_bootstrapping_with_upgrade(self):
7777

7878
self.run_pip.assert_called_once_with(
7979
[
80-
"install", "--no-index", "--find-links",
80+
"install", "--no-cache-dir", "--no-index", "--find-links",
8181
unittest.mock.ANY, "--upgrade", "setuptools", "pip",
8282
],
8383
unittest.mock.ANY,
@@ -88,7 +88,7 @@ def test_bootstrapping_with_verbosity_1(self):
8888

8989
self.run_pip.assert_called_once_with(
9090
[
91-
"install", "--no-index", "--find-links",
91+
"install", "--no-cache-dir", "--no-index", "--find-links",
9292
unittest.mock.ANY, "-v", "setuptools", "pip",
9393
],
9494
unittest.mock.ANY,
@@ -99,7 +99,7 @@ def test_bootstrapping_with_verbosity_2(self):
9999

100100
self.run_pip.assert_called_once_with(
101101
[
102-
"install", "--no-index", "--find-links",
102+
"install", "--no-cache-dir", "--no-index", "--find-links",
103103
unittest.mock.ANY, "-vv", "setuptools", "pip",
104104
],
105105
unittest.mock.ANY,
@@ -110,7 +110,7 @@ def test_bootstrapping_with_verbosity_3(self):
110110

111111
self.run_pip.assert_called_once_with(
112112
[
113-
"install", "--no-index", "--find-links",
113+
"install", "--no-cache-dir", "--no-index", "--find-links",
114114
unittest.mock.ANY, "-vvv", "setuptools", "pip",
115115
],
116116
unittest.mock.ANY,
@@ -260,7 +260,7 @@ def test_basic_bootstrapping(self):
260260

261261
self.run_pip.assert_called_once_with(
262262
[
263-
"install", "--no-index", "--find-links",
263+
"install", "--no-cache-dir", "--no-index", "--find-links",
264264
unittest.mock.ANY, "setuptools", "pip",
265265
],
266266
unittest.mock.ANY,

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ Vajrasky Kok
860860
Guido Kollerie
861861
Jacek Kołodziej
862862
Jacek Konieczny
863+
Krzysztof Konopko
863864
Arkady Koplyarov
864865
Peter A. Koren
865866
Марк Коренберг
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`ensurepip` now disables the use of `pip` cache when installing the
2+
bundled versions of `pip` and `setuptools`. Patch by Krzysztof Konopko.

0 commit comments

Comments
 (0)