mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
User-site special case fixes
This commit is contained in:
parent
7563a9c6cc
commit
1e1289e550
|
@ -5,7 +5,6 @@
|
|||
|
||||
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
|
||||
|
@ -13,26 +12,9 @@ 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 get_major_minor_version, 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")
|
||||
|
||||
# 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"
|
||||
from .base import bin_py, bin_user, get_major_minor_version
|
||||
|
||||
|
||||
def _distutils_scheme(
|
||||
|
|
|
@ -9,7 +9,7 @@ from pip._internal.exceptions import InvalidSchemeCombination, UserInstallationI
|
|||
from pip._internal.models.scheme import SCHEME_KEYS, Scheme
|
||||
from pip._internal.utils.virtualenv import running_under_virtualenv
|
||||
|
||||
from .base import get_major_minor_version
|
||||
from .base import bin_user, get_major_minor_version
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -101,12 +101,22 @@ def get_scheme(
|
|||
|
||||
paths = sysconfig.get_paths(scheme=scheme_name, vars=variables)
|
||||
|
||||
# Special header path for compatibility to distutils.
|
||||
# Pip historically uses a special header path in virtual environments.
|
||||
if running_under_virtualenv():
|
||||
base = variables.get("base", sys.prefix)
|
||||
if user:
|
||||
base = variables.get("userbase", sys.prefix)
|
||||
else:
|
||||
base = variables.get("base", sys.prefix)
|
||||
python_xy = f"python{get_major_minor_version()}"
|
||||
paths["include"] = os.path.join(base, "include", "site", python_xy)
|
||||
|
||||
# Special user scripts path on Windows for compatibility to distutils.
|
||||
# See ``distutils.commands.install.INSTALL_SCHEMES["nt_user"]["scritps"]``.
|
||||
if scheme_name == "nt_user":
|
||||
base = variables.get("userbase", sys.prefix)
|
||||
python_xy = f"Python{sys.version_info.major}{sys.version_info.minor}"
|
||||
paths["scripts"] = os.path.join(base, python_xy, "Scripts")
|
||||
|
||||
scheme = Scheme(
|
||||
platlib=paths["platlib"],
|
||||
purelib=paths["purelib"],
|
||||
|
@ -131,7 +141,10 @@ def get_bin_prefix():
|
|||
|
||||
def get_bin_user():
|
||||
# type: () -> str
|
||||
return sysconfig.get_paths(scheme=_infer_scheme("user"))["scripts"]
|
||||
# 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():
|
||||
|
|
|
@ -5,6 +5,7 @@ import sysconfig
|
|||
import typing
|
||||
|
||||
from pip._internal.utils import appdirs
|
||||
from pip._internal.utils.compat import WINDOWS
|
||||
from pip._internal.utils.virtualenv import running_under_virtualenv
|
||||
|
||||
# Application Directories
|
||||
|
@ -46,3 +47,20 @@ try:
|
|||
user_site = site.getusersitepackages() # type: typing.Optional[str]
|
||||
except AttributeError:
|
||||
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")
|
||||
|
||||
# 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"
|
||||
|
|
Loading…
Reference in a new issue