@@ -435,13 +435,40 @@ def _deduplicated(v1: str, v2: str) -> List[str]:
435435 return [v1 , v2 ]
436436
437437
438+ def _looks_like_apple_library (path : str ) -> bool :
439+ """Apple patches sysconfig to *always* look under */Library/Python*."""
440+ if sys .platform [:6 ] != "darwin" :
441+ return False
442+ return path == f"/Library/Python/{ get_major_minor_version ()} /site-packages"
443+
444+
438445def get_prefixed_libs (prefix : str ) -> List [str ]:
439446 """Return the lib locations under ``prefix``."""
440447 new_pure , new_plat = _sysconfig .get_prefixed_libs (prefix )
441448 if _USE_SYSCONFIG :
442449 return _deduplicated (new_pure , new_plat )
443450
444451 old_pure , old_plat = _distutils .get_prefixed_libs (prefix )
452+ old_lib_paths = _deduplicated (old_pure , old_plat )
453+
454+ # Apple's Python (shipped with Xcode and Command Line Tools) hard-code
455+ # platlib and purelib to '/Library/Python/X.Y/site-packages'. This will
456+ # cause serious build isolation bugs when Apple starts shipping 3.10 because
457+ # pip will install build backends to the wrong location. This tells users
458+ # who is at fault so Apple may notice it and fix the issue in time.
459+ if all (_looks_like_apple_library (p ) for p in old_lib_paths ):
460+ deprecated (
461+ reason = (
462+ "Python distributed by Apple's Command Line Tools incorrectly "
463+ "patches sysconfig to always point to '/Library/Python'. This "
464+ "will cause build isolation to operate incorrectly on Python "
465+ "3.10 or later. Please help report this to Apple so they can "
466+ "fix this. https://developer.apple.com/bug-reporting/"
467+ ),
468+ replacement = None ,
469+ gone_in = None ,
470+ )
471+ return old_lib_paths
445472
446473 warned = [
447474 _warn_if_mismatch (
@@ -458,4 +485,4 @@ def get_prefixed_libs(prefix: str) -> List[str]:
458485 if any (warned ):
459486 _log_context (prefix = prefix )
460487
461- return _deduplicated ( old_pure , old_plat )
488+ return old_lib_paths
0 commit comments