Skip to content

Commit 94fbb6c

Browse files
committed
Only do the ensure_text() dance on Windows
POSIX is problematic when the environment is not configured properly.
1 parent 5bfd1db commit 94fbb6c

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

news/8658.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
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.

src/pip/_internal/utils/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def get_prog():
137137
# Retry every half second for up to 3 seconds
138138
@retry(stop_max_delay=3000, wait_fixed=500)
139139
def rmtree(dir, ignore_errors=False):
140-
# type: (Text, bool) -> None
140+
# type: (AnyStr, bool) -> None
141141
shutil.rmtree(dir, ignore_errors=ignore_errors,
142142
onerror=rmtree_errorhandler)
143143

src/pip/_internal/utils/temp_dir.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pip._vendor.contextlib2 import ExitStack
1111
from pip._vendor.six import ensure_text
1212

13+
from pip._internal.utils.compat import WINDOWS
1314
from pip._internal.utils.misc import enum, rmtree
1415
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
1516

@@ -193,10 +194,17 @@ def cleanup(self):
193194
"""Remove the temporary directory created and reset state
194195
"""
195196
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:
199205
rmtree(ensure_text(self._path))
206+
else:
207+
rmtree(self._path)
200208

201209

202210
class AdjacentTempDirectory(TempDirectory):

0 commit comments

Comments
 (0)