Skip to content

Commit

Permalink
Extract common pattern to remove dir if exists to setuptools._shutil
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Nov 11, 2024
1 parent d9975c6 commit 1678730
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 5 additions & 0 deletions setuptools/_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 1 addition & 5 deletions setuptools/command/dist_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 1678730

Please sign in to comment.