Skip to content

Commit

Permalink
Make sure to not use setuptools>=71.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Aug 17, 2024
1 parent 52e3ee7 commit 3a75411
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 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",
"wheel",
"--wheel-dir",
str(testpkgs_dir),
Expand Down

0 comments on commit 3a75411

Please sign in to comment.