mirror of https://github.com/pypa/pip
incorporate review comments
This commit is contained in:
parent
eabefd4021
commit
454e9768fb
|
@ -130,7 +130,7 @@ def get_prog() -> str:
|
|||
def rmtree(
|
||||
dir: str,
|
||||
ignore_errors: bool = False,
|
||||
onexc: Optional[OnErr] = None,
|
||||
onexc: Optional[OnExc] = None,
|
||||
) -> None:
|
||||
if ignore_errors:
|
||||
onexc = _onerror_ignore
|
||||
|
@ -158,8 +158,8 @@ def _onerror_reraise(*_args: Any) -> None:
|
|||
|
||||
|
||||
def rmtree_errorhandler(
|
||||
func: Callable[..., Any],
|
||||
path: str,
|
||||
func: FunctionType,
|
||||
path: Path,
|
||||
exc_info: Union[ExcInfo, BaseException],
|
||||
*,
|
||||
onexc: OnExc = _onerror_reraise,
|
||||
|
@ -193,6 +193,8 @@ def rmtree_errorhandler(
|
|||
except OSError:
|
||||
pass
|
||||
|
||||
if not isinstance(exc_info, BaseException):
|
||||
_, exc_info, _ = exc_info
|
||||
onexc(func, path, exc_info)
|
||||
|
||||
|
||||
|
|
|
@ -6,15 +6,13 @@ import tempfile
|
|||
import traceback
|
||||
from contextlib import ExitStack, contextmanager
|
||||
from pathlib import Path
|
||||
from types import FunctionType
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Dict,
|
||||
Generator,
|
||||
List,
|
||||
Optional,
|
||||
Tuple,
|
||||
Type,
|
||||
TypeVar,
|
||||
Union,
|
||||
)
|
||||
|
@ -189,22 +187,24 @@ class TempDirectory:
|
|||
errors: List[BaseException] = []
|
||||
|
||||
def onerror(
|
||||
func: Callable[[str], Any],
|
||||
func: FunctionType,
|
||||
path: Path,
|
||||
exc_info: Tuple[Type[BaseException], BaseException, Any],
|
||||
exc_val: BaseException,
|
||||
) -> None:
|
||||
"""Log a warning for a `rmtree` error and continue"""
|
||||
exc_val = "\n".join(traceback.format_exception_only(*exc_info[:2]))
|
||||
exc_val = exc_val.rstrip() # remove trailing new line
|
||||
formatted_exc = "\n".join(
|
||||
traceback.format_exception_only(type(exc_val), exc_val)
|
||||
)
|
||||
formatted_exc = formatted_exc.rstrip() # remove trailing new line
|
||||
if func in (os.unlink, os.remove, os.rmdir):
|
||||
logger.debug(
|
||||
"Failed to remove a temporary file '%s' due to %s.\n",
|
||||
path,
|
||||
exc_val,
|
||||
formatted_exc,
|
||||
)
|
||||
else:
|
||||
logger.debug("%s failed with %s.", func.__qualname__, exc_val)
|
||||
errors.append(exc_info[1])
|
||||
logger.debug("%s failed with %s.", func.__qualname__, formatted_exc)
|
||||
errors.append(exc_val)
|
||||
|
||||
if self.ignore_cleanup_errors:
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue