|
7 | 7 | from typing import List, Optional
|
8 | 8 |
|
9 | 9 | from pip._internal.models.scheme import SCHEME_KEYS, Scheme
|
| 10 | +from pip._internal.utils.deprecation import deprecated |
10 | 11 |
|
11 | 12 | from . import _distutils, _sysconfig
|
12 | 13 | from .base import (
|
@@ -51,16 +52,20 @@ def _default_base(*, user: bool) -> str:
|
51 | 52 |
|
52 | 53 |
|
53 | 54 | @functools.lru_cache(maxsize=None)
|
54 |
| -def _warn_if_mismatch(old: pathlib.Path, new: pathlib.Path, *, key: str) -> bool: |
55 |
| - if old == new: |
56 |
| - return False |
| 55 | +def _warn_mismatched(old: pathlib.Path, new: pathlib.Path, *, key: str) -> None: |
57 | 56 | issue_url = "https://github.com/pypa/pip/issues/10151"
|
58 | 57 | message = (
|
59 | 58 | "Value for %s does not match. Please report this to <%s>"
|
60 | 59 | "\ndistutils: %s"
|
61 | 60 | "\nsysconfig: %s"
|
62 | 61 | )
|
63 | 62 | logger.log(_MISMATCH_LEVEL, message, key, issue_url, old, new)
|
| 63 | + |
| 64 | + |
| 65 | +def _warn_if_mismatch(old: pathlib.Path, new: pathlib.Path, *, key: str) -> bool: |
| 66 | + if old == new: |
| 67 | + return False |
| 68 | + _warn_mismatched(old, new, key=key) |
64 | 69 | return True
|
65 | 70 |
|
66 | 71 |
|
@@ -109,12 +114,15 @@ def get_scheme(
|
109 | 114 | )
|
110 | 115 |
|
111 | 116 | base = prefix or home or _default_base(user=user)
|
112 |
| - warned = [] |
| 117 | + warning_contexts = [] |
113 | 118 | for k in SCHEME_KEYS:
|
114 | 119 | # Extra join because distutils can return relative paths.
|
115 | 120 | old_v = pathlib.Path(base, getattr(old, k))
|
116 | 121 | new_v = pathlib.Path(getattr(new, k))
|
117 | 122 |
|
| 123 | + if old_v == new_v: |
| 124 | + continue |
| 125 | + |
118 | 126 | # distutils incorrectly put PyPy packages under ``site-packages/python``
|
119 | 127 | # in the ``posix_home`` scheme, but PyPy devs said they expect the
|
120 | 128 | # directory name to be ``pypy`` instead. So we treat this as a bug fix
|
@@ -143,10 +151,38 @@ def get_scheme(
|
143 | 151 | if skip_osx_framework_user_special_case:
|
144 | 152 | continue
|
145 | 153 |
|
146 |
| - warned.append(_warn_if_mismatch(old_v, new_v, key=f"scheme.{k}")) |
| 154 | + warning_contexts.append((old_v, new_v, f"scheme.{k}")) |
147 | 155 |
|
148 |
| - if any(warned): |
149 |
| - _log_context(user=user, home=home, root=root, prefix=prefix) |
| 156 | + if not warning_contexts: |
| 157 | + return old |
| 158 | + |
| 159 | + # Check if this path mismatch is caused by distutils config files. Those |
| 160 | + # files will no longer work once we switch to sysconfig, so this raises a |
| 161 | + # deprecation message for them. |
| 162 | + default_old = _distutils.distutils_scheme( |
| 163 | + dist_name, |
| 164 | + user, |
| 165 | + home, |
| 166 | + root, |
| 167 | + isolated, |
| 168 | + prefix, |
| 169 | + ignore_config_files=True, |
| 170 | + ) |
| 171 | + if any(default_old[k] != getattr(old, k) for k in SCHEME_KEYS): |
| 172 | + deprecated( |
| 173 | + "Configuring installation scheme with distutils config files " |
| 174 | + "is deprecated and will no longer work in the near future. If you " |
| 175 | + "are using a Homebrew or Linuxbrew Python, please see discussion " |
| 176 | + "at https://github.com/Homebrew/homebrew-core/issues/76621", |
| 177 | + replacement=None, |
| 178 | + gone_in=None, |
| 179 | + ) |
| 180 | + return old |
| 181 | + |
| 182 | + # Post warnings about this mismatch so user can report them back. |
| 183 | + for old_v, new_v, key in warning_contexts: |
| 184 | + _warn_mismatched(old_v, new_v, key=key) |
| 185 | + _log_context(user=user, home=home, root=root, prefix=prefix) |
150 | 186 |
|
151 | 187 | return old
|
152 | 188 |
|
|
0 commit comments