Coverage for src/hooks/configurations.py: 0.00%
22 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-08 13:49 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-08 13:49 +0000
1#!/usr/bin/env python3
3# Standard libraries
4from typing import List, NamedTuple
6# Changes regex type
7ChangesRegex = str
9# Changes parsers class
10class ChangesParsers(NamedTuple):
11 match: str
12 groups: List[int]
13 commit_type: str
15# Changes evaluator class
16class ChangesEvaluator(NamedTuple):
17 changes: List[ChangesRegex]
18 parsers: List[ChangesParsers]
20# Changes types class
21class ChangesType(NamedTuple):
22 commit_type: str
23 changes: List[ChangesRegex]
25# Changes matcher class
26class ChangesMatcher(NamedTuple):
27 commit_scope: str
28 types: List[ChangesType]
30# Commits changes constants
31COMMITS_CHANGES_PATTERN: str = r'^#\s*(new file|modified|deleted|renamed|copied):\s*(.* -> |)(.+)$'
32COMMITS_CHANGES_SECTION: str = '# Changes to be committed:'
34# Commits comments constants
35COMMITS_COMMENTS_PREFIX: str = '#'
37# Commits default constants
38COMMITS_DEFAULT_BODY: str = '# Issue: #...'
39COMMITS_DEFAULT_SCOPE: str = 'scope'
40COMMITS_DEFAULT_SUBJECT: str = ''
41COMMITS_DEFAULT_TYPE: str = 'type'
43# Commits footers constants
44COMMITS_FOOTER_SIGNOFF: str = 'Signed-off-by: '
46# Commits message constants
47COMMITS_MESSAGE_EOL: str = '\n'
49# Commitizen constants
50COMMITIZEN_CONFIGURATION_FILE: str = '.cz.yaml'
52# Regex constants
53REGEX_EXT: str = r'[^/.]*'
54REGEX_FOLDER: str = r'[^/]+?'
55REGEX_STEM: str = r'[^/]+?'
56REGEX_STEM_VISIBLE: str = r'[^/]{1}[^/]+?'
58# Changes evaluators constants # pylint: disable=line-too-long
59CHANGES_EVALUATORS: List[ChangesEvaluator] = [
60 # Sources
61 ChangesEvaluator(
62 changes=[
63 r'^sources/|^src/',
64 ],
65 parsers=[
66 ChangesParsers(
67 match=
68 fr'(({REGEX_FOLDER})/)??(({REGEX_FOLDER})/)?({REGEX_STEM_VISIBLE})\.{REGEX_EXT}$',
69 groups=[5, 4, 2],
70 commit_type='fix',
71 ),
72 ],
73 ),
74 # Documentations
75 ChangesEvaluator(
76 changes=[
77 r'^docs/',
78 ],
79 parsers=[
80 ChangesParsers(
81 match=
82 fr'(({REGEX_FOLDER})/)??(({REGEX_FOLDER})/)?({REGEX_STEM_VISIBLE})(\.{REGEX_EXT})?$',
83 groups=[5, 4, 2],
84 commit_type='docs',
85 ),
86 ],
87 ),
88 # Containers
89 ChangesEvaluator(
90 changes=[
91 r'^containers/',
92 ],
93 parsers=[
94 ChangesParsers(
95 match=
96 fr'(({REGEX_FOLDER})/)??(({REGEX_FOLDER})/)?({REGEX_STEM_VISIBLE})(\.{REGEX_EXT})?$',
97 groups=[4, 2],
98 commit_type='build',
99 ),
100 ],
101 ),
102 # Resources
103 ChangesEvaluator(
104 changes=[
105 r'^res/|^resources/',
106 ],
107 parsers=[
108 ChangesParsers(
109 match=
110 fr'(({REGEX_FOLDER})/)??(({REGEX_FOLDER})/)?({REGEX_STEM_VISIBLE})(\.{REGEX_EXT})?$',
111 groups=[4, 2],
112 commit_type='docs',
113 ),
114 ],
115 ),
116 # Templates
117 ChangesEvaluator(
118 changes=[
119 r'^templates/',
120 ],
121 parsers=[
122 ChangesParsers(
123 match=
124 fr'(({REGEX_FOLDER})/)??(({REGEX_FOLDER})/)?({REGEX_STEM_VISIBLE})(\.{REGEX_EXT})?$',
125 groups=[5, 4, 2],
126 commit_type='ci',
127 ),
128 ],
129 ),
130 # Tests
131 ChangesEvaluator(
132 changes=[
133 r'^test[s]?/',
134 ],
135 parsers=[
136 ChangesParsers(
137 match=
138 fr'(({REGEX_FOLDER})/)??(({REGEX_FOLDER})/)?({REGEX_STEM_VISIBLE})(\.{REGEX_EXT})?$',
139 groups=[5, 4, 2],
140 commit_type='test',
141 ),
142 ],
143 ),
144 # Yocto
145 ChangesEvaluator(
146 changes=[
147 fr'conf/(distro|machine)|recipes-{REGEX_STEM}',
148 ],
149 parsers=[
150 ChangesParsers(
151 match=fr'conf/(distro|machine)/{REGEX_STEM}.conf$',
152 groups=[1],
153 commit_type='fix',
154 ),
155 ChangesParsers(
156 match=fr'({REGEX_STEM})/{REGEX_STEM}\.(bb[^/.]*|inc)$',
157 groups=[1],
158 commit_type='fix',
159 ),
160 ChangesParsers(
161 match=fr'recipes-{REGEX_STEM}/({REGEX_STEM})/.*',
162 groups=[1],
163 commit_type='fix',
164 ),
165 ],
166 ),
167]
169# Changes matchers constant
170CHANGES_MATCHERS: List[ChangesMatcher] = [
171 ChangesMatcher(
172 commit_scope='gitlab-ci',
173 types=[
174 ChangesType(
175 commit_type='ci',
176 changes=[
177 r'\.gitlab-ci\.yml$',
178 r'\.gitlab-ci\.d$',
179 ],
180 ),
181 ],
182 ),
183 ChangesMatcher(
184 commit_scope='hooks',
185 types=[
186 ChangesType(
187 commit_type='chore',
188 changes=[
189 r'^\.hooks',
190 ],
191 ),
192 ],
193 ),
194 ChangesMatcher(
195 commit_scope='gitignore',
196 types=[
197 ChangesType(
198 commit_type='chore',
199 changes=[
200 r'\.gitignore$',
201 ],
202 ),
203 ],
204 ),
205 ChangesMatcher(
206 commit_scope='submodules',
207 types=[
208 ChangesType(
209 commit_type='chore',
210 changes=[
211 r'\.gitmodules$',
212 ],
213 ),
214 ],
215 ),
216 ChangesMatcher(
217 commit_scope='makefile',
218 types=[
219 ChangesType(
220 commit_type='build',
221 changes=[
222 r'Makefile$',
223 r'\.make$',
224 ],
225 ),
226 ],
227 ),
228 ChangesMatcher(
229 commit_scope='dockerfile',
230 types=[
231 ChangesType(
232 commit_type='build',
233 changes=[
234 r'Dockerfile$',
235 ],
236 ),
237 ],
238 ),
239 ChangesMatcher(
240 commit_scope='commitizen',
241 types=[
242 ChangesType(
243 commit_type='chore',
244 changes=[
245 r'\.cz.*$',
246 ],
247 ),
248 ],
249 ),
250 ChangesMatcher(
251 commit_scope='coveragerc',
252 types=[
253 ChangesType(
254 commit_type='chore',
255 changes=[
256 r'\.coveragerc$',
257 ],
258 ),
259 ],
260 ),
261 ChangesMatcher(
262 commit_scope='mise',
263 types=[
264 ChangesType(
265 commit_type='chore',
266 changes=[
267 r'^(\.config/)?\.?mise(\.[^/]+)?\.(toml|lock)$',
268 r'^(\.config/)?\.?mise/',
269 r'^\.tool-versions$',
270 ],
271 ),
272 ],
273 ),
274 ChangesMatcher(
275 commit_scope='mkdocs',
276 types=[
277 ChangesType(
278 commit_type='docs',
279 changes=[
280 r'^mkdocs\.yml$',
281 ],
282 ),
283 ],
284 ),
285 ChangesMatcher(
286 commit_scope='mypy',
287 types=[
288 ChangesType(
289 commit_type='chore',
290 changes=[
291 r'mypy\.ini$',
292 ],
293 ),
294 ],
295 ),
296 ChangesMatcher(
297 commit_scope='pre-commit',
298 types=[
299 ChangesType(
300 commit_type='chore',
301 changes=[
302 r'\.pre-commit.*$',
303 r'^pre_commit_hooks/',
304 ],
305 ),
306 ],
307 ),
308 ChangesMatcher(
309 commit_scope='requirements',
310 types=[
311 ChangesType(
312 commit_type='build',
313 changes=[
314 r'^requirements/',
315 ],
316 ),
317 ],
318 ),
319 ChangesMatcher(
320 commit_scope='scripts',
321 types=[
322 ChangesType(
323 commit_type='chore',
324 changes=[
325 r'scripts/',
326 ],
327 ),
328 ],
329 ),
330 ChangesMatcher(
331 commit_scope='setup',
332 types=[
333 ChangesType(
334 commit_type='chore',
335 changes=[
336 r'setup\.py$',
337 ],
338 ),
339 ],
340 ),
341 ChangesMatcher(
342 commit_scope='sonar',
343 types=[
344 ChangesType(
345 commit_type='chore',
346 changes=[
347 r'^sonar-project\.properties$',
348 ],
349 ),
350 ],
351 ),
352 ChangesMatcher(
353 commit_scope='tsconfig',
354 types=[
355 ChangesType(
356 commit_type='build',
357 changes=[
358 r'tsconfig\.json$',
359 ],
360 ),
361 ],
362 ),
363 ChangesMatcher(
364 commit_scope='vscode',
365 types=[
366 ChangesType(
367 commit_type='chore',
368 changes=[
369 r'\.vscode/',
370 ],
371 ),
372 ],
373 ),
374 ChangesMatcher(
375 commit_scope='license',
376 types=[
377 ChangesType(
378 commit_type='docs',
379 changes=[
380 r'LICENSE$',
381 r'LICENSE\..*$',
382 ],
383 ),
384 ],
385 ),
386 ChangesMatcher(
387 commit_scope='readme',
388 types=[
389 ChangesType(
390 commit_type='docs',
391 changes=[
392 r'README$',
393 r'README\..*$',
394 ],
395 ),
396 ],
397 ),
398 ChangesMatcher(
399 commit_scope='changelog',
400 types=[
401 ChangesType(
402 commit_type='docs',
403 changes=[
404 r'CHANGELOG$',
405 r'CHANGELOG\..*$',
406 ],
407 ),
408 ],
409 ),
410]