Skip to content

Commit

Permalink
Merge pull request #159 from sbidoul/warn-wheel-absent-fix
Browse files Browse the repository at this point in the history
Make sure to not use setuptools>=71.
  • Loading branch information
sbidoul committed Aug 17, 2024
2 parents 52e3ee7 + 465094a commit 75813d3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
30 changes: 27 additions & 3 deletions src/pip_deepfreeze/sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ def check_env(python: str) -> bool:
or (
# pip not installed in target python env and local pip is not compatible
# with target python, so we'll need pkg_resources to inspect with
# env-info-json.py
# pip-list-json.py
not pip_version and not local_pip_compatible(python)
)
):
setuptools_install_cmd = shlex.join(
[python, "-m", "pip", "install", "setuptools"]
[python, "-m", "pip", "install", "setuptools<71"]
)
pip_upgrade_cmd = shlex.join(
[python, "-m", "pip", "install", "--upgrade", "pip"]
[python, "-m", "pip", "install", "--upgrade", "pip>=22.2"]
)
log_error(
f"pkg_resources is not available to {python}. It is currently "
Expand All @@ -119,6 +119,30 @@ def check_env(python: str) -> bool:
f"installs pkg_resources with '{setuptools_install_cmd}'."
)
return False
setuptools_version = env_info.get("setuptools_version")
if (
setuptools_version
and Version(setuptools_version) >= Version("71")
and pip_version
and Version(pip_version) < Version("22.2")
):
# In setuptools>=71, pkg_resources.working_set reports setuptools'
# vendored dependencies, so we can't rely on it to inspect the
# environment.
# https://github.com/pypa/setuptools/issues/4516
setuptools_downgrade_cmd = shlex.join(
[python, "-m", "pip", "install", "setuptools<71"]
)
pip_upgrade_cmd = shlex.join(
[python, "-m", "pip", "install", "--upgrade", "pip>=22.2"]
)
log_error(
f"setuptools>=71 has a version of pkg_resources that cannot be "
f"used to reliably inspect the environment. You need to downgrade "
f"setuptools with '{setuptools_downgrade_cmd}' or upgrade pip with "
f"'{pip_upgrade_cmd}'."
)
return False
# Testing for pip must be done after testing for pkg_resources, because
# pkg_resources is needed to obtain the pip version for python < 3.8.
if not pip_version and not local_pip_compatible(python):
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def virtualenv_python(tmp_path, testpkgs):
testpkgs,
"-U",
"pip",
"setuptools",
"setuptools<71", # https://github.com/pypa/setuptools/issues/4516
"wheel",
]
)
Expand Down Expand Up @@ -91,7 +91,7 @@ def testpkgs(tmp_path_factory):
"-m",
"pip",
"wheel",
"setuptools",
"setuptools<71", # https://github.com/pypa/setuptools/issues/4516
"wheel",
"--wheel-dir",
str(testpkgs_dir),
Expand Down
14 changes: 13 additions & 1 deletion tests/test_pip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import subprocess
import sys
import textwrap
from typing import Iterable, Iterator

Expand Down Expand Up @@ -378,7 +379,18 @@ def test_pip_upgrade_vcs_url(


@pytest.mark.parametrize(
"pip_list_function", (_pip_list__env_info_json, _pip_list__pip_inspect, pip_list)
"pip_list_function",
(
pytest.param(
_pip_list__env_info_json,
marks=pytest.mark.skipif(
sys.version_info >= (3, 12),
reason="All pip versions that support Python 3.12 have pip inspect",
),
),
_pip_list__pip_inspect,
pip_list,
),
)
def test_pip_list(virtualenv_python, testpkgs, pip_list_function):
subprocess.check_call(
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ python =
extras = test
usedevelop = true
commands =
pytest -n auto --cov --cov-branch --cov-report=xml --cov-report=html --cov-report=term {posargs}
pytest -vv -n auto --cov --cov-branch --cov-report=xml --cov-report=html --cov-report=term {posargs}

[testenv:py27]
# run only helper scripts tests on python 2
Expand Down

0 comments on commit 75813d3

Please sign in to comment.