diff --git a/src/pip/_internal/locations/__init__.py b/src/pip/_internal/locations/__init__.py index 327d75a957b..78969546345 100644 --- a/src/pip/_internal/locations/__init__.py +++ b/src/pip/_internal/locations/__init__.py @@ -8,6 +8,7 @@ from . import _distutils, _sysconfig from .base import ( USER_CACHE_DIR, + get_bin_user, get_major_minor_version, get_src_prefix, site_packages, @@ -100,14 +101,6 @@ def get_bin_prefix(): return old -def get_bin_user(): - # type: () -> str - old = _distutils.get_bin_user() - new = _sysconfig.get_bin_user() - _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="bin_user") - return old - - def get_purelib(): # type: () -> str """Return the default pure-Python lib location.""" diff --git a/src/pip/_internal/locations/_distutils.py b/src/pip/_internal/locations/_distutils.py index 7eecf8d8fa4..2d7ab73213c 100644 --- a/src/pip/_internal/locations/_distutils.py +++ b/src/pip/_internal/locations/_distutils.py @@ -4,7 +4,7 @@ # mypy: strict-optional=False import os -import os.path +import sys from distutils.cmd import Command as DistutilsCommand from distutils.command.install import SCHEME_KEYS from distutils.command.install import install as distutils_install_command @@ -12,9 +12,10 @@ from typing import Dict, List, Optional, Tuple, Union, cast from pip._internal.models.scheme import Scheme +from pip._internal.utils.compat import WINDOWS from pip._internal.utils.virtualenv import running_under_virtualenv -from .base import bin_py, bin_user, get_major_minor_version +from .base import get_major_minor_version def _distutils_scheme( @@ -118,12 +119,17 @@ def get_scheme( def get_bin_prefix(): # type: () -> str - return bin_py - - -def get_bin_user(): - # type: () -> str - return bin_user + if WINDOWS: + bin_py = os.path.join(sys.prefix, "Scripts") + # buildout uses 'bin' on Windows too? + if not os.path.exists(bin_py): + bin_py = os.path.join(sys.prefix, "bin") + return bin_py + # Forcing to use /usr/local/bin for standard macOS framework installs + # Also log to ~/Library/Logs/ for use with the Console.app log viewer + if sys.platform[:6] == "darwin" and sys.prefix[:16] == "/System/Library/": + return "/usr/local/bin" + return os.path.join(sys.prefix, "bin") def get_purelib(): diff --git a/src/pip/_internal/locations/_sysconfig.py b/src/pip/_internal/locations/_sysconfig.py index a71cd8adc43..8ef72813b3b 100644 --- a/src/pip/_internal/locations/_sysconfig.py +++ b/src/pip/_internal/locations/_sysconfig.py @@ -9,7 +9,7 @@ from pip._internal.models.scheme import SCHEME_KEYS, Scheme from pip._internal.utils.virtualenv import running_under_virtualenv -from .base import bin_user, get_major_minor_version +from .base import get_major_minor_version logger = logging.getLogger(__name__) @@ -139,14 +139,6 @@ def get_bin_prefix(): return sysconfig.get_paths(scheme=_infer_scheme("prefix"))["scripts"] -def get_bin_user(): - # type: () -> str - # pip puts the scripts directory in site-packages, not under userbase. - # I'm honestly not sure if this is a bug (because ``get_scheme()`` puts it - # correctly under userbase), but we need to be compatible. - return bin_user - - def get_purelib(): # type: () -> str return sysconfig.get_paths()["purelib"] diff --git a/src/pip/_internal/locations/base.py b/src/pip/_internal/locations/base.py index 5035662e3a4..3a03a79565c 100644 --- a/src/pip/_internal/locations/base.py +++ b/src/pip/_internal/locations/base.py @@ -49,18 +49,18 @@ def get_src_prefix(): user_site = site.USER_SITE -if WINDOWS: - bin_py = os.path.join(sys.prefix, "Scripts") - bin_user = os.path.join(user_site, "Scripts") - # buildout uses 'bin' on Windows too? - if not os.path.exists(bin_py): - bin_py = os.path.join(sys.prefix, "bin") - bin_user = os.path.join(user_site, "bin") -else: - bin_py = os.path.join(sys.prefix, "bin") - bin_user = os.path.join(user_site, "bin") +def get_bin_user(): + # type: () -> str + """Get the user-site scripts directory. - # Forcing to use /usr/local/bin for standard macOS framework installs - # Also log to ~/Library/Logs/ for use with the Console.app log viewer - if sys.platform[:6] == "darwin" and sys.prefix[:16] == "/System/Library/": - bin_py = "/usr/local/bin" + Pip puts the scripts directory in site-packages, not under userbase. + I'm honestly not sure if this is a bug (because ``get_scheme()`` puts it + correctly under userbase), but we need to keep backwards compatibility. + """ + assert user_site is not None, "user site unavailable" + if not WINDOWS: + return os.path.join(user_site, "bin") + # Special case for buildout, which uses 'bin' on Windows too? + if not os.path.exists(os.path.join(sys.prefix, "Scripts")): + os.path.join(user_site, "bin") + return os.path.join(user_site, "Scripts")