Skip to content

Commit b7068f6

Browse files
committed
Split bin_user and bin_prefix implementations
Module-level logic is bad.
1 parent 1e1289e commit b7068f6

File tree

4 files changed

+30
-39
lines changed

4 files changed

+30
-39
lines changed

src/pip/_internal/locations/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from . import _distutils, _sysconfig
99
from .base import (
1010
USER_CACHE_DIR,
11+
get_bin_user,
1112
get_major_minor_version,
1213
get_src_prefix,
1314
site_packages,
@@ -100,14 +101,6 @@ def get_bin_prefix():
100101
return old
101102

102103

103-
def get_bin_user():
104-
# type: () -> str
105-
old = _distutils.get_bin_user()
106-
new = _sysconfig.get_bin_user()
107-
_warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="bin_user")
108-
return old
109-
110-
111104
def get_purelib():
112105
# type: () -> str
113106
"""Return the default pure-Python lib location."""

src/pip/_internal/locations/_distutils.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
# mypy: strict-optional=False
55

66
import os
7-
import os.path
7+
import sys
88
from distutils.cmd import Command as DistutilsCommand
99
from distutils.command.install import SCHEME_KEYS
1010
from distutils.command.install import install as distutils_install_command
1111
from distutils.sysconfig import get_python_lib
1212
from typing import Dict, List, Optional, Tuple, Union, cast
1313

1414
from pip._internal.models.scheme import Scheme
15+
from pip._internal.utils.compat import WINDOWS
1516
from pip._internal.utils.virtualenv import running_under_virtualenv
1617

17-
from .base import bin_py, bin_user, get_major_minor_version
18+
from .base import get_major_minor_version
1819

1920

2021
def _distutils_scheme(
@@ -118,12 +119,17 @@ def get_scheme(
118119

119120
def get_bin_prefix():
120121
# type: () -> str
121-
return bin_py
122-
123-
124-
def get_bin_user():
125-
# type: () -> str
126-
return bin_user
122+
if WINDOWS:
123+
bin_py = os.path.join(sys.prefix, "Scripts")
124+
# buildout uses 'bin' on Windows too?
125+
if not os.path.exists(bin_py):
126+
bin_py = os.path.join(sys.prefix, "bin")
127+
return bin_py
128+
# Forcing to use /usr/local/bin for standard macOS framework installs
129+
# Also log to ~/Library/Logs/ for use with the Console.app log viewer
130+
if sys.platform[:6] == "darwin" and sys.prefix[:16] == "/System/Library/":
131+
return "/usr/local/bin"
132+
return os.path.join(sys.prefix, "bin")
127133

128134

129135
def get_purelib():

src/pip/_internal/locations/_sysconfig.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pip._internal.models.scheme import SCHEME_KEYS, Scheme
1010
from pip._internal.utils.virtualenv import running_under_virtualenv
1111

12-
from .base import bin_user, get_major_minor_version
12+
from .base import get_major_minor_version
1313

1414
logger = logging.getLogger(__name__)
1515

@@ -139,14 +139,6 @@ def get_bin_prefix():
139139
return sysconfig.get_paths(scheme=_infer_scheme("prefix"))["scripts"]
140140

141141

142-
def get_bin_user():
143-
# type: () -> str
144-
# pip puts the scripts directory in site-packages, not under userbase.
145-
# I'm honestly not sure if this is a bug (because ``get_scheme()`` puts it
146-
# correctly under userbase), but we need to be compatible.
147-
return bin_user
148-
149-
150142
def get_purelib():
151143
# type: () -> str
152144
return sysconfig.get_paths()["purelib"]

src/pip/_internal/locations/base.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ def get_src_prefix():
4949
user_site = site.USER_SITE
5050

5151

52-
if WINDOWS:
53-
bin_py = os.path.join(sys.prefix, "Scripts")
54-
bin_user = os.path.join(user_site, "Scripts")
55-
# buildout uses 'bin' on Windows too?
56-
if not os.path.exists(bin_py):
57-
bin_py = os.path.join(sys.prefix, "bin")
58-
bin_user = os.path.join(user_site, "bin")
59-
else:
60-
bin_py = os.path.join(sys.prefix, "bin")
61-
bin_user = os.path.join(user_site, "bin")
52+
def get_bin_user():
53+
# type: () -> str
54+
"""Get the user-site scripts directory.
6255
63-
# Forcing to use /usr/local/bin for standard macOS framework installs
64-
# Also log to ~/Library/Logs/ for use with the Console.app log viewer
65-
if sys.platform[:6] == "darwin" and sys.prefix[:16] == "/System/Library/":
66-
bin_py = "/usr/local/bin"
56+
Pip puts the scripts directory in site-packages, not under userbase.
57+
I'm honestly not sure if this is a bug (because ``get_scheme()`` puts it
58+
correctly under userbase), but we need to keep backwards compatibility.
59+
"""
60+
assert user_site is not None, "user site unavailable"
61+
if not WINDOWS:
62+
return os.path.join(user_site, "bin")
63+
# Special case for buildout, which uses 'bin' on Windows too?
64+
if not os.path.exists(os.path.join(sys.prefix, "Scripts")):
65+
os.path.join(user_site, "bin")
66+
return os.path.join(user_site, "Scripts")

0 commit comments

Comments
 (0)