Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only do the ensure_text() dance on Windows #8666

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/8658.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Only converts Windows path to unicode on Python 2 to avoid regressions when a
POSIX environment does not configure the file system encoding correctly.
2 changes: 1 addition & 1 deletion src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def get_prog():
# Retry every half second for up to 3 seconds
@retry(stop_max_delay=3000, wait_fixed=500)
def rmtree(dir, ignore_errors=False):
# type: (Text, bool) -> None
# type: (AnyStr, bool) -> None
shutil.rmtree(dir, ignore_errors=ignore_errors,
onerror=rmtree_errorhandler)

Expand Down
14 changes: 11 additions & 3 deletions src/pip/_internal/utils/temp_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pip._vendor.contextlib2 import ExitStack
from pip._vendor.six import ensure_text

from pip._internal.utils.compat import WINDOWS
from pip._internal.utils.misc import enum, rmtree
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

Expand Down Expand Up @@ -193,10 +194,17 @@ def cleanup(self):
"""Remove the temporary directory created and reset state
"""
self._deleted = True
if os.path.exists(self._path):
# Make sure to pass unicode on Python 2 to make the contents also
# use unicode, ensuring non-ASCII names and can be represented.
if not os.path.exists(self._path):
return
# Make sure to pass unicode on Python 2 to make the contents also
# use unicode, ensuring non-ASCII names and can be represented.
# This is only done on Windows because POSIX platforms use bytes
# natively for paths, and the bytes-text conversion omission avoids
# errors caused by the environment configuring encodings incorrectly.
if WINDOWS:
rmtree(ensure_text(self._path))
else:
rmtree(self._path)


class AdjacentTempDirectory(TempDirectory):
Expand Down