mirror of https://github.com/pypa/pip
Abstract out get_python_lib() usages
This commit is contained in:
parent
7662c5961e
commit
edbda257c6
|
@ -6,7 +6,6 @@ import os
|
|||
import sys
|
||||
import textwrap
|
||||
from collections import OrderedDict
|
||||
from distutils.sysconfig import get_python_lib
|
||||
from sysconfig import get_paths
|
||||
from types import TracebackType
|
||||
from typing import TYPE_CHECKING, Iterable, List, Optional, Set, Tuple, Type
|
||||
|
@ -15,6 +14,7 @@ from pip._vendor.pkg_resources import Requirement, VersionConflict, WorkingSet
|
|||
|
||||
from pip import __file__ as pip_location
|
||||
from pip._internal.cli.spinners import open_spinner
|
||||
from pip._internal.locations import get_platlib, get_prefixed_libs, get_purelib
|
||||
from pip._internal.utils.subprocess import call_subprocess
|
||||
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
|
||||
|
||||
|
@ -34,14 +34,7 @@ class _Prefix:
|
|||
'nt' if os.name == 'nt' else 'posix_prefix',
|
||||
vars={'base': path, 'platbase': path}
|
||||
)['scripts']
|
||||
# Note: prefer distutils' sysconfig to get the
|
||||
# library paths so PyPy is correctly supported.
|
||||
purelib = get_python_lib(plat_specific=False, prefix=path)
|
||||
platlib = get_python_lib(plat_specific=True, prefix=path)
|
||||
if purelib == platlib:
|
||||
self.lib_dirs = [purelib]
|
||||
else:
|
||||
self.lib_dirs = [purelib, platlib]
|
||||
self.lib_dirs = get_prefixed_libs(path)
|
||||
|
||||
|
||||
class BuildEnvironment:
|
||||
|
@ -69,10 +62,7 @@ class BuildEnvironment:
|
|||
# - ensure .pth files are honored
|
||||
# - prevent access to system site packages
|
||||
system_sites = {
|
||||
os.path.normcase(site) for site in (
|
||||
get_python_lib(plat_specific=False),
|
||||
get_python_lib(plat_specific=True),
|
||||
)
|
||||
os.path.normcase(site) for site in (get_purelib(), get_platlib())
|
||||
}
|
||||
self._site_dir = os.path.join(temp_dir.path, 'site')
|
||||
if not os.path.exists(self._site_dir):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import logging
|
||||
import pathlib
|
||||
import sysconfig
|
||||
from typing import Optional
|
||||
from typing import List, Optional
|
||||
|
||||
from pip._internal.models.scheme import SCHEME_KEYS, Scheme
|
||||
|
||||
|
@ -19,6 +19,9 @@ __all__ = [
|
|||
"get_bin_prefix",
|
||||
"get_bin_user",
|
||||
"get_major_minor_version",
|
||||
"get_platlib",
|
||||
"get_prefixed_libs",
|
||||
"get_purelib",
|
||||
"get_scheme",
|
||||
"get_src_prefix",
|
||||
"init_backend",
|
||||
|
@ -102,3 +105,33 @@ def get_bin_user():
|
|||
new = _sysconfig.get_bin_user()
|
||||
_warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="bin_user")
|
||||
return old
|
||||
|
||||
|
||||
def get_purelib():
|
||||
# type: () -> str
|
||||
"""Return the default pure-Python lib location."""
|
||||
old = _distutils.get_purelib()
|
||||
new = _sysconfig.get_purelib()
|
||||
_warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="purelib")
|
||||
return old
|
||||
|
||||
|
||||
def get_platlib():
|
||||
# type: () -> str
|
||||
"""Return the default platform-shared lib location."""
|
||||
old = _distutils.get_platlib()
|
||||
new = _sysconfig.get_platlib()
|
||||
_warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="platlib")
|
||||
return old
|
||||
|
||||
|
||||
def get_prefixed_libs(prefix):
|
||||
# type: (str) -> List[str]
|
||||
"""Return the lib locations under ``prefix``."""
|
||||
old_pure, old_plat = _distutils.get_prefixed_libs(prefix)
|
||||
new_pure, new_plat = _sysconfig.get_prefixed_libs(prefix)
|
||||
_warn_if_mismatch(old_pure, new_pure, key="prefixed-purelib")
|
||||
_warn_if_mismatch(old_plat, new_plat, key="prefixed-platlib")
|
||||
if old_pure == old_plat:
|
||||
return [old_pure]
|
||||
return [old_pure, old_plat]
|
||||
|
|
|
@ -9,7 +9,8 @@ import sys
|
|||
from distutils.cmd import Command as DistutilsCommand
|
||||
from distutils.command.install import SCHEME_KEYS
|
||||
from distutils.command.install import install as distutils_install_command
|
||||
from typing import Dict, List, Optional, Union, cast
|
||||
from distutils.sysconfig import get_python_lib
|
||||
from typing import Dict, List, Optional, Tuple, Union, cast
|
||||
|
||||
from pip._internal.models.scheme import Scheme
|
||||
from pip._internal.utils.compat import WINDOWS
|
||||
|
@ -145,3 +146,21 @@ def get_bin_prefix():
|
|||
def get_bin_user():
|
||||
# type: () -> str
|
||||
return bin_user
|
||||
|
||||
|
||||
def get_purelib():
|
||||
# type: () -> str
|
||||
return get_python_lib(plat_specific=False)
|
||||
|
||||
|
||||
def get_platlib():
|
||||
# type: () -> str
|
||||
return get_python_lib(plat_specific=True)
|
||||
|
||||
|
||||
def get_prefixed_libs(prefix):
|
||||
# type: (str) -> Tuple[str, str]
|
||||
return (
|
||||
get_python_lib(plat_specific=False, prefix=prefix),
|
||||
get_python_lib(plat_specific=True, prefix=prefix),
|
||||
)
|
||||
|
|
|
@ -135,3 +135,19 @@ def get_bin_prefix():
|
|||
|
||||
def get_bin_user():
|
||||
return sysconfig.get_path("scripts", scheme=_infer_scheme("user"))
|
||||
|
||||
|
||||
def get_purelib():
|
||||
# type: () -> str
|
||||
return sysconfig.get_path("purelib")
|
||||
|
||||
|
||||
def get_platlib():
|
||||
# type: () -> str
|
||||
return sysconfig.get_path("platlib")
|
||||
|
||||
|
||||
def get_prefixed_libs(prefix):
|
||||
# type: (str) -> typing.Tuple[str, str]
|
||||
paths = sysconfig.get_paths(vars={"base": prefix, "platbase": prefix})
|
||||
return (paths["purelib"], paths["platlib"])
|
||||
|
|
Loading…
Reference in New Issue