From 1678730e70272129044cb1c47ca7f7f05cd4db46 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Mon, 7 Oct 2024 14:35:19 +0100 Subject: [PATCH] Extract common pattern to remove dir if exists to setuptools._shutil --- setuptools/_shutil.py | 5 +++++ setuptools/command/dist_info.py | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/setuptools/_shutil.py b/setuptools/_shutil.py index 8abf5faa6b..3d2c11e019 100644 --- a/setuptools/_shutil.py +++ b/setuptools/_shutil.py @@ -39,3 +39,8 @@ def _auto_chmod(func: Callable[..., _T], arg: str, exc: BaseException) -> _T: def rmtree(path, ignore_errors=False, onexc=_auto_chmod): return py311.shutil_rmtree(path, ignore_errors, onexc) + + +def rmdir(path, **opts): + if os.path.isdir(path): + rmtree(path, **opts) diff --git a/setuptools/command/dist_info.py b/setuptools/command/dist_info.py index 3ad27ed708..0192ebb260 100644 --- a/setuptools/command/dist_info.py +++ b/setuptools/command/dist_info.py @@ -10,6 +10,7 @@ from typing import cast from .. import _normalization +from .._shutil import rmdir as _rm from .egg_info import egg_info as egg_info_cls from distutils import log @@ -100,8 +101,3 @@ def run(self) -> None: # TODO: if bdist_wheel if merged into setuptools, just add "keep_egg_info" there with self._maybe_bkp_dir(egg_info_dir, self.keep_egg_info): bdist_wheel.egg2dist(egg_info_dir, self.dist_info_dir) - - -def _rm(dir_name, **opts): - if os.path.isdir(dir_name): - shutil.rmtree(dir_name, **opts)