Make InheritDeprecated check for direct inherits, and give line numbers
authorZac Medico <zmedico@gentoo.org>
Sun, 22 Aug 2010 19:43:09 +0000 (12:43 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 22 Aug 2010 19:43:09 +0000 (12:43 -0700)
in error messages.

pym/repoman/checks.py

index f3ab6e4c2d9ae5885adb2365c2d26b3b063c68d1..41235c5fadba46690f74b69929898bf6fd50c0bd 100644 (file)
@@ -361,33 +361,53 @@ class ImplicitRuntimeDeps(LineCheck):
                        yield 'RDEPEND is not explicitly assigned'
 
 class InheritDeprecated(LineCheck):
-       """Check if ebuild inherits a deprecated eclass"""
+       """Check if ebuild directly inherits a deprecated eclass"""
 
        repoman_check_name = 'inherit.deprecated'
 
-       # deprecated eclass : new eclass (0 if no new eclass)
+       # deprecated eclass : new eclass (False if no new eclass)
        deprecated_classes = {
                "gems": "ruby-fakegem",
                "php-pear": "php-pear-r1",
-               "qt3": 0,
+               "qt3": False,
                "qt4": "qt4-r2",
                "ruby": "ruby-ng",
                "ruby-gnome2": "ruby-ng-gnome2"
                }
 
+       _inherit_re = re.compile(r'^\s*inherit\s(.*)$')
+
        def new(self, pkg):
-               self.matched_eclasses = frozenset(self.deprecated_classes.keys()).intersection(pkg.inherited)
+               self._errors = []
 
        def check(self, num, line):
-               pass
 
-       def end(self):
-               for i in self.matched_eclasses:
-                       if self.deprecated_classes[i] == 0:
-                               yield i + ": deprecated eclass"
+               direct_inherits = None
+               m = self._inherit_re.match(line)
+               if m is not None:
+                       direct_inherits = m.group(1)
+                       if direct_inherits:
+                               direct_inherits = direct_inherits.split()
+
+               if not direct_inherits:
+                       return
+
+               for eclass in direct_inherits:
+                       replacement = self.deprecated_classes.get(eclass)
+                       if replacement is None:
+                               pass
+                       elif replacement is False:
+                               self._errors.append("please migrate from " + \
+                                       "'%s' (no replacement) on line: %d" % (eclass, num + 1))
                        else:
-                               yield "uses deprecated eclass '"+ i +"'. please migrate to '"+ \
-                                       self.deprecated_classes[i] +"'"
+                               self._errors.append("please migrate from " + \
+                                       "'%s' to '%s' on line: %d" % \
+                                       (eclass, replacement, num + 1))
+
+       def end(self):
+               for error in self._errors:
+                       yield error
+               del self._errors
 
 class InheritAutotools(LineCheck):
        """