更改enroll命名,添加了注释,向get_error_msg中添加了一些错误代码
This commit is contained in:
@@ -38,34 +38,14 @@ __all__ = [
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if os.environ.get("_PIP_LOCATIONS_NO_WARN_ON_MISMATCH"):
|
||||
_MISMATCH_LEVEL = logging.DEBUG
|
||||
else:
|
||||
_MISMATCH_LEVEL = logging.WARNING
|
||||
|
||||
_PLATLIBDIR: str = getattr(sys, "platlibdir", "lib")
|
||||
|
||||
_USE_SYSCONFIG_DEFAULT = sys.version_info >= (3, 10)
|
||||
|
||||
|
||||
def _should_use_sysconfig() -> bool:
|
||||
"""This function determines the value of _USE_SYSCONFIG.
|
||||
|
||||
By default, pip uses sysconfig on Python 3.10+.
|
||||
But Python distributors can override this decision by setting:
|
||||
sysconfig._PIP_USE_SYSCONFIG = True / False
|
||||
Rationale in https://github.com/pypa/pip/issues/10647
|
||||
|
||||
This is a function for testability, but should be constant during any one
|
||||
run.
|
||||
"""
|
||||
return bool(getattr(sysconfig, "_PIP_USE_SYSCONFIG", _USE_SYSCONFIG_DEFAULT))
|
||||
|
||||
|
||||
_USE_SYSCONFIG = _should_use_sysconfig()
|
||||
|
||||
# Be noisy about incompatibilities if this platforms "should" be using
|
||||
# sysconfig, but is explicitly opting out and using distutils instead.
|
||||
if _USE_SYSCONFIG_DEFAULT and not _USE_SYSCONFIG:
|
||||
_MISMATCH_LEVEL = logging.WARNING
|
||||
else:
|
||||
_MISMATCH_LEVEL = logging.DEBUG
|
||||
_USE_SYSCONFIG = sys.version_info >= (3, 10)
|
||||
|
||||
|
||||
def _looks_like_bpo_44860() -> bool:
|
||||
@@ -84,8 +64,8 @@ def _looks_like_bpo_44860() -> bool:
|
||||
|
||||
def _looks_like_red_hat_patched_platlib_purelib(scheme: Dict[str, str]) -> bool:
|
||||
platlib = scheme["platlib"]
|
||||
if "/$platlibdir/" in platlib:
|
||||
platlib = platlib.replace("/$platlibdir/", f"/{_PLATLIBDIR}/")
|
||||
if "/$platlibdir/" in platlib and hasattr(sys, "platlibdir"):
|
||||
platlib = platlib.replace("/$platlibdir/", f"/{sys.platlibdir}/")
|
||||
if "/lib64/" not in platlib:
|
||||
return False
|
||||
unpatched = platlib.replace("/lib64/", "/lib/")
|
||||
@@ -135,22 +115,6 @@ def _looks_like_red_hat_scheme() -> bool:
|
||||
)
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=None)
|
||||
def _looks_like_slackware_scheme() -> bool:
|
||||
"""Slackware patches sysconfig but fails to patch distutils and site.
|
||||
|
||||
Slackware changes sysconfig's user scheme to use ``"lib64"`` for the lib
|
||||
path, but does not do the same to the site module.
|
||||
"""
|
||||
if user_site is None: # User-site not available.
|
||||
return False
|
||||
try:
|
||||
paths = sysconfig.get_paths(scheme="posix_user", expand=False)
|
||||
except KeyError: # User-site not available.
|
||||
return False
|
||||
return "/lib64/" in paths["purelib"] and "/lib64/" not in user_site
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=None)
|
||||
def _looks_like_msys2_mingw_scheme() -> bool:
|
||||
"""MSYS2 patches distutils and sysconfig to use a UNIX-like scheme.
|
||||
@@ -306,17 +270,6 @@ def get_scheme(
|
||||
if skip_bpo_44860:
|
||||
continue
|
||||
|
||||
# Slackware incorrectly patches posix_user to use lib64 instead of lib,
|
||||
# but not usersite to match the location.
|
||||
skip_slackware_user_scheme = (
|
||||
user
|
||||
and k in ("platlib", "purelib")
|
||||
and not WINDOWS
|
||||
and _looks_like_slackware_scheme()
|
||||
)
|
||||
if skip_slackware_user_scheme:
|
||||
continue
|
||||
|
||||
# Both Debian and Red Hat patch Python to place the system site under
|
||||
# /usr/local instead of /usr. Debian also places lib in dist-packages
|
||||
# instead of site-packages, but the /usr/local check should cover it.
|
||||
@@ -467,13 +420,6 @@ def _deduplicated(v1: str, v2: str) -> List[str]:
|
||||
return [v1, v2]
|
||||
|
||||
|
||||
def _looks_like_apple_library(path: str) -> bool:
|
||||
"""Apple patches sysconfig to *always* look under */Library/Python*."""
|
||||
if sys.platform[:6] != "darwin":
|
||||
return False
|
||||
return path == f"/Library/Python/{get_major_minor_version()}/site-packages"
|
||||
|
||||
|
||||
def get_prefixed_libs(prefix: str) -> List[str]:
|
||||
"""Return the lib locations under ``prefix``."""
|
||||
new_pure, new_plat = _sysconfig.get_prefixed_libs(prefix)
|
||||
@@ -481,26 +427,6 @@ def get_prefixed_libs(prefix: str) -> List[str]:
|
||||
return _deduplicated(new_pure, new_plat)
|
||||
|
||||
old_pure, old_plat = _distutils.get_prefixed_libs(prefix)
|
||||
old_lib_paths = _deduplicated(old_pure, old_plat)
|
||||
|
||||
# Apple's Python (shipped with Xcode and Command Line Tools) hard-code
|
||||
# platlib and purelib to '/Library/Python/X.Y/site-packages'. This will
|
||||
# cause serious build isolation bugs when Apple starts shipping 3.10 because
|
||||
# pip will install build backends to the wrong location. This tells users
|
||||
# who is at fault so Apple may notice it and fix the issue in time.
|
||||
if all(_looks_like_apple_library(p) for p in old_lib_paths):
|
||||
deprecated(
|
||||
reason=(
|
||||
"Python distributed by Apple's Command Line Tools incorrectly "
|
||||
"patches sysconfig to always point to '/Library/Python'. This "
|
||||
"will cause build isolation to operate incorrectly on Python "
|
||||
"3.10 or later. Please help report this to Apple so they can "
|
||||
"fix this. https://developer.apple.com/bug-reporting/"
|
||||
),
|
||||
replacement=None,
|
||||
gone_in=None,
|
||||
)
|
||||
return old_lib_paths
|
||||
|
||||
warned = [
|
||||
_warn_if_mismatch(
|
||||
@@ -517,4 +443,4 @@ def get_prefixed_libs(prefix: str) -> List[str]:
|
||||
if any(warned):
|
||||
_log_context(prefix=prefix)
|
||||
|
||||
return old_lib_paths
|
||||
return _deduplicated(old_pure, old_plat)
|
||||
|
||||
Reference in New Issue
Block a user