From aa9b6f66f0cd207db2822015e7548a04c5824458 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Sat, 29 Jan 2022 14:07:31 +0800 Subject: [PATCH] Disable location warning for Python < 3.10 --- src/pip/_internal/locations/__init__.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/pip/_internal/locations/__init__.py b/src/pip/_internal/locations/__init__.py index 6aeb64e79ec..fb1d7d87a80 100644 --- a/src/pip/_internal/locations/__init__.py +++ b/src/pip/_internal/locations/__init__.py @@ -38,30 +38,37 @@ 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. + """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. """ if hasattr(sysconfig, "_PIP_USE_SYSCONFIG"): return bool(sysconfig._PIP_USE_SYSCONFIG) # type: ignore [attr-defined] - return sys.version_info >= (3, 10) + return _USE_SYSCONFIG_DEFAULT -# This is a function for testability, but should be constant during any one run. _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 + def _looks_like_bpo_44860() -> bool: """The resolution to bpo-44860 will change this incorrect platlib.