fix pip.req import error in pip 10.0.0

This commit is contained in:
Jeff.JF Lin 2018-04-17 18:37:09 +08:00 committed by rallytime
parent c1dc42e67e
commit bd0c23396c
No known key found for this signature in database
GPG Key ID: E8F1A4B90D0DEA19

View File

@ -41,14 +41,18 @@ except ImportError:
if HAS_PIP is True:
try:
import pip.req
from pip.req import InstallRequirement
except ImportError:
HAS_PIP = False
# Remove references to the loaded pip module above so reloading works
import sys
del pip
if 'pip' in sys.modules:
del sys.modules['pip']
# pip 10.0.0 move req module under pip._internal
try:
from pip._internal.req import InstallRequirement
except:
HAS_PIP = False
# Remove references to the loaded pip module above so reloading works
import sys
del pip
if 'pip' in sys.modules:
del sys.modules['pip']
try:
from pip.exceptions import InstallationError
@ -129,7 +133,7 @@ def _check_pkg_version_format(pkg):
logger.debug(
'Installed pip version: {0}'.format(pip.__version__)
)
install_req = pip.req.InstallRequirement.from_line(pkg)
install_req = InstallRequirement.from_line(pkg)
except AttributeError:
logger.debug('Installed pip version is lower than 1.2')
supported_vcs = ('git', 'svn', 'hg', 'bzr')
@ -137,12 +141,12 @@ def _check_pkg_version_format(pkg):
for vcs in supported_vcs:
if pkg.startswith(vcs):
from_vcs = True
install_req = pip.req.InstallRequirement.from_line(
install_req = InstallRequirement.from_line(
pkg.split('{0}+'.format(vcs))[-1]
)
break
else:
install_req = pip.req.InstallRequirement.from_line(pkg)
install_req = InstallRequirement.from_line(pkg)
except (ValueError, InstallationError) as exc:
ret['result'] = False
if not from_vcs and '=' in pkg and '==' not in pkg: