@@ -102,15 +102,15 @@ def check_env(python: str) -> bool:
102
102
or (
103
103
# pip not installed in target python env and local pip is not compatible
104
104
# with target python, so we'll need pkg_resources to inspect with
105
- # env-info -json.py
105
+ # pip-list -json.py
106
106
not pip_version and not local_pip_compatible (python )
107
107
)
108
108
):
109
109
setuptools_install_cmd = shlex .join (
110
- [python , "-m" , "pip" , "install" , "setuptools" ]
110
+ [python , "-m" , "pip" , "install" , "setuptools<71 " ]
111
111
)
112
112
pip_upgrade_cmd = shlex .join (
113
- [python , "-m" , "pip" , "install" , "--upgrade" , "pip" ]
113
+ [python , "-m" , "pip" , "install" , "--upgrade" , "pip>=22.2 " ]
114
114
)
115
115
log_error (
116
116
f"pkg_resources is not available to { python } . It is currently "
@@ -119,6 +119,30 @@ def check_env(python: str) -> bool:
119
119
f"installs pkg_resources with '{ setuptools_install_cmd } '."
120
120
)
121
121
return False
122
+ setuptools_version = env_info .get ("setuptools_version" )
123
+ if (
124
+ setuptools_version
125
+ and Version (setuptools_version ) >= Version ("71" )
126
+ and pip_version
127
+ and Version (pip_version ) < Version ("22.2" )
128
+ ):
129
+ # In setuptools>=71, pkg_resources.working_set reports setuptools'
130
+ # vendored dependencies, so we can't rely on it to inspect the
131
+ # environment.
132
+ # https://github.com/pypa/setuptools/issues/4516
133
+ setuptools_downgrade_cmd = shlex .join (
134
+ [python , "-m" , "pip" , "install" , "setuptools<71" ]
135
+ )
136
+ pip_upgrade_cmd = shlex .join (
137
+ [python , "-m" , "pip" , "install" , "--upgrade" , "pip>=22.2" ]
138
+ )
139
+ log_error (
140
+ f"setuptools>=71 has a version of pkg_resources that cannot be "
141
+ f"used to reliably inspect the environment. You need to downgrade "
142
+ f"setuptools with '{ setuptools_downgrade_cmd } ' or upgrade pip with "
143
+ f"'{ pip_upgrade_cmd } '."
144
+ )
145
+ return False
122
146
# Testing for pip must be done after testing for pkg_resources, because
123
147
# pkg_resources is needed to obtain the pip version for python < 3.8.
124
148
if not pip_version and not local_pip_compatible (python ):
0 commit comments