From 856a44f8d770396318fa6572acd05311cda0e091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Mon, 29 Jul 2024 19:25:39 +0200 Subject: [PATCH] Make sure to not use setuptools>=71. --- src/pip_deepfreeze/sanity.py | 30 +++++++++++++++++++++++++++--- tests/conftest.py | 4 ++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/pip_deepfreeze/sanity.py b/src/pip_deepfreeze/sanity.py index bdc52cb..3788699 100644 --- a/src/pip_deepfreeze/sanity.py +++ b/src/pip_deepfreeze/sanity.py @@ -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 " @@ -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): diff --git a/tests/conftest.py b/tests/conftest.py index c6e0e78..67d6df7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -29,7 +29,7 @@ def virtualenv_python(tmp_path, testpkgs): testpkgs, "-U", "pip", - "setuptools", + "setuptools<71", # https://github.com/pypa/setuptools/issues/4516 "wheel", ] ) @@ -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),