Skip to content

Commit 0e06452

Browse files
committed
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.
1 parent a7a35dc commit 0e06452

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/pip/_internal/locations/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pip._internal.utils.deprecation import deprecated
1212
from pip._internal.utils.virtualenv import running_under_virtualenv
1313

14-
from . import _distutils, _sysconfig
14+
from . import _sysconfig
1515
from .base import (
1616
USER_CACHE_DIR,
1717
get_major_minor_version,
@@ -241,6 +241,8 @@ def get_scheme(
241241
if _USE_SYSCONFIG:
242242
return new
243243

244+
from . import _distutils
245+
244246
old = _distutils.get_scheme(
245247
dist_name,
246248
user=user,
@@ -405,6 +407,8 @@ def get_bin_prefix() -> str:
405407
if _USE_SYSCONFIG:
406408
return new
407409

410+
from . import _distutils
411+
408412
old = _distutils.get_bin_prefix()
409413
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="bin_prefix"):
410414
_log_context()
@@ -438,6 +442,8 @@ def get_purelib() -> str:
438442
if _USE_SYSCONFIG:
439443
return new
440444

445+
from . import _distutils
446+
441447
old = _distutils.get_purelib()
442448
if _looks_like_deb_system_dist_packages(old):
443449
return old
@@ -452,6 +458,8 @@ def get_platlib() -> str:
452458
if _USE_SYSCONFIG:
453459
return new
454460

461+
from . import _distutils
462+
455463
old = _distutils.get_platlib()
456464
if _looks_like_deb_system_dist_packages(old):
457465
return old
@@ -480,6 +488,8 @@ def get_prefixed_libs(prefix: str) -> List[str]:
480488
if _USE_SYSCONFIG:
481489
return _deduplicated(new_pure, new_plat)
482490

491+
from . import _distutils
492+
483493
old_pure, old_plat = _distutils.get_prefixed_libs(prefix)
484494
old_lib_paths = _deduplicated(old_pure, old_plat)
485495

0 commit comments

Comments
 (0)