deps: Survive exceptions from pkg_resources
This commit is contained in:
parent
357c23d0d7
commit
48dfcf6fd1
@ -94,16 +94,21 @@ def python_info():
|
||||
def pkg_info(project_name=None, include_extras=False):
|
||||
if project_name is None:
|
||||
project_name = 'Mopidy'
|
||||
distribution = pkg_resources.get_distribution(project_name)
|
||||
extras = include_extras and distribution.extras or []
|
||||
dependencies = [
|
||||
pkg_info(d) for d in distribution.requires(extras)]
|
||||
return {
|
||||
'name': distribution.project_name,
|
||||
'version': distribution.version,
|
||||
'path': distribution.location,
|
||||
'dependencies': dependencies,
|
||||
}
|
||||
try:
|
||||
distribution = pkg_resources.get_distribution(project_name)
|
||||
extras = include_extras and distribution.extras or []
|
||||
dependencies = [
|
||||
pkg_info(d) for d in distribution.requires(extras)]
|
||||
return {
|
||||
'name': project_name,
|
||||
'version': distribution.version,
|
||||
'path': distribution.location,
|
||||
'dependencies': dependencies,
|
||||
}
|
||||
except pkg_resources.ResolutionError:
|
||||
return {
|
||||
'name': project_name,
|
||||
}
|
||||
|
||||
|
||||
def gstreamer_info():
|
||||
|
||||
@ -7,6 +7,7 @@ pygst.require('0.10')
|
||||
import gst
|
||||
|
||||
import mock
|
||||
import pkg_resources
|
||||
|
||||
from mopidy.utils import deps
|
||||
|
||||
@ -107,3 +108,23 @@ class DepsTest(unittest.TestCase):
|
||||
dep_info_setuptools = dep_info_pykka['dependencies'][0]
|
||||
self.assertEquals('setuptools', dep_info_setuptools['name'])
|
||||
self.assertEquals('0.6', dep_info_setuptools['version'])
|
||||
|
||||
@mock.patch('pkg_resources.get_distribution')
|
||||
def test_pkg_info_for_missing_dist(self, get_distribution_mock):
|
||||
get_distribution_mock.side_effect = pkg_resources.DistributionNotFound
|
||||
|
||||
result = deps.pkg_info()
|
||||
|
||||
self.assertEquals('Mopidy', result['name'])
|
||||
self.assertNotIn('version', result)
|
||||
self.assertNotIn('path', result)
|
||||
|
||||
@mock.patch('pkg_resources.get_distribution')
|
||||
def test_pkg_info_for_wrong_dist_version(self, get_distribution_mock):
|
||||
get_distribution_mock.side_effect = pkg_resources.VersionConflict
|
||||
|
||||
result = deps.pkg_info()
|
||||
|
||||
self.assertEquals('Mopidy', result['name'])
|
||||
self.assertNotIn('version', result)
|
||||
self.assertNotIn('path', result)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user