File tree 3 files changed +14
-4
lines changed 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change
1
+ Only converts Windows path to unicode on Python 2 to avoid regressions when a
2
+ POSIX environment does not configure the file system encoding correctly.
Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ def get_prog():
137
137
# Retry every half second for up to 3 seconds
138
138
@retry (stop_max_delay = 3000 , wait_fixed = 500 )
139
139
def rmtree (dir , ignore_errors = False ):
140
- # type: (Text , bool) -> None
140
+ # type: (AnyStr , bool) -> None
141
141
shutil .rmtree (dir , ignore_errors = ignore_errors ,
142
142
onerror = rmtree_errorhandler )
143
143
Original file line number Diff line number Diff line change 10
10
from pip ._vendor .contextlib2 import ExitStack
11
11
from pip ._vendor .six import ensure_text
12
12
13
+ from pip ._internal .utils .compat import WINDOWS
13
14
from pip ._internal .utils .misc import enum , rmtree
14
15
from pip ._internal .utils .typing import MYPY_CHECK_RUNNING
15
16
@@ -193,10 +194,17 @@ def cleanup(self):
193
194
"""Remove the temporary directory created and reset state
194
195
"""
195
196
self ._deleted = True
196
- if os .path .exists (self ._path ):
197
- # Make sure to pass unicode on Python 2 to make the contents also
198
- # use unicode, ensuring non-ASCII names and can be represented.
197
+ if not os .path .exists (self ._path ):
198
+ return
199
+ # Make sure to pass unicode on Python 2 to make the contents also
200
+ # use unicode, ensuring non-ASCII names and can be represented.
201
+ # This is only done on Windows because POSIX platforms use bytes
202
+ # natively for paths, and the bytes-text conversion omission avoids
203
+ # errors caused by the environment configuring encodings incorrectly.
204
+ if WINDOWS :
199
205
rmtree (ensure_text (self ._path ))
206
+ else :
207
+ rmtree (self ._path )
200
208
201
209
202
210
class AdjacentTempDirectory (TempDirectory ):
You can’t perform that action at this time.
0 commit comments