Skip to content

Commit 90d6fc8

Browse files
committed
Handle Python3.12a7 compatibility problems (#3897)
2 parents 245d72a + aac3c66 commit 90d6fc8

File tree

6 files changed

+36
-5
lines changed

6 files changed

+36
-5
lines changed

pkg_resources/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3046,6 +3046,9 @@ def has_version(self):
30463046
except ValueError:
30473047
issue_warning("Unbuilt egg for " + repr(self))
30483048
return False
3049+
except SystemError:
3050+
# TODO: remove this except clause when python/cpython#103632 is fixed.
3051+
return False
30493052
return True
30503053

30513054
def clone(self, **kw):

pkg_resources/tests/test_pkg_resources.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ def make_distribution_no_version(tmpdir, basename):
256256
('dist-info', 'METADATA', DistInfoDistribution),
257257
],
258258
)
259+
@pytest.mark.xfail(
260+
sys.version_info[:2] == (3, 12) and sys.version_info.releaselevel != 'final',
261+
reason="https://github.com/python/cpython/issues/103632",
262+
)
259263
def test_distribution_version_missing(
260264
tmpdir, suffix, expected_filename, expected_dist_type):
261265
"""
@@ -286,6 +290,10 @@ def test_distribution_version_missing(
286290
assert type(dist) == expected_dist_type
287291

288292

293+
@pytest.mark.xfail(
294+
sys.version_info[:2] == (3, 12) and sys.version_info.releaselevel != 'final',
295+
reason="https://github.com/python/cpython/issues/103632",
296+
)
289297
def test_distribution_version_missing_undetected_path():
290298
"""
291299
Test Distribution.version when the "Version" header is missing and

pkg_resources/tests/test_resources.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ def test_marker_evaluation_with_extras_loop(self):
319319
res = list(ws.resolve(parse_requirements("a"), ad))
320320
assert res == [a, c, b, foo]
321321

322+
@pytest.mark.xfail(
323+
sys.version_info[:2] == (3, 12) and sys.version_info.releaselevel != 'final',
324+
reason="https://github.com/python/cpython/issues/103632",
325+
)
322326
def testDistroDependsOptions(self):
323327
d = self.distRequires("""
324328
Twisted>=1.5

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ filterwarnings=
3636
# python/cpython#100750
3737
ignore:'encoding' argument not specified::platform
3838

39+
# Dependencies might not have been updated yet
40+
default:onerror argument is deprecated, use onexc instead
41+
3942
## end upstream
4043

4144
# https://github.com/pypa/setuptools/issues/1823

setuptools/command/easy_install.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
VersionConflict, DEVELOP_DIST,
6363
)
6464
import pkg_resources
65+
from .. import py312compat
6566
from .._path import ensure_directory
6667
from ..extern.jaraco.text import yield_lines
6768

@@ -202,7 +203,7 @@ def _delete_path(self, path):
202203
return
203204

204205
is_tree = os.path.isdir(path) and not os.path.islink(path)
205-
remover = rmtree if is_tree else os.unlink
206+
remover = _rmtree if is_tree else os.unlink
206207
remover(path)
207208

208209
@staticmethod
@@ -645,7 +646,7 @@ def _tmpdir(self):
645646
# cast to str as workaround for #709 and #710 and #712
646647
yield str(tmpdir)
647648
finally:
648-
os.path.exists(tmpdir) and rmtree(tmpdir)
649+
os.path.exists(tmpdir) and _rmtree(tmpdir)
649650

650651
def easy_install(self, spec, deps=False):
651652
with self._tmpdir() as tmpdir:
@@ -1182,7 +1183,7 @@ def build_and_install(self, setup_script, setup_base):
11821183
dist_dir)
11831184
return eggs
11841185
finally:
1185-
rmtree(dist_dir)
1186+
_rmtree(dist_dir)
11861187
log.set_verbosity(self.verbose) # restore our log verbosity
11871188

11881189
def _set_fetcher_options(self, base):
@@ -2289,8 +2290,8 @@ def load_launcher_manifest(name):
22892290
return manifest.decode('utf-8') % vars()
22902291

22912292

2292-
def rmtree(path, ignore_errors=False, onerror=auto_chmod):
2293-
return shutil.rmtree(path, ignore_errors, onerror)
2293+
def _rmtree(path, ignore_errors=False, onexc=auto_chmod):
2294+
return py312compat.shutil_rmtree(path, ignore_errors, onexc)
22942295

22952296

22962297
def current_umask():

setuptools/py312compat.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys
2+
import shutil
3+
4+
5+
def shutil_rmtree(path, ignore_errors=False, onexc=None):
6+
if sys.version_info >= (3, 12):
7+
return shutil.rmtree(path, ignore_errors, onexc=onexc)
8+
9+
def _handler(fn, path, excinfo):
10+
return onexc(fn, path, excinfo[1])
11+
12+
return shutil.rmtree(path, ignore_errors, onerror=_handler)

0 commit comments

Comments
 (0)