Don't fail if pkg_resources is not importable

This commit is contained in:
Pedro Algarvio 2019-04-15 10:29:41 +01:00
parent a1eb400041
commit 493f493bbe
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF

View file

@ -37,7 +37,7 @@ from salt.version import SaltStackVersion as _SaltStackVersion
from salt.exceptions import CommandExecutionError, CommandNotFoundError
# Import 3rd-party libs
from salt.ext import six
import salt.ext.six as six
# pylint: disable=import-error
try:
import pip
@ -290,8 +290,10 @@ def _pep440_version_cmp(pkg1, pkg2, ignore_epoch=False):
and 1 if version1 > version2. Return None if there was a problem
making the comparison.
'''
normalize = lambda x: six.text_type(x).split('!', 1)[-1] \
if ignore_epoch else six.text_type(x)
if HAS_PKG_RESOURCES is False:
log.warning('The pkg_resources packages was not loaded. Please install setuptools.')
return None
normalize = lambda x: six.text_type(x).split('!', 1)[-1] if ignore_epoch else six.text_type(x)
pkg1 = normalize(pkg1)
pkg2 = normalize(pkg2)