Path: blob/main/test/lib/python3.9/site-packages/pip/_internal/locations/base.py
5170 views
import functools1import os2import site3import sys4import sysconfig5import typing67from pip._internal.utils import appdirs8from pip._internal.utils.virtualenv import running_under_virtualenv910# Application Directories11USER_CACHE_DIR = appdirs.user_cache_dir("pip")1213# FIXME doesn't account for venv linked to global site-packages14site_packages: typing.Optional[str] = sysconfig.get_path("purelib")151617def get_major_minor_version() -> str:18"""19Return the major-minor version of the current Python as a string, e.g.20"3.7" or "3.10".21"""22return "{}.{}".format(*sys.version_info)232425def get_src_prefix() -> str:26if running_under_virtualenv():27src_prefix = os.path.join(sys.prefix, "src")28else:29# FIXME: keep src in cwd for now (it is not a temporary folder)30try:31src_prefix = os.path.join(os.getcwd(), "src")32except OSError:33# In case the current working directory has been renamed or deleted34sys.exit("The folder you are executing pip from can no longer be found.")3536# under macOS + virtualenv sys.prefix is not properly resolved37# it is something like /path/to/python/bin/..38return os.path.abspath(src_prefix)394041try:42# Use getusersitepackages if this is present, as it ensures that the43# value is initialised properly.44user_site: typing.Optional[str] = site.getusersitepackages()45except AttributeError:46user_site = site.USER_SITE474849@functools.lru_cache(maxsize=None)50def is_osx_framework() -> bool:51return bool(sysconfig.get_config_var("PYTHONFRAMEWORK"))525354