summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2023-04-19 17:18:27 +0100
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2023-04-19 17:18:27 +0100
commitac07f21af8ee73e32448bb0429469b56f412a597 (patch)
treec45e8284ca8668b8aa594deed813145adc1264b8
parent245d72a8aa4d47e1811425213aba2a06a0bb64fa (diff)
downloadpython-setuptools-git-ac07f21af8ee73e32448bb0429469b56f412a597.tar.gz
Handle Python3.12a7 compatibility problems
-rw-r--r--pkg_resources/__init__.py3
-rw-r--r--pkg_resources/tests/test_pkg_resources.py8
-rw-r--r--pkg_resources/tests/test_resources.py4
-rw-r--r--pytest.ini3
-rw-r--r--setuptools/_py312compat.py11
-rw-r--r--setuptools/command/easy_install.py11
6 files changed, 35 insertions, 5 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index a73a1df3..8159afd2 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -3046,6 +3046,9 @@ class Distribution:
except ValueError:
issue_warning("Unbuilt egg for " + repr(self))
return False
+ except SystemError:
+ # TODO: remove this except clause when python/cpython#103632 is fixed.
+ return False
return True
def clone(self, **kw):
diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py
index 684c9777..fd5cc8ce 100644
--- a/pkg_resources/tests/test_pkg_resources.py
+++ b/pkg_resources/tests/test_pkg_resources.py
@@ -256,6 +256,10 @@ def make_distribution_no_version(tmpdir, basename):
('dist-info', 'METADATA', DistInfoDistribution),
],
)
+@pytest.mark.xfail(
+ sys.version_info[:2] == (3, 12) and sys.version_info.releaselevel != 'final',
+ reason="https://github.com/python/cpython/issues/103632",
+)
def test_distribution_version_missing(
tmpdir, suffix, expected_filename, expected_dist_type):
"""
@@ -286,6 +290,10 @@ def test_distribution_version_missing(
assert type(dist) == expected_dist_type
+@pytest.mark.xfail(
+ sys.version_info[:2] == (3, 12) and sys.version_info.releaselevel != 'final',
+ reason="https://github.com/python/cpython/issues/103632",
+)
def test_distribution_version_missing_undetected_path():
"""
Test Distribution.version when the "Version" header is missing and
diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py
index 2138f95e..baf477db 100644
--- a/pkg_resources/tests/test_resources.py
+++ b/pkg_resources/tests/test_resources.py
@@ -319,6 +319,10 @@ class TestDistro:
res = list(ws.resolve(parse_requirements("a"), ad))
assert res == [a, c, b, foo]
+ @pytest.mark.xfail(
+ sys.version_info[:2] == (3, 12) and sys.version_info.releaselevel != 'final',
+ reason="https://github.com/python/cpython/issues/103632",
+ )
def testDistroDependsOptions(self):
d = self.distRequires("""
Twisted>=1.5
diff --git a/pytest.ini b/pytest.ini
index 016f1181..9131822b 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -36,6 +36,9 @@ filterwarnings=
# python/cpython#100750
ignore:'encoding' argument not specified::platform
+ # Dependencies might not have been updated yet
+ default:onerror argument is deprecated, use onexc instead
+
## end upstream
# https://github.com/pypa/setuptools/issues/1823
diff --git a/setuptools/_py312compat.py b/setuptools/_py312compat.py
new file mode 100644
index 00000000..a17d5aec
--- /dev/null
+++ b/setuptools/_py312compat.py
@@ -0,0 +1,11 @@
+import sys
+import shutil
+
+def shutil_rmtree(path, ignore_errors=False, onexc=None):
+ if sys.version_info >= (3, 12):
+ return shutil.rmtree(path, ignore_errors, onexc=onexc)
+
+ def _handler(fn, path, excinfo):
+ onexc(fn, path, excinfo[1])
+
+ return shutil.rmtree(path, ignore_errors, onerror=_handler)
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index 444d3b33..bf6c964e 100644
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -62,6 +62,7 @@ from pkg_resources import (
VersionConflict, DEVELOP_DIST,
)
import pkg_resources
+from .. import _py312compat
from .._path import ensure_directory
from ..extern.jaraco.text import yield_lines
@@ -202,7 +203,7 @@ class easy_install(Command):
return
is_tree = os.path.isdir(path) and not os.path.islink(path)
- remover = rmtree if is_tree else os.unlink
+ remover = _rmtree if is_tree else os.unlink
remover(path)
@staticmethod
@@ -645,7 +646,7 @@ class easy_install(Command):
# cast to str as workaround for #709 and #710 and #712
yield str(tmpdir)
finally:
- os.path.exists(tmpdir) and rmtree(tmpdir)
+ os.path.exists(tmpdir) and _rmtree(tmpdir)
def easy_install(self, spec, deps=False):
with self._tmpdir() as tmpdir:
@@ -1182,7 +1183,7 @@ class easy_install(Command):
dist_dir)
return eggs
finally:
- rmtree(dist_dir)
+ _rmtree(dist_dir)
log.set_verbosity(self.verbose) # restore our log verbosity
def _set_fetcher_options(self, base):
@@ -2289,8 +2290,8 @@ def load_launcher_manifest(name):
return manifest.decode('utf-8') % vars()
-def rmtree(path, ignore_errors=False, onerror=auto_chmod):
- return shutil.rmtree(path, ignore_errors, onerror)
+def _rmtree(path, ignore_errors=False, onexc=auto_chmod):
+ return _py312compat.shutil_rmtree(path, ignore_errors, onexc)
def current_umask():