Gentoo Archives: gentoo-commits

From: Brian Dolbec <dolsen@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:repoman commit in: repoman/pym/repoman/modules/linechecks/eapi/
Date: Mon, 11 Sep 2017 21:43:54
Message-Id: 1505146394.fb1afecc6583a10ff477d4f9be600d4252c67b06.dolsen@gentoo
1 commit: fb1afecc6583a10ff477d4f9be600d4252c67b06
2 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
3 AuthorDate: Sat Jul 15 00:20:37 2017 +0000
4 Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
5 CommitDate: Mon Sep 11 16:13:14 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=fb1afecc
7
8 repoman: New linechecks module, eapi
9
10 .../repoman/modules/linechecks/eapi/__init__.py | 51 +++++++++++++
11 .../pym/repoman/modules/linechecks/eapi/checks.py | 83 ++++++++++++++++++++++
12 .../repoman/modules/linechecks/eapi/definition.py | 36 ++++++++++
13 3 files changed, 170 insertions(+)
14
15 diff --git a/repoman/pym/repoman/modules/linechecks/eapi/__init__.py b/repoman/pym/repoman/modules/linechecks/eapi/__init__.py
16 new file mode 100644
17 index 000000000..e598fdfe3
18 --- /dev/null
19 +++ b/repoman/pym/repoman/modules/linechecks/eapi/__init__.py
20 @@ -0,0 +1,51 @@
21 +# Copyright 2015-2016 Gentoo Foundation
22 +# Distributed under the terms of the GNU General Public License v2
23 +
24 +doc = """Eapi plug-in module for repoman LineChecks.
25 +Performs eapi dependant checks on ebuilds."""
26 +__doc__ = doc[:]
27 +
28 +
29 +module_spec = {
30 + 'name': 'eapi',
31 + 'description': doc,
32 + 'provides':{
33 + 'definition-check': {
34 + 'name': "definition",
35 + 'sourcefile': "definition",
36 + 'class': "EapiDefinition",
37 + 'description': doc,
38 + },
39 + 'srcprepare-check': {
40 + 'name': "srcprepare",
41 + 'sourcefile': "checks",
42 + 'class': "UndefinedSrcPrepareSrcConfigurePhases",
43 + 'description': doc,
44 + },
45 + 'eapi3deprecated-check': {
46 + 'name': "eapi3deprecated",
47 + 'sourcefile': "checks",
48 + 'class': "Eapi3DeprecatedFuncs",
49 + 'description': doc,
50 + },
51 + 'pkgpretend-check': {
52 + 'name': "pkgpretend",
53 + 'sourcefile': "checks",
54 + 'class': "UndefinedPkgPretendPhase",
55 + 'description': doc,
56 + },
57 + 'eapi4incompatible-check': {
58 + 'name': "eapi4incompatible",
59 + 'sourcefile': "checks",
60 + 'class': "Eapi4IncompatibleFuncs",
61 + 'description': doc,
62 + },
63 + 'eapi4gonevars-check': {
64 + 'name': "eapi4gonevars",
65 + 'sourcefile': "checks",
66 + 'class': "Eapi4GoneVars",
67 + 'description': doc,
68 + },
69 + }
70 +}
71 +
72
73 diff --git a/repoman/pym/repoman/modules/linechecks/eapi/checks.py b/repoman/pym/repoman/modules/linechecks/eapi/checks.py
74 new file mode 100644
75 index 000000000..de899c061
76 --- /dev/null
77 +++ b/repoman/pym/repoman/modules/linechecks/eapi/checks.py
78 @@ -0,0 +1,83 @@
79 +
80 +import re
81 +
82 +from portage.eapi import (
83 + eapi_has_src_prepare_and_src_configure, eapi_has_dosed_dohard,
84 + eapi_exports_AA, eapi_has_pkg_pretend)
85 +from repoman.modules.linechecks.base import LineCheck
86 +
87 +
88 +# EAPI <2 checks
89 +class UndefinedSrcPrepareSrcConfigurePhases(LineCheck):
90 + repoman_check_name = 'EAPI.incompatible'
91 + src_configprepare_re = re.compile(r'\s*(src_configure|src_prepare)\s*\(\)')
92 +
93 + def check_eapi(self, eapi):
94 + return not eapi_has_src_prepare_and_src_configure(eapi)
95 +
96 + def check(self, num, line):
97 + m = self.src_configprepare_re.match(line)
98 + if m is not None:
99 + return ("'%s'" % m.group(1)) + \
100 + " phase is not defined in EAPI < 2 on line: %d"
101 +
102 +
103 +# EAPI-3 checks
104 +class Eapi3DeprecatedFuncs(LineCheck):
105 + repoman_check_name = 'EAPI.deprecated'
106 + deprecated_commands_re = re.compile(r'^\s*(check_license)\b')
107 +
108 + def check_eapi(self, eapi):
109 + return eapi not in ('0', '1', '2')
110 +
111 + def check(self, num, line):
112 + m = self.deprecated_commands_re.match(line)
113 + if m is not None:
114 + return ("'%s'" % m.group(1)) + \
115 + " has been deprecated in EAPI=3 on line: %d"
116 +
117 +
118 +# EAPI <4 checks
119 +class UndefinedPkgPretendPhase(LineCheck):
120 + repoman_check_name = 'EAPI.incompatible'
121 + pkg_pretend_re = re.compile(r'\s*(pkg_pretend)\s*\(\)')
122 +
123 + def check_eapi(self, eapi):
124 + return not eapi_has_pkg_pretend(eapi)
125 +
126 + def check(self, num, line):
127 + m = self.pkg_pretend_re.match(line)
128 + if m is not None:
129 + return ("'%s'" % m.group(1)) + \
130 + " phase is not defined in EAPI < 4 on line: %d"
131 +
132 +
133 +# EAPI-4 checks
134 +class Eapi4IncompatibleFuncs(LineCheck):
135 + repoman_check_name = 'EAPI.incompatible'
136 + banned_commands_re = re.compile(r'^\s*(dosed|dohard)')
137 +
138 + def check_eapi(self, eapi):
139 + return not eapi_has_dosed_dohard(eapi)
140 +
141 + def check(self, num, line):
142 + m = self.banned_commands_re.match(line)
143 + if m is not None:
144 + return ("'%s'" % m.group(1)) + \
145 + " has been banned in EAPI=4 on line: %d"
146 +
147 +
148 +class Eapi4GoneVars(LineCheck):
149 + repoman_check_name = 'EAPI.incompatible'
150 + undefined_vars_re = re.compile(
151 + r'.*\$(\{(AA|KV|EMERGE_FROM)\}|(AA|KV|EMERGE_FROM))')
152 +
153 + def check_eapi(self, eapi):
154 + # AA, KV, and EMERGE_FROM should not be referenced in EAPI 4 or later.
155 + return not eapi_exports_AA(eapi)
156 +
157 + def check(self, num, line):
158 + m = self.undefined_vars_re.match(line)
159 + if m is not None:
160 + return ("variable '$%s'" % m.group(1)) + \
161 + " is gone in EAPI=4 on line: %d"
162
163 diff --git a/repoman/pym/repoman/modules/linechecks/eapi/definition.py b/repoman/pym/repoman/modules/linechecks/eapi/definition.py
164 new file mode 100644
165 index 000000000..410bad1c7
166 --- /dev/null
167 +++ b/repoman/pym/repoman/modules/linechecks/eapi/definition.py
168 @@ -0,0 +1,36 @@
169 +
170 +from repoman.modules.linechecks.base import LineCheck
171 +from repoman._portage import portage
172 +
173 +
174 +class EapiDefinition(LineCheck):
175 + """
176 + Check that EAPI assignment conforms to PMS section 7.3.1
177 + (first non-comment, non-blank line).
178 + """
179 + repoman_check_name = 'EAPI.definition'
180 + ignore_comment = True
181 + _eapi_re = portage._pms_eapi_re
182 +
183 + def new(self, pkg):
184 + self._cached_eapi = pkg.eapi
185 + self._parsed_eapi = None
186 + self._eapi_line_num = None
187 +
188 + def check(self, num, line):
189 + if self._eapi_line_num is None and line.strip():
190 + self._eapi_line_num = num + 1
191 + m = self._eapi_re.match(line)
192 + if m is not None:
193 + self._parsed_eapi = m.group(2)
194 +
195 + def end(self):
196 + if self._parsed_eapi is None:
197 + if self._cached_eapi != "0":
198 + yield "valid EAPI assignment must occur on or before line: %s" % \
199 + self._eapi_line_num
200 + elif self._parsed_eapi != self._cached_eapi:
201 + yield (
202 + "bash returned EAPI '%s' which does not match "
203 + "assignment on line: %s" %
204 + (self._cached_eapi, self._eapi_line_num))