From eca8282d6d3b5011ec2660c288c1b768c1731cb6 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 19 Jun 2008 05:01:18 +0000 Subject: Refactor the 'inherit.autotools' and 'IUSE.undefined' checks into classes derived from LineCheck. svn path=/main/trunk/; revision=10723 --- pym/repoman/checks.py | 92 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 26 deletions(-) (limited to 'pym/repoman') diff --git a/pym/repoman/checks.py b/pym/repoman/checks.py index b4caff27f..afe5c8658 100644 --- a/pym/repoman/checks.py +++ b/pym/repoman/checks.py @@ -16,11 +16,17 @@ class LineCheck(object): """A regular expression to determine whether to ignore the line""" ignore_line = False + def new(self): + pass + def check(self, num, line): """Run the check on line and return error if there is one""" if self.re.match(line): return self.error + def end(self): + pass + class EbuildHeader(LineCheck): """Ensure ebuilds have proper headers Copyright header errors @@ -211,44 +217,78 @@ class EbuildQuotedA(LineCheck): if match: return "Quoted \"${A}\" on line: %d" +class InheritAutotools(LineCheck): + """ + Make sure appropriate functions are called in + ebuilds that inherit autotools.eclass. + """ + + repoman_check_name = 'inherit.autotools' + ignore_line = re.compile(r'(^|\s*)#') + _inherit_autotools_re = re.compile(r'^\s*inherit\s(.*\s)?autotools(\s|$)') + _autotools_funcs = ( + "eaclocal", "eautoconf", "eautoheader", + "eautomake", "eautoreconf", "_elibtoolize") + _autotools_func_re = re.compile(r'(^|\s)(' + \ + "|".join(_autotools_funcs) + ')(\s|$)') + + def new(self): + self._inherit_autotools = None + self._autotools_func_call = None + + def check(self, num, line): + if self._inherit_autotools is None: + self._inherit_autotools = self._inherit_autotools_re.match(line) + if self._inherit_autotools is not None and \ + self._autotools_func_call is None: + self._autotools_func_call = self._autotools_func_re.search(line) + + def end(self): + if self._inherit_autotools and self._autotools_func_call is None: + yield 'no eauto* function called' + +class IUseUndefined(LineCheck): + """ + Make sure the ebuild defines IUSE (style guideline + says to define IUSE even when empty). + """ + + repoman_check_name = 'IUSE.undefined' + _iuse_def_re = re.compile(r'^IUSE=.*') + + def new(self): + self._iuse_def = None + + def check(self, num, line): + if self._iuse_def is None: + self._iuse_def = self._iuse_def_re.match(line) + + def end(self): + if self._iuse_def is None: + yield 'IUSE is not defined' + _constant_checks = tuple((c() for c in ( EbuildWhitespace, EbuildQuote, EbuildAssignment, EbuildUselessDodoc, EbuildUselessCdS, EbuildNestedDie, - EbuildPatches, EbuildQuotedA))) - -_iuse_def_re = re.compile(r'^IUSE=.*') -_comment_re = re.compile(r'(^|\s*)#') -_inherit_autotools_re = re.compile(r'^\s*inherit\s(.*\s)?autotools(\s|$)') -_autotools_funcs = ( - "eaclocal", "eautoconf", "eautoheader", - "eautomake", "eautoreconf", "_elibtoolize") -_autotools_func_re = re.compile(r'(^|\s)(' + \ - "|".join(_autotools_funcs) + ')(\s|$)') + EbuildPatches, EbuildQuotedA, + IUseUndefined, InheritAutotools))) def run_checks(contents, pkg): checks = list(_constant_checks) checks.append(EbuildHeader(pkg.mtime)) - iuse_def = None - inherit_autotools = None - autotools_func_call = None + + for lc in checks: + lc.new() for num, line in enumerate(contents): - comment = _comment_re.match(line) - if comment is None: - if inherit_autotools is None: - inherit_autotools = _inherit_autotools_re.match(line) - if inherit_autotools is not None and \ - autotools_func_call is None: - autotools_func_call = _autotools_func_re.search(line) - if iuse_def is None: - iuse_def = _iuse_def_re.match(line) for lc in checks: ignore = lc.ignore_line if not ignore or not ignore.match(line): e = lc.check(num, line) if e: yield lc.repoman_check_name, e % (num + 1) - if iuse_def is None: - yield 'IUSE.undefined', 'IUSE is not defined' - if inherit_autotools and autotools_func_call is None: - yield 'inherit.autotools', 'no eauto* function called' + for lc in checks: + i = lc.end() + if i is not None: + for e in i: + yield lc.repoman_check_name, e -- cgit v1.2.3-1-g7c22