|
8 | 8 |
|
9 | 9 | from pip._internal.models.scheme import SCHEME_KEYS, Scheme
|
10 | 10 | from pip._internal.utils.compat import WINDOWS
|
| 11 | +from pip._internal.utils.deprecation import deprecated |
11 | 12 |
|
12 | 13 | from . import _distutils, _sysconfig
|
13 | 14 | from .base import (
|
@@ -99,16 +100,20 @@ def _default_base(*, user: bool) -> str:
|
99 | 100 |
|
100 | 101 |
|
101 | 102 | @functools.lru_cache(maxsize=None)
|
102 |
| -def _warn_if_mismatch(old: pathlib.Path, new: pathlib.Path, *, key: str) -> bool: |
103 |
| - if old == new: |
104 |
| - return False |
| 103 | +def _warn_mismatched(old: pathlib.Path, new: pathlib.Path, *, key: str) -> None: |
105 | 104 | issue_url = "https://github.com/pypa/pip/issues/10151"
|
106 | 105 | message = (
|
107 | 106 | "Value for %s does not match. Please report this to <%s>"
|
108 | 107 | "\ndistutils: %s"
|
109 | 108 | "\nsysconfig: %s"
|
110 | 109 | )
|
111 | 110 | logger.log(_MISMATCH_LEVEL, message, key, issue_url, old, new)
|
| 111 | + |
| 112 | + |
| 113 | +def _warn_if_mismatch(old: pathlib.Path, new: pathlib.Path, *, key: str) -> bool: |
| 114 | + if old == new: |
| 115 | + return False |
| 116 | + _warn_mismatched(old, new, key=key) |
112 | 117 | return True
|
113 | 118 |
|
114 | 119 |
|
@@ -157,12 +162,15 @@ def get_scheme(
|
157 | 162 | )
|
158 | 163 |
|
159 | 164 | base = prefix or home or _default_base(user=user)
|
160 |
| - warned = [] |
| 165 | + warning_contexts = [] |
161 | 166 | for k in SCHEME_KEYS:
|
162 | 167 | # Extra join because distutils can return relative paths.
|
163 | 168 | old_v = pathlib.Path(base, getattr(old, k))
|
164 | 169 | new_v = pathlib.Path(getattr(new, k))
|
165 | 170 |
|
| 171 | + if old_v == new_v: |
| 172 | + continue |
| 173 | + |
166 | 174 | # distutils incorrectly put PyPy packages under ``site-packages/python``
|
167 | 175 | # in the ``posix_home`` scheme, but PyPy devs said they expect the
|
168 | 176 | # directory name to be ``pypy`` instead. So we treat this as a bug fix
|
@@ -221,10 +229,38 @@ def get_scheme(
|
221 | 229 | if skip_sysconfig_abiflag_bug:
|
222 | 230 | continue
|
223 | 231 |
|
224 |
| - warned.append(_warn_if_mismatch(old_v, new_v, key=f"scheme.{k}")) |
| 232 | + warning_contexts.append((old_v, new_v, f"scheme.{k}")) |
225 | 233 |
|
226 |
| - if any(warned): |
227 |
| - _log_context(user=user, home=home, root=root, prefix=prefix) |
| 234 | + if not warning_contexts: |
| 235 | + return old |
| 236 | + |
| 237 | + # Check if this path mismatch is caused by distutils config files. Those |
| 238 | + # files will no longer work once we switch to sysconfig, so this raises a |
| 239 | + # deprecation message for them. |
| 240 | + default_old = _distutils.distutils_scheme( |
| 241 | + dist_name, |
| 242 | + user, |
| 243 | + home, |
| 244 | + root, |
| 245 | + isolated, |
| 246 | + prefix, |
| 247 | + ignore_config_files=True, |
| 248 | + ) |
| 249 | + if any(default_old[k] != getattr(old, k) for k in SCHEME_KEYS): |
| 250 | + deprecated( |
| 251 | + "Configuring installation scheme with distutils config files " |
| 252 | + "is deprecated and will no longer work in the near future. If you " |
| 253 | + "are using a Homebrew or Linuxbrew Python, please see discussion " |
| 254 | + "at https://github.com/Homebrew/homebrew-core/issues/76621", |
| 255 | + replacement=None, |
| 256 | + gone_in=None, |
| 257 | + ) |
| 258 | + return old |
| 259 | + |
| 260 | + # Post warnings about this mismatch so user can report them back. |
| 261 | + for old_v, new_v, key in warning_contexts: |
| 262 | + _warn_mismatched(old_v, new_v, key=key) |
| 263 | + _log_context(user=user, home=home, root=root, prefix=prefix) |
228 | 264 |
|
229 | 265 | return old
|
230 | 266 |
|
|
0 commit comments