5
5
import tempfile
6
6
import traceback
7
7
from contextlib import ExitStack , contextmanager
8
- from typing import Any , Callable , Dict , Generator , Optional , Tuple , Type , TypeVar , Union
8
+ from typing import (
9
+ Any ,
10
+ Callable ,
11
+ Dict ,
12
+ Generator ,
13
+ List ,
14
+ Optional ,
15
+ Tuple ,
16
+ Type ,
17
+ TypeVar ,
18
+ Union ,
19
+ )
9
20
10
21
from pip ._internal .utils .misc import enum , rmtree
11
22
@@ -174,6 +185,8 @@ def cleanup(self) -> None:
174
185
if not os .path .exists (self ._path ):
175
186
return
176
187
188
+ errors : List [BaseException ] = []
189
+
177
190
def onerror (
178
191
func : Callable [[str ], Any ],
179
192
path : str ,
@@ -183,14 +196,14 @@ def onerror(
183
196
exc_val = "\n " .join (traceback .format_exception_only (* exc_info [:2 ]))
184
197
exc_val = exc_val .rstrip () # remove trailing new line
185
198
if func in (os .unlink , os .remove , os .rmdir ):
186
- logging .warning (
187
- "Failed to remove a temporary file '%s' due to %s.\n "
188
- "You can safely remove it manually." ,
199
+ logger .debug (
200
+ "Failed to remove a temporary file '%s' due to %s.\n " ,
189
201
path ,
190
202
exc_val ,
191
203
)
192
204
else :
193
- logging .warning ("%s failed with %s." , func .__qualname__ , exc_val )
205
+ logger .debug ("%s failed with %s." , func .__qualname__ , exc_val )
206
+ errors .append (exc_info [1 ])
194
207
195
208
if self .ignore_cleanup_errors :
196
209
try :
@@ -199,6 +212,12 @@ def onerror(
199
212
except OSError :
200
213
# last pass ignore/log all errors
201
214
rmtree (self ._path , onerror = onerror )
215
+ if errors :
216
+ logger .warning (
217
+ "Failed to remove contents of a temporary directory '%s'.\n "
218
+ "You can safely remove it manually." ,
219
+ self ._path ,
220
+ )
202
221
else :
203
222
rmtree (self ._path )
204
223
0 commit comments