mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Use find_on_path, extract compatibility check
This commit is contained in:
parent
c55544d83e
commit
9f4f6738a5
2 changed files with 33 additions and 25 deletions
|
@ -28,7 +28,9 @@ from pip.util import (
|
|||
)
|
||||
from pip.req.req_uninstall import UninstallPathSet
|
||||
from pip.vcs import vcs
|
||||
from pip.wheel import move_wheel_files, Wheel, wheel_ext
|
||||
from pip.wheel import (
|
||||
move_wheel_files, Wheel, wheel_ext, wheel_version
|
||||
)
|
||||
|
||||
|
||||
class InstallRequirement(object):
|
||||
|
@ -710,17 +712,9 @@ exec(compile(
|
|||
self.install_editable(install_options, global_options)
|
||||
return
|
||||
if self.is_wheel:
|
||||
wheel_version = pip.wheel.wheel_version(self.source_dir)
|
||||
if ((not wheel_version) or
|
||||
(wheel_version[0] > pip.wheel.VERSION_COMPATIBLE[0])):
|
||||
raise UnsupportedWheel(
|
||||
"%s's wheel version is not compatible with this version "
|
||||
"of pip" % self.name
|
||||
)
|
||||
elif (wheel_version[0] == pip.wheel.VERSION_COMPATIBLE[0] and
|
||||
wheel_version > pip.wheel.VERSION_COMPATIBLE):
|
||||
logger.warn('Installing a newer Wheel-Version: %s'
|
||||
% '.'.join(map(str, wheel_version)))
|
||||
version = wheel_version(self.source_dir)
|
||||
pip.wheel.check_compatibility(version, self.name)
|
||||
|
||||
self.move_wheel_files(self.source_dir, root=root)
|
||||
self.install_succeeded = True
|
||||
return
|
||||
|
@ -1109,8 +1103,8 @@ def parse_editable(editable_req, default_vcs=None):
|
|||
options = _build_editable_options(editable_req)
|
||||
except Exception as exc:
|
||||
raise InstallationError(
|
||||
'--editable=%s error in editable options:%s' % (editable_req, exc))
|
||||
|
||||
'--editable=%s error in editable options:%s' % (editable_req, exc)
|
||||
)
|
||||
if not options or 'egg' not in options:
|
||||
req = _build_req_from_url(editable_req)
|
||||
if not req:
|
||||
|
|
36
pip/wheel.py
36
pip/wheel.py
|
@ -16,13 +16,14 @@ from base64 import urlsafe_b64encode
|
|||
from email.parser import Parser
|
||||
|
||||
from pip.backwardcompat import ConfigParser, StringIO, binary
|
||||
from pip.exceptions import InvalidWheelFilename
|
||||
from pip.exceptions import InvalidWheelFilename, UnsupportedWheel
|
||||
from pip.locations import distutils_scheme
|
||||
from pip.log import logger
|
||||
from pip import pep425tags
|
||||
from pip.util import call_subprocess, normalize_path, make_path_relative
|
||||
from pip._vendor.distlib.scripts import ScriptMaker
|
||||
from pip._vendor.pkg_resources import Distribution, PathMetadata
|
||||
# from pip._vendor.pkg_resources import Distribution, PathMetadata
|
||||
from pip._vendor import pkg_resources
|
||||
|
||||
|
||||
wheel_ext = '.whl'
|
||||
|
@ -404,18 +405,11 @@ def wheel_version(source_dir):
|
|||
Otherwise, return False if we couldn't parse / extract it.
|
||||
"""
|
||||
try:
|
||||
entries = [e for e in os.listdir(source_dir)
|
||||
if e.lower().endswith('.dist-info')]
|
||||
entry = entries[0]
|
||||
fullpath = os.path.join(source_dir, entry)
|
||||
metadata = PathMetadata(source_dir, fullpath)
|
||||
|
||||
dist = Distribution.from_location(
|
||||
source_dir, entry, metadata
|
||||
)
|
||||
dist = [d for d in pkg_resources.find_on_path(None, source_dir)][0]
|
||||
|
||||
wheel_data = dist.get_metadata('WHEEL')
|
||||
wheel_data = Parser().parsestr(wheel_data)
|
||||
|
||||
version = wheel_data['Wheel-Version'].strip()
|
||||
version = tuple(map(int, version.split('.')))
|
||||
return version
|
||||
|
@ -423,6 +417,26 @@ def wheel_version(source_dir):
|
|||
return False
|
||||
|
||||
|
||||
def check_compatibility(version, name):
|
||||
"""
|
||||
Raises errors or warns if called with an incompatible wheel version
|
||||
|
||||
name: name of wheel or package to raise exception about
|
||||
"""
|
||||
if not version:
|
||||
raise UnsupportedWheel(
|
||||
"%s is in an unsupported or invalid wheel" % name
|
||||
)
|
||||
if version[0] > VERSION_COMPATIBLE[0]:
|
||||
raise UnsupportedWheel(
|
||||
"%s's Wheel-Version (%s) is not compatible with this version "
|
||||
"of pip" % (name, '.'.join(map(str, version)))
|
||||
)
|
||||
elif version > VERSION_COMPATIBLE:
|
||||
logger.warn('Installing from a newer Wheel-Version: %s'
|
||||
% '.'.join(map(str, version)))
|
||||
|
||||
|
||||
class Wheel(object):
|
||||
"""A wheel file"""
|
||||
|
||||
|
|
Loading…
Reference in a new issue