summaryrefslogtreecommitdiffstats
path: root/pym/repoman
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-07-08 00:47:31 -0700
committerZac Medico <zmedico@gentoo.org>2011-07-08 00:47:31 -0700
commitcaf6e68cc5fd175a52610bebdec7d354cc7b714a (patch)
tree7f2a1c493beaae6e42068e71a2bd0db1b3028349 /pym/repoman
parentde32b0d92ee28965c137bea637cddf6d8c0679c2 (diff)
downloadportage-caf6e68cc5fd175a52610bebdec7d354cc7b714a.tar.gz
portage-caf6e68cc5fd175a52610bebdec7d354cc7b714a.tar.bz2
portage-caf6e68cc5fd175a52610bebdec7d354cc7b714a.zip
repoman: centralize code for ignoring comments
Diffstat (limited to 'pym/repoman')
-rw-r--r--pym/repoman/checks.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/pym/repoman/checks.py b/pym/repoman/checks.py
index fabf0b3fb..58ac20df0 100644
--- a/pym/repoman/checks.py
+++ b/pym/repoman/checks.py
@@ -16,6 +16,9 @@ class LineCheck(object):
"""Run a check on a line of an ebuild."""
"""A regular expression to determine whether to ignore the line"""
ignore_line = False
+ """True if lines containing nothing more than comments with optional
+ leading whitespace should be ignored"""
+ ignore_comment = True
def new(self, pkg):
pass
@@ -35,7 +38,6 @@ class LineCheck(object):
class PhaseCheck(LineCheck):
""" basic class for function detection """
- ignore_line = re.compile(r'(^\s*#)')
func_end_re = re.compile(r'^\}$')
phases_re = re.compile('(%s)' % '|'.join((
'pkg_pretend', 'pkg_setup', 'src_unpack', 'src_prepare',
@@ -103,6 +105,7 @@ class EbuildWhitespace(LineCheck):
repoman_check_name = 'ebuild.minorsyn'
ignore_line = re.compile(r'(^$)|(^(\t)*#)')
+ ignore_comment = False
leading_spaces = re.compile(r'^[\S\t]')
trailing_whitespace = re.compile(r'.*([\S]$)')
@@ -114,6 +117,7 @@ class EbuildWhitespace(LineCheck):
class EbuildBlankLine(LineCheck):
repoman_check_name = 'ebuild.minorsyn'
+ ignore_comment = False
blank_line = re.compile(r'^$')
def new(self, pkg):
@@ -142,6 +146,7 @@ class EbuildQuote(LineCheck):
_ignored_commands = ["local", "export"] + _message_commands
ignore_line = re.compile(r'(^$)|(^\s*#.*)|(^\s*\w+=.*)' + \
r'|(^\s*(' + "|".join(_ignored_commands) + r')\s+)')
+ ignore_comment = False
var_names = ["D", "DISTDIR", "FILESDIR", "S", "T", "ROOT", "WORKDIR"]
# EAPI=3/Prefix vars
@@ -215,6 +220,7 @@ class EbuildAssignment(LineCheck):
readonly_assignment = re.compile(r'^\s*(export\s+)?(A|CATEGORY|P|PV|PN|PR|PVR|PF|D|WORKDIR|FILESDIR|FEATURES|USE)=')
line_continuation = re.compile(r'([^#]*\S)(\s+|\t)\\$')
ignore_line = re.compile(r'(^$)|(^(\t)*#)')
+ ignore_comment = False
def __init__(self):
self.previous_line = None
@@ -448,7 +454,6 @@ class InheritAutotools(LineCheck):
"""
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",
@@ -582,7 +587,6 @@ class SrcUnpackPatches(PhaseCheck):
class BuiltWithUse(LineCheck):
repoman_check_name = 'ebuild.minorsyn'
- ignore_line = re.compile(r'^\s*#')
re = re.compile('^.*built_with_use')
error = errors.BUILT_WITH_USE
@@ -601,7 +605,6 @@ class DeprecatedHasq(LineCheck):
# EAPI-3 checks
class Eapi3DeprecatedFuncs(LineCheck):
repoman_check_name = 'EAPI.deprecated'
- ignore_line = re.compile(r'(^\s*#)')
deprecated_commands_re = re.compile(r'^\s*(check_license)\b')
def check_eapi(self, eapi):
@@ -616,7 +619,6 @@ class Eapi3DeprecatedFuncs(LineCheck):
# EAPI-4 checks
class Eapi4IncompatibleFuncs(LineCheck):
repoman_check_name = 'EAPI.incompatible'
- ignore_line = re.compile(r'(^\s*#)')
banned_commands_re = re.compile(r'^\s*(dosed|dohard)')
def check_eapi(self, eapi):
@@ -630,7 +632,6 @@ class Eapi4IncompatibleFuncs(LineCheck):
class Eapi4GoneVars(LineCheck):
repoman_check_name = 'EAPI.incompatible'
- ignore_line = re.compile(r'(^\s*#)')
undefined_vars_re = re.compile(r'.*\$(\{(AA|KV|EMERGE_FROM)\}|(AA|KV|EMERGE_FROM))')
def check_eapi(self, eapi):
@@ -667,6 +668,7 @@ _constant_checks = tuple((c() for c in (
DeprecatedUseq, DeprecatedHasq)))
_here_doc_re = re.compile(r'.*\s<<[-]?(\w+)$')
+_ignore_comment_re = re.compile(r'^\s*#')
def run_checks(contents, pkg):
checks = _constant_checks
@@ -687,7 +689,10 @@ def run_checks(contents, pkg):
if here_doc_delim is None:
# We're not in a here-document.
+ is_comment = _ignore_comment_re.match(line) is not None
for lc in checks:
+ if is_comment and lc.ignore_comment:
+ continue
if lc.check_eapi(pkg.metadata['EAPI']):
ignore = lc.ignore_line
if not ignore or not ignore.match(line):