diff options
| author | Tarek Ziade <tarek@ziade.org> | 2010-10-03 12:30:06 +0200 |
|---|---|---|
| committer | Tarek Ziade <tarek@ziade.org> | 2010-10-03 12:30:06 +0200 |
| commit | 47658d6c3a2d438c7f4e0de7471bb422b1610ca6 (patch) | |
| tree | 7c942b04b0ab01d06b1af54ddcb05fa260281dfa | |
| parent | 09fae4438308a7a316022a0e96afeee28d64a6dd (diff) | |
| download | disutils2-47658d6c3a2d438c7f4e0de7471bb422b1610ca6.tar.gz | |
make sure depgraph don't choke on irrational installed versions
| -rw-r--r-- | distutils2/_backport/tests/fake_dists/choxie-2.0.0.9.dist-info/METADATA | 1 | ||||
| -rw-r--r-- | distutils2/_backport/tests/fake_dists/nut-funkyversion.egg-info | 3 | ||||
| -rw-r--r-- | distutils2/depgraph.py | 15 | ||||
| -rw-r--r-- | distutils2/tests/test_depgraph.py | 35 |
4 files changed, 49 insertions, 5 deletions
diff --git a/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9.dist-info/METADATA b/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9.dist-info/METADATA index 00c3674..418929e 100644 --- a/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9.dist-info/METADATA +++ b/distutils2/_backport/tests/fake_dists/choxie-2.0.0.9.dist-info/METADATA @@ -3,6 +3,7 @@ Name: choxie Version: 2.0.0.9 Summary: Chocolate with a kick! Requires-Dist: towel-stuff (0.1) +Requires-Dist: nut Provides-Dist: truffles (1.0) Obsoletes-Dist: truffles (<=0.8,>=0.5) Obsoletes-Dist: truffles (<=0.9,>=0.6) diff --git a/distutils2/_backport/tests/fake_dists/nut-funkyversion.egg-info b/distutils2/_backport/tests/fake_dists/nut-funkyversion.egg-info new file mode 100644 index 0000000..0c58ec1 --- /dev/null +++ b/distutils2/_backport/tests/fake_dists/nut-funkyversion.egg-info @@ -0,0 +1,3 @@ +Metadata-Version: 1.2 +Name: nut +Version: funkyversion diff --git a/distutils2/depgraph.py b/distutils2/depgraph.py index fee524f..d8e92e3 100644 --- a/distutils2/depgraph.py +++ b/distutils2/depgraph.py @@ -4,7 +4,7 @@ and generate a dependency graph. import sys from StringIO import StringIO from distutils2.errors import DistutilsError -from distutils2.version import VersionPredicate +from distutils2.version import VersionPredicate, IrrationalVersionError __all__ = ['DependencyGraph', 'generate_graph', 'dependent_dists', 'graph_to_dot'] @@ -156,8 +156,17 @@ def generate_graph(dists): graph.add_missing(dist, req) else: matched = False - for (version, provider) in provided[name]: - if predicate.match(version): + for version, provider in provided[name]: + try: + match = predicate.match(version) + except IrrationalVersionError: + # XXX small compat-mode + if version.split(' ' ) == 1: + match = True + else: + match = False + + if match: graph.add_edge(dist, provider, req) matched = True break diff --git a/distutils2/tests/test_depgraph.py b/distutils2/tests/test_depgraph.py index 99ba5ea..abd0836 100644 --- a/distutils2/tests/test_depgraph.py +++ b/distutils2/tests/test_depgraph.py @@ -17,6 +17,8 @@ class DepGraphTestCase(support.LoggingCatcher, DISTROS_DIST = ('choxie', 'grammar', 'towel-stuff') DISTROS_EGG = ('bacon', 'banana', 'strawberry', 'cheese') + BAD_EGGS = ('nut',) + EDGE = re.compile( r'"(?P<from>.*)" -> "(?P<to>.*)" \[label="(?P<label>.*)"\]' ) @@ -53,7 +55,7 @@ class DepGraphTestCase(support.LoggingCatcher, deps = [(x.name, y) for (x,y) in graph.adjacency_list[choxie]] self.checkLists([('towel-stuff', 'towel-stuff (0.1)')], deps) self.assertTrue(choxie in graph.reverse_list[towel]) - self.checkLists(graph.missing[choxie], []) + self.checkLists(graph.missing[choxie], ['nut']) deps = [(x.name, y) for (x,y) in graph.adjacency_list[grammar]] self.checkLists([], deps) @@ -77,7 +79,7 @@ class DepGraphTestCase(support.LoggingCatcher, deps = [(x.name, y) for (x,y) in graph.adjacency_list[choxie]] self.checkLists([('towel-stuff', 'towel-stuff (0.1)')], deps) self.assertTrue(choxie in graph.reverse_list[towel]) - self.checkLists(graph.missing[choxie], []) + self.checkLists(graph.missing[choxie], ['nut']) deps = [(x.name, y) for (x,y) in graph.adjacency_list[grammar]] self.checkLists([('bacon', 'truffles (>=1.2)')], deps) @@ -181,6 +183,35 @@ class DepGraphTestCase(support.LoggingCatcher, self.checkLists(matches, expected) + def test_graph_bad_version_to_dot(self): + expected = ( + ('towel-stuff', 'bacon', 'bacon (<=0.2)'), + ('grammar', 'bacon', 'truffles (>=1.2)'), + ('choxie', 'towel-stuff', 'towel-stuff (0.1)'), + ('banana', 'strawberry', 'strawberry (>=0.5)') + ) + + dists = [] + for name in self.DISTROS_DIST + self.DISTROS_EGG + self.BAD_EGGS: + dist = pkgutil.get_distribution(name, use_egg_info=True) + self.assertNotEqual(dist, None) + dists.append(dist) + + graph = depgraph.generate_graph(dists) + buf = StringIO.StringIO() + depgraph.graph_to_dot(graph, buf) + buf.seek(0) + matches = [] + lines = buf.readlines() + for line in lines[1:-1]: # skip the first and the last lines + if line[-1] == '\n': + line = line[:-1] + match = self.EDGE.match(line.strip()) + self.assertTrue(match is not None) + matches.append(match.groups()) + + self.checkLists(matches, expected) + def test_main(self): tempout = StringIO.StringIO() old = sys.stdout |
