Skip to content

Commit 75813d3

Browse files
authored
Merge pull request #159 from sbidoul/warn-wheel-absent-fix
Make sure to not use setuptools>=71.
2 parents 52e3ee7 + 465094a commit 75813d3

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

src/pip_deepfreeze/sanity.py

+27-3
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ def check_env(python: str) -> bool:
102102
or (
103103
# pip not installed in target python env and local pip is not compatible
104104
# with target python, so we'll need pkg_resources to inspect with
105-
# env-info-json.py
105+
# pip-list-json.py
106106
not pip_version and not local_pip_compatible(python)
107107
)
108108
):
109109
setuptools_install_cmd = shlex.join(
110-
[python, "-m", "pip", "install", "setuptools"]
110+
[python, "-m", "pip", "install", "setuptools<71"]
111111
)
112112
pip_upgrade_cmd = shlex.join(
113-
[python, "-m", "pip", "install", "--upgrade", "pip"]
113+
[python, "-m", "pip", "install", "--upgrade", "pip>=22.2"]
114114
)
115115
log_error(
116116
f"pkg_resources is not available to {python}. It is currently "
@@ -119,6 +119,30 @@ def check_env(python: str) -> bool:
119119
f"installs pkg_resources with '{setuptools_install_cmd}'."
120120
)
121121
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
122146
# Testing for pip must be done after testing for pkg_resources, because
123147
# pkg_resources is needed to obtain the pip version for python < 3.8.
124148
if not pip_version and not local_pip_compatible(python):

tests/conftest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def virtualenv_python(tmp_path, testpkgs):
2929
testpkgs,
3030
"-U",
3131
"pip",
32-
"setuptools",
32+
"setuptools<71", # https://github.com/pypa/setuptools/issues/4516
3333
"wheel",
3434
]
3535
)
@@ -91,7 +91,7 @@ def testpkgs(tmp_path_factory):
9191
"-m",
9292
"pip",
9393
"wheel",
94-
"setuptools",
94+
"setuptools<71", # https://github.com/pypa/setuptools/issues/4516
9595
"wheel",
9696
"--wheel-dir",
9797
str(testpkgs_dir),

tests/test_pip.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import subprocess
2+
import sys
23
import textwrap
34
from typing import Iterable, Iterator
45

@@ -378,7 +379,18 @@ def test_pip_upgrade_vcs_url(
378379

379380

380381
@pytest.mark.parametrize(
381-
"pip_list_function", (_pip_list__env_info_json, _pip_list__pip_inspect, pip_list)
382+
"pip_list_function",
383+
(
384+
pytest.param(
385+
_pip_list__env_info_json,
386+
marks=pytest.mark.skipif(
387+
sys.version_info >= (3, 12),
388+
reason="All pip versions that support Python 3.12 have pip inspect",
389+
),
390+
),
391+
_pip_list__pip_inspect,
392+
pip_list,
393+
),
382394
)
383395
def test_pip_list(virtualenv_python, testpkgs, pip_list_function):
384396
subprocess.check_call(

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ python =
1717
extras = test
1818
usedevelop = true
1919
commands =
20-
pytest -n auto --cov --cov-branch --cov-report=xml --cov-report=html --cov-report=term {posargs}
20+
pytest -vv -n auto --cov --cov-branch --cov-report=xml --cov-report=html --cov-report=term {posargs}
2121

2222
[testenv:py27]
2323
# run only helper scripts tests on python 2

0 commit comments

Comments
 (0)