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):
|
def pkg_info(project_name=None, include_extras=False):
|
||||||
if project_name is None:
|
if project_name is None:
|
||||||
project_name = 'Mopidy'
|
project_name = 'Mopidy'
|
||||||
distribution = pkg_resources.get_distribution(project_name)
|
try:
|
||||||
extras = include_extras and distribution.extras or []
|
distribution = pkg_resources.get_distribution(project_name)
|
||||||
dependencies = [
|
extras = include_extras and distribution.extras or []
|
||||||
pkg_info(d) for d in distribution.requires(extras)]
|
dependencies = [
|
||||||
return {
|
pkg_info(d) for d in distribution.requires(extras)]
|
||||||
'name': distribution.project_name,
|
return {
|
||||||
'version': distribution.version,
|
'name': project_name,
|
||||||
'path': distribution.location,
|
'version': distribution.version,
|
||||||
'dependencies': dependencies,
|
'path': distribution.location,
|
||||||
}
|
'dependencies': dependencies,
|
||||||
|
}
|
||||||
|
except pkg_resources.ResolutionError:
|
||||||
|
return {
|
||||||
|
'name': project_name,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def gstreamer_info():
|
def gstreamer_info():
|
||||||
|
|||||||
@ -7,6 +7,7 @@ pygst.require('0.10')
|
|||||||
import gst
|
import gst
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
from mopidy.utils import deps
|
from mopidy.utils import deps
|
||||||
|
|
||||||
@ -107,3 +108,23 @@ class DepsTest(unittest.TestCase):
|
|||||||
dep_info_setuptools = dep_info_pykka['dependencies'][0]
|
dep_info_setuptools = dep_info_pykka['dependencies'][0]
|
||||||
self.assertEquals('setuptools', dep_info_setuptools['name'])
|
self.assertEquals('setuptools', dep_info_setuptools['name'])
|
||||||
self.assertEquals('0.6', dep_info_setuptools['version'])
|
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