@@ -58,6 +58,38 @@ def _should_use_virtualenv() -> bool:
58
58
)
59
59
60
60
61
+ def _minimum_pip_version () -> str :
62
+ if platform .system () == 'Darwin' and int (platform .mac_ver ()[0 ].split ('.' )[0 ]) >= 11 :
63
+ # macOS 11+ name scheme change requires 20.3. Intel macOS 11.0 can be
64
+ # told to report 10.16 for backwards compatibility; but that also fixes
65
+ # earlier versions of pip so this is only needed for 11+.
66
+ is_apple_silicon_python = platform .machine () != 'x86_64'
67
+ return '21.0.1' if is_apple_silicon_python else '20.3.0'
68
+
69
+ # PEP-517 and manylinux1 was first implemented in 19.1
70
+ return '19.1.0'
71
+
72
+
73
+ def _has_valid_pip (purelib : str ) -> bool :
74
+ """
75
+ Given a path, see if Pip is present and return True if the version is
76
+ sufficient for build, False if it is not.
77
+ """
78
+
79
+ import packaging .version
80
+
81
+ if sys .version_info < (3 , 8 ):
82
+ import importlib_metadata as metadata
83
+ else :
84
+ from importlib import metadata
85
+
86
+ pip_distribution = next (iter (metadata .distributions (name = 'pip' , path = [purelib ])))
87
+
88
+ current_pip_version = packaging .version .Version (pip_distribution .version )
89
+
90
+ return current_pip_version >= packaging .version .Version (_minimum_pip_version ())
91
+
92
+
61
93
def _subprocess (cmd : list [str ]) -> None :
62
94
"""Invoke subprocess and output stdout and stderr if it fails."""
63
95
try :
@@ -203,13 +235,6 @@ def _create_isolated_env_venv(path: str) -> tuple[str, str]:
203
235
"""
204
236
import venv
205
237
206
- import packaging .version
207
-
208
- if sys .version_info < (3 , 8 ):
209
- import importlib_metadata as metadata
210
- else :
211
- from importlib import metadata
212
-
213
238
symlinks = _fs_supports_symlink ()
214
239
try :
215
240
with warnings .catch_warnings ():
@@ -222,20 +247,8 @@ def _create_isolated_env_venv(path: str) -> tuple[str, str]:
222
247
executable , script_dir , purelib = _find_executable_and_scripts (path )
223
248
224
249
# Get the version of pip in the environment
225
- pip_distribution = next (iter (metadata .distributions (name = 'pip' , path = [purelib ])))
226
- current_pip_version = packaging .version .Version (pip_distribution .version )
227
-
228
- if platform .system () == 'Darwin' and int (platform .mac_ver ()[0 ].split ('.' )[0 ]) >= 11 :
229
- # macOS 11+ name scheme change requires 20.3. Intel macOS 11.0 can be told to report 10.16 for backwards
230
- # compatibility; but that also fixes earlier versions of pip so this is only needed for 11+.
231
- is_apple_silicon_python = platform .machine () != 'x86_64'
232
- minimum_pip_version = '21.0.1' if is_apple_silicon_python else '20.3.0'
233
- else :
234
- # PEP-517 and manylinux1 was first implemented in 19.1
235
- minimum_pip_version = '19.1.0'
236
-
237
- if current_pip_version < packaging .version .Version (minimum_pip_version ):
238
- _subprocess ([executable , '-m' , 'pip' , 'install' , f'pip>={ minimum_pip_version } ' ])
250
+ if not _has_valid_pip (purelib ):
251
+ _subprocess ([executable , '-m' , 'pip' , 'install' , f'pip>={ _minimum_pip_version ()} ' ])
239
252
240
253
# Avoid the setuptools from ensurepip to break the isolation
241
254
_subprocess ([executable , '-m' , 'pip' , 'uninstall' , 'setuptools' , '-y' ])
0 commit comments