From db49b97f8d9d855482ecdc9a5760d3d620948d1d Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 15 Apr 2012 15:21:49 -0700 Subject: repoman: update EAPI.definition check for PMS The plan is to update PMS section 8.3.1 as discussed here: http://archives.gentoo.org/gentoo-pms/msg_ef7635aa655913f2386e64e385f5a6ae.xml --- pym/repoman/checks.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'pym/repoman') diff --git a/pym/repoman/checks.py b/pym/repoman/checks.py index 50c017af2..c3d110f88 100644 --- a/pym/repoman/checks.py +++ b/pym/repoman/checks.py @@ -283,21 +283,37 @@ class EbuildUselessCdS(LineCheck): self.check_next_line = True class EapiDefinition(LineCheck): - """ Check that EAPI is defined before inherits""" + """ + Check that EAPI assignment conforms to PMS section 8.3.1 + (first non-comment, non-blank line). + """ repoman_check_name = 'EAPI.definition' + ignore_comment = True - eapi_re = re.compile(r'^EAPI=') - inherit_re = re.compile(r'^\s*inherit\s') + # This pattern is specified by PMS section 8.3.1. + _eapi_re = re.compile(r"^[ \t]*EAPI=(['\"]?)([A-Za-z0-9+_.-]*)\1[ \t]*(#.*)?$") def new(self, pkg): - self.inherit_line = None + self._cached_eapi = pkg.metadata['EAPI'] + self._parsed_eapi = None + self._eapi_line_num = None def check(self, num, line): - if self.eapi_re.match(line) is not None: - if self.inherit_line is not None: - return errors.EAPI_DEFINED_AFTER_INHERIT - elif self.inherit_re.match(line) is not None: - self.inherit_line = line + if self._eapi_line_num is None and line.strip(): + self._eapi_line_num = num + 1 + m = self._eapi_re.match(line) + if m is not None: + self._parsed_eapi = m.group(2) + + def end(self): + if self._parsed_eapi is None: + if self._cached_eapi != "0": + yield "valid EAPI assignment must occur on or before line: %d" % \ + self._eapi_line_num + elif self._parsed_eapi != self._cached_eapi: + yield ("bash returned EAPI '%s' which does not match " + "assignment on line: %d") % \ + (self._cached_eapi, self._eapi_line_num) class EbuildPatches(LineCheck): """Ensure ebuilds use bash arrays for PATCHES to ensure white space safety""" -- cgit v1.2.3-1-g7c22