diff options
Diffstat (limited to 'setuptools')
| -rw-r--r-- | setuptools/command/easy_install.py | 11 | ||||
| -rw-r--r-- | setuptools/py312compat.py | 12 |
2 files changed, 18 insertions, 5 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 444d3b33..3185ee1d 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(): diff --git a/setuptools/py312compat.py b/setuptools/py312compat.py new file mode 100644 index 00000000..28175b1f --- /dev/null +++ b/setuptools/py312compat.py @@ -0,0 +1,12 @@ +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): + return onexc(fn, path, excinfo[1]) + + return shutil.rmtree(path, ignore_errors, onerror=_handler) |
