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
@@ -195,10 +196,17 @@ def cleanup(self):
195
196
"""Remove the temporary directory created and reset state
196
197
"""
197
198
self ._deleted = True
198
- if os .path .exists (self ._path ):
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.
199
+ if not os .path .exists (self ._path ):
200
+ return
201
+ # Make sure to pass unicode on Python 2 to make the contents also
202
+ # use unicode, ensuring non-ASCII names and can be represented.
203
+ # This is only done on Windows because POSIX platforms use bytes
204
+ # natively for paths, and the bytes-text conversion omission avoids
205
+ # errors caused by the environment configuring encodings incorrectly.
206
+ if WINDOWS :
201
207
rmtree (ensure_text (self ._path ))
208
+ else :
209
+ rmtree (self ._path )
202
210
203
211
204
212
class AdjacentTempDirectory (TempDirectory ):
You can’t perform that action at this time.
0 commit comments