diff --git a/src/pip/_internal/cache.py b/src/pip/_internal/cache.py index 930205f6461..8c2041527c1 100644 --- a/src/pip/_internal/cache.py +++ b/src/pip/_internal/cache.py @@ -8,15 +8,14 @@ import json import logging import os -import sys from pip._vendor.packaging.utils import canonicalize_name from pip._internal.exceptions import InvalidWheelFilename from pip._internal.models.link import Link from pip._internal.models.wheel import Wheel +from pip._internal.pep425tags import interpreter_name, interpreter_version from pip._internal.utils.compat import expanduser -from pip._internal.utils.misc import interpreter_name from pip._internal.utils.temp_dir import TempDirectory from pip._internal.utils.typing import MYPY_CHECK_RUNNING from pip._internal.utils.urls import path_to_url @@ -104,11 +103,8 @@ def _get_cache_path_parts(self, link): # depending on the python version their setup.py is being run on, # and don't encode the difference in compatibility tags. # https://github.com/pypa/pip/issues/7296 - key_parts["interpreter"] = "{}-{}.{}".format( - interpreter_name(), - sys.version_info[0], - sys.version_info[1], - ) + key_parts["interpreter_name"] = interpreter_name() + key_parts["interpreter_version"] = interpreter_version() # Encode our key url with sha224, we'll use this because it has similar # security properties to sha256, but with a shorter total output (and diff --git a/src/pip/_internal/pep425tags.py b/src/pip/_internal/pep425tags.py index b8aba326c71..3a291ebaeb1 100644 --- a/src/pip/_internal/pep425tags.py +++ b/src/pip/_internal/pep425tags.py @@ -54,6 +54,9 @@ def get_abbr_impl(): return pyimpl +interpreter_name = get_abbr_impl + + def version_info_to_nodot(version_info): # type: (Tuple[int, ...]) -> str # Only use up to the first two numbers. @@ -69,6 +72,9 @@ def get_impl_ver(): return impl_ver +interpreter_version = get_impl_ver + + def get_impl_version_info(): # type: () -> Tuple[int, ...] """Return sys.version_info-like tuple for use in decrementing the minor diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py index 9a802556269..85acab856b0 100644 --- a/src/pip/_internal/utils/misc.py +++ b/src/pip/_internal/utils/misc.py @@ -11,7 +11,6 @@ import io import logging import os -import platform import posixpath import shutil import stat @@ -880,13 +879,3 @@ def hash_file(path, blocksize=1 << 20): length += len(block) h.update(block) return (h, length) # type: ignore - - -def interpreter_name(): - # type: () -> str - try: - name = sys.implementation.name # type: ignore - except AttributeError: # pragma: no cover - # Python 2.7 compatibility. - name = platform.python_implementation().lower() - return name