On 05/23/2012 12:21 PM, Mike Frysinger wrote: > Rather than copying & pasting the same behavior for the different eclass > checks, add a common class for them to extend. This makes adding more > eclass checks trivial, and keeps down bitrot. > > This does abuse the checking interface slightly -- the eclass will change > its category between unused and missing based on the checks. > > URL: https://bugs.gentoo.org/417159 > URL: https://bugs.gentoo.org/417231
It's fragile to keep all of these eclass interface definitions hardcoded in python. For example, the _comprehensive checks are going to start triggering repoman warnings every time that we add a new function to an eclass. If we keep the eclass interface definitions in the tree with the eclasses, then it will solve this problem, and it will also be possible for overlays to fork eclasses and tweak interfaces. > def new(self, pkg): > - self._inherit_autotools = None > - self._autotools_func_call = None > - self._disabled = > self._exempt_eclasses.intersection(pkg.inherited) > + self.repoman_check_name = 'inherit.missing' > + self._inherit_re = re.compile(r'^\s*inherit\s(.*\s)?%s(\s|$)' % > self._eclass) > + self._func_re = re.compile(r'\b(' + '|'.join(self._funcs) + > r')\b') The _inherit_re and _func_re regular expressions do not change from one package to the next, so we can compile them inside the __init__ constructor instead, which is only called once in global scope. > + # We can't use pkg.inherited because that tells us all the > eclass that > + # have been inherited and not just the ones we inherit directly. > + self._inherit = False > + self._func_call = False > + if '_exempt_eclasses' in dir(self): > + self._disabled = > self._exempt_eclasses.intersection(pkg.inherited) > + else: > + self._disabled = False It's more efficient to use hasattr(self, '_exempt_eclasses') than to use '_exempt_eclasses' in dir(self). -- Thanks, Zac