Skip to content

Commit 8a949a1

Browse files
authored
Merge pull request #9415 from jdufresne/path_to_display
Remove Python 2 compat shim path_to_display()
2 parents 8f1bd0e + 3f6df16 commit 8a949a1

File tree

5 files changed

+5
-47
lines changed

5 files changed

+5
-47
lines changed

news/a06e528d-1172-4012-a0a5-0fc42264a70d.trivial.rst

Whitespace-only changes.

src/pip/_internal/operations/prepare.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from pip._internal.utils.filesystem import copy2_fixed
3939
from pip._internal.utils.hashes import Hashes, MissingHashes
4040
from pip._internal.utils.logging import indent_log
41-
from pip._internal.utils.misc import display_path, hide_url, path_to_display, rmtree
41+
from pip._internal.utils.misc import display_path, hide_url, rmtree
4242
from pip._internal.utils.temp_dir import TempDirectory
4343
from pip._internal.utils.unpacking import unpack_file
4444
from pip._internal.vcs import vcs
@@ -121,8 +121,8 @@ def _copy2_ignoring_special_files(src, dest):
121121
logger.warning(
122122
"Ignoring special file error '%s' encountered copying %s to %s.",
123123
str(e),
124-
path_to_display(src),
125-
path_to_display(dest),
124+
src,
125+
dest,
126126
)
127127

128128

src/pip/_internal/utils/misc.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -144,30 +144,6 @@ def rmtree_errorhandler(func, path, exc_info):
144144
raise
145145

146146

147-
def path_to_display(path):
148-
# type: (Optional[str]) -> Optional[str]
149-
"""
150-
Convert a bytes (or text) path to text (unicode in Python 2) for display
151-
and logging purposes.
152-
153-
This function should never error out. Also, this function is mainly needed
154-
for Python 2 since in Python 3 str paths are already text.
155-
"""
156-
if path is None:
157-
return None
158-
if isinstance(path, str):
159-
return path
160-
# Otherwise, path is a bytes object (str in Python 2).
161-
try:
162-
display_path = path.decode(sys.getfilesystemencoding(), 'strict')
163-
except UnicodeDecodeError:
164-
# Include the full bytes to make troubleshooting easier, even though
165-
# it may not be very human readable.
166-
display_path = ascii(path)
167-
168-
return display_path
169-
170-
171147
def display_path(path):
172148
# type: (str) -> str
173149
"""Gives the display value for a given path, making it relative to cwd

src/pip/_internal/utils/subprocess.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pip._internal.exceptions import InstallationSubprocessError
99
from pip._internal.utils.compat import console_to_str, str_to_display
1010
from pip._internal.utils.logging import subprocess_logger
11-
from pip._internal.utils.misc import HiddenText, path_to_display
11+
from pip._internal.utils.misc import HiddenText
1212

1313
CommandArgs = List[Union[str, HiddenText]]
1414

@@ -79,7 +79,6 @@ def make_subprocess_output_error(
7979
# "UnicodeDecodeError: 'ascii' codec can't decode byte ..." in Python 2
8080
# if either contains a non-ascii character.
8181
command_display = str_to_display(command, desc='command bytes')
82-
cwd_display = path_to_display(cwd)
8382

8483
# We know the joined output value ends in a newline.
8584
output = ''.join(lines)
@@ -94,7 +93,7 @@ def make_subprocess_output_error(
9493
).format(
9594
exit_status=exit_status,
9695
command_display=command_display,
97-
cwd_display=cwd_display,
96+
cwd_display=cwd,
9897
line_count=len(lines),
9998
output=output,
10099
divider=LOG_DIVIDER,

tests/unit/test_utils.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
normalize_path,
3939
normalize_version_info,
4040
parse_netloc,
41-
path_to_display,
4241
redact_auth_from_url,
4342
redact_netloc,
4443
remove_auth_from_url,
@@ -431,22 +430,6 @@ def test_rmtree_retries_for_3sec(tmpdir, monkeypatch):
431430
)
432431

433432

434-
@pytest.mark.parametrize('path, fs_encoding, expected', [
435-
(None, None, None),
436-
# Test passing a text (unicode) string.
437-
('/path/déf', None, '/path/déf'),
438-
# Test a bytes object with a non-ascii character.
439-
('/path/déf'.encode('utf-8'), 'utf-8', '/path/déf'),
440-
# Test a bytes object with a character that can't be decoded.
441-
('/path/déf'.encode('utf-8'), 'ascii', "b'/path/d\\xc3\\xa9f'"),
442-
('/path/déf'.encode('utf-16'), 'utf-8', expected_byte_string),
443-
])
444-
def test_path_to_display(monkeypatch, path, fs_encoding, expected):
445-
monkeypatch.setattr(sys, 'getfilesystemencoding', lambda: fs_encoding)
446-
actual = path_to_display(path)
447-
assert actual == expected, f'actual: {actual!r}'
448-
449-
450433
class Test_normalize_path:
451434
# Technically, symlinks are possible on Windows, but you need a special
452435
# permission bit to create them, and Python 2 doesn't support it anyway, so

0 commit comments

Comments
 (0)