Skip to content

Commit

Permalink
Split bin_user and bin_prefix implementations
Browse files Browse the repository at this point in the history
Module-level logic is bad.
  • Loading branch information
uranusjr committed Feb 22, 2021
1 parent 1e1289e commit b7068f6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 39 deletions.
9 changes: 1 addition & 8 deletions src/pip/_internal/locations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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."""
Expand Down
22 changes: 14 additions & 8 deletions src/pip/_internal/locations/_distutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
# 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
from distutils.sysconfig import get_python_lib
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(
Expand Down Expand Up @@ -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():
Expand Down
10 changes: 1 addition & 9 deletions src/pip/_internal/locations/_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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"]
Expand Down
28 changes: 14 additions & 14 deletions src/pip/_internal/locations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit b7068f6

Please sign in to comment.