Avoid importing distutils globally
The distutils module is deprecated in 3.11 so we should avoid importing
it unless absolutely necessary to avoid emitting superfulous warnings.
@@ -11,7 +11,7 @@ from pip._internal.utils.compat import WINDOWS
from pip._internal.utils.deprecation import deprecated
from pip._internal.utils.virtualenv import running_under_virtualenv
-from . import _distutils, _sysconfig
+from . import _sysconfig
from .base import (
USER_CACHE_DIR,
get_major_minor_version,
@@ -241,6 +241,8 @@ def get_scheme(
if _USE_SYSCONFIG:
return new
+ from . import _distutils
+
old = _distutils.get_scheme(
dist_name,
user=user,
@@ -405,6 +407,8 @@ def get_bin_prefix() -> str:
if _USE_SYSCONFIG:
return new
+ from . import _distutils
+
old = _distutils.get_bin_prefix()
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="bin_prefix"):
_log_context()
@@ -438,6 +442,8 @@ def get_purelib() -> str:
if _USE_SYSCONFIG:
return new
+ from . import _distutils
+
old = _distutils.get_purelib()
if _looks_like_deb_system_dist_packages(old):
return old
@@ -452,6 +458,8 @@ def get_platlib() -> str:
if _USE_SYSCONFIG:
return new
+ from . import _distutils
+
old = _distutils.get_platlib()
if _looks_like_deb_system_dist_packages(old):
return old
@@ -480,6 +488,8 @@ def get_prefixed_libs(prefix: str) -> List[str]:
if _USE_SYSCONFIG:
return _deduplicated(new_pure, new_plat)
+ from . import _distutils
+
old_pure, old_plat = _distutils.get_prefixed_libs(prefix)
old_lib_paths = _deduplicated(old_pure, old_plat)
