Skip to content

Commit

Permalink
Merge pull request pypa#9396 from jdufresne/expanduser
Browse files Browse the repository at this point in the history
Replace compat.expanduser() with os.path.expanduser()
  • Loading branch information
pradyunsg authored Dec 29, 2020
2 parents af5b7fe + 5150129 commit 7369ac2
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 37 deletions.
Empty file.
4 changes: 2 additions & 2 deletions src/pip/_internal/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
ConfigurationFileCouldNotBeLoaded,
)
from pip._internal.utils import appdirs
from pip._internal.utils.compat import WINDOWS, expanduser
from pip._internal.utils.compat import WINDOWS
from pip._internal.utils.misc import ensure_dir, enum
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

Expand Down Expand Up @@ -80,7 +80,7 @@ def get_configuration_files():

site_config_file = os.path.join(sys.prefix, CONFIG_BASENAME)
legacy_config_file = os.path.join(
expanduser('~'),
os.path.expanduser('~'),
'pip' if WINDOWS else '.pip',
CONFIG_BASENAME,
)
Expand Down
13 changes: 0 additions & 13 deletions src/pip/_internal/utils/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,6 @@ def get_path_uid(path):
return file_uid


def expanduser(path):
# type: (str) -> str
"""
Expand ~ and ~user constructions.
Includes a workaround for https://bugs.python.org/issue14768
"""
expanded = os.path.expanduser(path)
if path.startswith('~/') and expanded.startswith('//'):
expanded = expanded[1:]
return expanded


# packages in the stdlib that may have installation metadata, but should not be
# considered 'installed'. this theoretically could be determined based on
# dist.location (py27:`sysconfig.get_paths()['stdlib']`,
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from pip import __version__
from pip._internal.exceptions import CommandError
from pip._internal.locations import get_major_minor_version, site_packages, user_site
from pip._internal.utils.compat import WINDOWS, expanduser, stdlib_pkgs
from pip._internal.utils.compat import WINDOWS, stdlib_pkgs
from pip._internal.utils.typing import MYPY_CHECK_RUNNING, cast
from pip._internal.utils.virtualenv import (
running_under_virtualenv,
Expand Down Expand Up @@ -302,7 +302,7 @@ def normalize_path(path, resolve_symlinks=True):
Convert a path to its canonical, case-normalized, absolute version.
"""
path = expanduser(path)
path = os.path.expanduser(path)
if resolve_symlinks:
path = os.path.realpath(path)
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ def test_link_collector_create(
assert search_scope.index_urls == expected_index_urls


@patch('pip._internal.utils.misc.expanduser')
@patch('os.path.expanduser')
def test_link_collector_create_find_links_expansion(
mock_expanduser, tmpdir,
):
Expand Down
20 changes: 1 addition & 19 deletions tests/unit/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
import pytest

import pip._internal.utils.compat as pip_compat
from pip._internal.utils.compat import (
console_to_str,
expanduser,
get_path_uid,
str_to_display,
)
from pip._internal.utils.compat import console_to_str, get_path_uid, str_to_display


def test_get_path_uid():
Expand Down Expand Up @@ -127,16 +122,3 @@ def check_warning(msg, *args, **kwargs):
monkeypatch.setattr(locale, 'getpreferredencoding', lambda: 'utf-8')
monkeypatch.setattr(pip_compat.logger, 'warning', check_warning)
console_to_str(some_bytes)


@pytest.mark.parametrize("home,path,expanded", [
("/Users/test", "~", "/Users/test"),
("/Users/test", "~/.cache", "/Users/test/.cache"),
# Verify that we are not affected by https://bugs.python.org/issue14768
("/", "~", "/"),
("/", "~/.cache", "/.cache"),
])
def test_expanduser(home, path, expanded, monkeypatch):
monkeypatch.setenv("HOME", home)
monkeypatch.setenv("USERPROFILE", home)
assert expanduser(path) == expanded

0 comments on commit 7369ac2

Please sign in to comment.