Skip to content

Commit 1678730

Browse files
committed
Extract common pattern to remove dir if exists to setuptools._shutil
1 parent d9975c6 commit 1678730

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

setuptools/_shutil.py

+5
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,8 @@ def _auto_chmod(func: Callable[..., _T], arg: str, exc: BaseException) -> _T:
3939

4040
def rmtree(path, ignore_errors=False, onexc=_auto_chmod):
4141
return py311.shutil_rmtree(path, ignore_errors, onexc)
42+
43+
44+
def rmdir(path, **opts):
45+
if os.path.isdir(path):
46+
rmtree(path, **opts)

setuptools/command/dist_info.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import cast
1111

1212
from .. import _normalization
13+
from .._shutil import rmdir as _rm
1314
from .egg_info import egg_info as egg_info_cls
1415

1516
from distutils import log
@@ -100,8 +101,3 @@ def run(self) -> None:
100101
# TODO: if bdist_wheel if merged into setuptools, just add "keep_egg_info" there
101102
with self._maybe_bkp_dir(egg_info_dir, self.keep_egg_info):
102103
bdist_wheel.egg2dist(egg_info_dir, self.dist_info_dir)
103-
104-
105-
def _rm(dir_name, **opts):
106-
if os.path.isdir(dir_name):
107-
shutil.rmtree(dir_name, **opts)

0 commit comments

Comments
 (0)