Skip to content

Commit 7369ac2

Browse files
authored
Merge pull request #9396 from jdufresne/expanduser
Replace compat.expanduser() with os.path.expanduser()
2 parents af5b7fe + 5150129 commit 7369ac2

File tree

6 files changed

+6
-37
lines changed

6 files changed

+6
-37
lines changed

news/7edb0afc-938e-457b-ae6e-0905e7443b2f.trivial.rst

Whitespace-only changes.

src/pip/_internal/configuration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
ConfigurationFileCouldNotBeLoaded,
2323
)
2424
from pip._internal.utils import appdirs
25-
from pip._internal.utils.compat import WINDOWS, expanduser
25+
from pip._internal.utils.compat import WINDOWS
2626
from pip._internal.utils.misc import ensure_dir, enum
2727
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
2828

@@ -80,7 +80,7 @@ def get_configuration_files():
8080

8181
site_config_file = os.path.join(sys.prefix, CONFIG_BASENAME)
8282
legacy_config_file = os.path.join(
83-
expanduser('~'),
83+
os.path.expanduser('~'),
8484
'pip' if WINDOWS else '.pip',
8585
CONFIG_BASENAME,
8686
)

src/pip/_internal/utils/compat.py

-13
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,6 @@ def get_path_uid(path):
139139
return file_uid
140140

141141

142-
def expanduser(path):
143-
# type: (str) -> str
144-
"""
145-
Expand ~ and ~user constructions.
146-
147-
Includes a workaround for https://bugs.python.org/issue14768
148-
"""
149-
expanded = os.path.expanduser(path)
150-
if path.startswith('~/') and expanded.startswith('//'):
151-
expanded = expanded[1:]
152-
return expanded
153-
154-
155142
# packages in the stdlib that may have installation metadata, but should not be
156143
# considered 'installed'. this theoretically could be determined based on
157144
# dist.location (py27:`sysconfig.get_paths()['stdlib']`,

src/pip/_internal/utils/misc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from pip import __version__
2929
from pip._internal.exceptions import CommandError
3030
from pip._internal.locations import get_major_minor_version, site_packages, user_site
31-
from pip._internal.utils.compat import WINDOWS, expanduser, stdlib_pkgs
31+
from pip._internal.utils.compat import WINDOWS, stdlib_pkgs
3232
from pip._internal.utils.typing import MYPY_CHECK_RUNNING, cast
3333
from pip._internal.utils.virtualenv import (
3434
running_under_virtualenv,
@@ -302,7 +302,7 @@ def normalize_path(path, resolve_symlinks=True):
302302
Convert a path to its canonical, case-normalized, absolute version.
303303
304304
"""
305-
path = expanduser(path)
305+
path = os.path.expanduser(path)
306306
if resolve_symlinks:
307307
path = os.path.realpath(path)
308308
else:

tests/unit/test_collector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ def test_link_collector_create(
733733
assert search_scope.index_urls == expected_index_urls
734734

735735

736-
@patch('pip._internal.utils.misc.expanduser')
736+
@patch('os.path.expanduser')
737737
def test_link_collector_create_find_links_expansion(
738738
mock_expanduser, tmpdir,
739739
):

tests/unit/test_compat.py

+1-19
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
import pytest
66

77
import pip._internal.utils.compat as pip_compat
8-
from pip._internal.utils.compat import (
9-
console_to_str,
10-
expanduser,
11-
get_path_uid,
12-
str_to_display,
13-
)
8+
from pip._internal.utils.compat import console_to_str, get_path_uid, str_to_display
149

1510

1611
def test_get_path_uid():
@@ -127,16 +122,3 @@ def check_warning(msg, *args, **kwargs):
127122
monkeypatch.setattr(locale, 'getpreferredencoding', lambda: 'utf-8')
128123
monkeypatch.setattr(pip_compat.logger, 'warning', check_warning)
129124
console_to_str(some_bytes)
130-
131-
132-
@pytest.mark.parametrize("home,path,expanded", [
133-
("/Users/test", "~", "/Users/test"),
134-
("/Users/test", "~/.cache", "/Users/test/.cache"),
135-
# Verify that we are not affected by https://bugs.python.org/issue14768
136-
("/", "~", "/"),
137-
("/", "~/.cache", "/.cache"),
138-
])
139-
def test_expanduser(home, path, expanded, monkeypatch):
140-
monkeypatch.setenv("HOME", home)
141-
monkeypatch.setenv("USERPROFILE", home)
142-
assert expanduser(path) == expanded

0 commit comments

Comments
 (0)