pre-commit-crocodile 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. pre_commit_crocodile/__init__.py +5 -0
  2. pre_commit_crocodile/__main__.py +5 -0
  3. pre_commit_crocodile/assets/.cz.yaml +188 -0
  4. pre_commit_crocodile/assets/.pre-commit-config.yaml +68 -0
  5. pre_commit_crocodile/assets/__init__.py +0 -0
  6. pre_commit_crocodile/cli/__init__.py +0 -0
  7. pre_commit_crocodile/cli/entrypoint.py +414 -0
  8. pre_commit_crocodile/cli/main.py +269 -0
  9. pre_commit_crocodile/hooks/__init__.py +0 -0
  10. pre_commit_crocodile/hooks/configurations.py +322 -0
  11. pre_commit_crocodile/hooks/prepare_commit_message.py +258 -0
  12. pre_commit_crocodile/package/__init__.py +0 -0
  13. pre_commit_crocodile/package/bundle.py +34 -0
  14. pre_commit_crocodile/package/settings.py +148 -0
  15. pre_commit_crocodile/package/updates.py +228 -0
  16. pre_commit_crocodile/package/version.py +80 -0
  17. pre_commit_crocodile/prints/__init__.py +0 -0
  18. pre_commit_crocodile/prints/boxes.py +82 -0
  19. pre_commit_crocodile/prints/colors.py +85 -0
  20. pre_commit_crocodile/system/__init__.py +0 -0
  21. pre_commit_crocodile/system/commands.py +90 -0
  22. pre_commit_crocodile/system/platform.py +74 -0
  23. pre_commit_crocodile/types/__init__.py +0 -0
  24. pre_commit_crocodile/types/environments.py +92 -0
  25. pre_commit_crocodile/types/strings.py +152 -0
  26. pre_commit_crocodile-2.0.0.dist-info/LICENSE +201 -0
  27. pre_commit_crocodile-2.0.0.dist-info/METADATA +212 -0
  28. pre_commit_crocodile-2.0.0.dist-info/RECORD +31 -0
  29. pre_commit_crocodile-2.0.0.dist-info/WHEEL +5 -0
  30. pre_commit_crocodile-2.0.0.dist-info/entry_points.txt +3 -0
  31. pre_commit_crocodile-2.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,269 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Standard libraries
4
+ from argparse import (
5
+ _ArgumentGroup,
6
+ _MutuallyExclusiveGroup,
7
+ ArgumentParser,
8
+ Namespace,
9
+ RawTextHelpFormatter,
10
+ )
11
+ from os import environ
12
+ from shutil import get_terminal_size
13
+ from sys import exit as sys_exit
14
+
15
+ # Components
16
+ from ..package.bundle import Bundle
17
+ from ..package.settings import Settings
18
+ from ..package.updates import Updates
19
+ from ..package.version import Version
20
+ from ..prints.colors import Colors
21
+ from ..system.platform import Platform
22
+ from ..types.environments import Environments
23
+ from .entrypoint import Entrypoint
24
+
25
+ # Constants
26
+ HELP_POSITION: int = 23
27
+
28
+ # Main, pylint: disable=too-many-branches,too-many-statements
29
+ def main() -> None:
30
+
31
+ # Variables
32
+ environments: Environments
33
+ group: _ArgumentGroup
34
+ result: Entrypoint.Result = Entrypoint.Result.ERROR
35
+ subgroup: _MutuallyExclusiveGroup
36
+
37
+ # Configure environment variables
38
+ environments = Environments()
39
+
40
+ # Arguments creation
41
+ parser: ArgumentParser = ArgumentParser(
42
+ prog=Bundle.NAME,
43
+ description=f'{Bundle.NAME}: {Bundle.DESCRIPTION}',
44
+ epilog=environments.help(HELP_POSITION),
45
+ add_help=False,
46
+ formatter_class=lambda prog: RawTextHelpFormatter(
47
+ prog,
48
+ max_help_position=HELP_POSITION,
49
+ width=min(
50
+ 120,
51
+ get_terminal_size().columns - 2,
52
+ ),
53
+ ),
54
+ )
55
+
56
+ # Arguments internal definitions
57
+ group = parser.add_argument_group('internal arguments')
58
+ group.add_argument(
59
+ '-h',
60
+ '--help',
61
+ dest='help',
62
+ action='store_true',
63
+ help='Show this help message',
64
+ )
65
+ group.add_argument(
66
+ '--version',
67
+ dest='version',
68
+ action='store_true',
69
+ help='Show the current version',
70
+ )
71
+ group.add_argument(
72
+ '--no-color',
73
+ dest='no_color',
74
+ action='store_true',
75
+ help=f'Disable colors outputs with \'{Bundle.ENV_NO_COLOR}=1\'\n'
76
+ '(or default settings: [themes] > no_color)',
77
+ )
78
+ group.add_argument(
79
+ '--update-check',
80
+ dest='update_check',
81
+ action='store_true',
82
+ help='Check for newer package updates',
83
+ )
84
+ group.add_argument(
85
+ '--settings',
86
+ dest='settings',
87
+ action='store_true',
88
+ help='Show the current settings path and contents',
89
+ )
90
+ group.add_argument(
91
+ '--set',
92
+ dest='set',
93
+ action='store',
94
+ metavar=('GROUP', 'KEY', 'VAL'),
95
+ nargs=3,
96
+ help='Set settings specific \'VAL\' value to [GROUP] > KEY\n' \
97
+ 'or unset by using \'UNSET\' as \'VAL\'',
98
+ )
99
+
100
+ # Arguments modes definitions
101
+ group = parser.add_argument_group('modes arguments')
102
+ subgroup = group.add_mutually_exclusive_group()
103
+ subgroup.add_argument(
104
+ '-l',
105
+ '--list',
106
+ dest='list',
107
+ action='store_true',
108
+ help='List Git hooks installed in sources',
109
+ )
110
+ subgroup.add_argument(
111
+ '-i',
112
+ '--install',
113
+ dest='install',
114
+ action='store_true',
115
+ help='Install dependencies for pre-commit hooks',
116
+ )
117
+ subgroup.add_argument(
118
+ '-c',
119
+ '--configure',
120
+ dest='configure',
121
+ action='store_true',
122
+ help='Update sources with hooks configurations',
123
+ )
124
+ subgroup.add_argument(
125
+ '-e',
126
+ '--enable',
127
+ dest='enable',
128
+ action='store_true',
129
+ help='Enable pre-commit hooks',
130
+ )
131
+ subgroup.add_argument(
132
+ '-d',
133
+ '--disable',
134
+ dest='disable',
135
+ action='store_true',
136
+ help='Disable pre-commit hooks',
137
+ )
138
+ subgroup.add_argument(
139
+ '-a',
140
+ '--autoupdate',
141
+ dest='autoupdate',
142
+ action='store_true',
143
+ help='Autoupdate pre-commit hooks',
144
+ )
145
+ subgroup.add_argument(
146
+ '-r',
147
+ '--run',
148
+ dest='run',
149
+ action='store_true',
150
+ help='Run pre-commit hooks',
151
+ )
152
+
153
+ # Arguments positional definitions
154
+ group = parser.add_argument_group('positional arguments')
155
+ group.add_argument(
156
+ '--',
157
+ dest='double_dash',
158
+ action='store_true',
159
+ help='Positional arguments separator (recommended)',
160
+ )
161
+
162
+ # Arguments parser
163
+ options: Namespace = parser.parse_args()
164
+
165
+ # Help informations
166
+ if options.help:
167
+ print(' ')
168
+ parser.print_help()
169
+ print(' ')
170
+ Platform.flush()
171
+ sys_exit(0)
172
+
173
+ # Instantiate settings
174
+ settings: Settings = Settings(name=Bundle.NAME)
175
+
176
+ # Prepare no_color
177
+ if not options.no_color:
178
+ if settings.has('themes', 'no_color'):
179
+ options.no_color = settings.get_bool('themes', 'no_color')
180
+ else:
181
+ options.no_color = False
182
+ settings.set_bool('themes', 'no_color', options.no_color)
183
+
184
+ # Configure no_color
185
+ if options.no_color:
186
+ environ[Bundle.ENV_NO_COLOR] = '1'
187
+
188
+ # Prepare colors
189
+ Colors.prepare()
190
+
191
+ # Settings setter
192
+ if options.set:
193
+ settings.set(options.set[0], options.set[1], options.set[2])
194
+ settings.show()
195
+ sys_exit(0)
196
+
197
+ # Settings informations
198
+ if options.settings:
199
+ settings.show()
200
+ sys_exit(0)
201
+
202
+ # Instantiate updates
203
+ updates: Updates = Updates(
204
+ name=Bundle.NAME,
205
+ settings=settings,
206
+ )
207
+
208
+ # Version informations
209
+ if options.version:
210
+ print(
211
+ f'{Bundle.NAME} {Version.get()} from {Version.path()} (python {Version.python()})'
212
+ )
213
+ Platform.flush()
214
+ sys_exit(0)
215
+
216
+ # Check for current updates
217
+ if options.update_check:
218
+ if not updates.check():
219
+ updates.check(older=True)
220
+ sys_exit(0)
221
+
222
+ # Arguments modes
223
+ if options.enable:
224
+ options.run = True
225
+ elif options.autoupdate:
226
+ options.enable = True
227
+ elif not (options.list or options.install or options.configure or options.disable
228
+ or options.run):
229
+ result = Entrypoint.Result.CRITICAL
230
+
231
+ # Header
232
+ print(' ')
233
+ Platform.flush()
234
+
235
+ # Tool identifier
236
+ if result != Entrypoint.Result.CRITICAL:
237
+ print(f'{Colors.BOLD} {Bundle.NAME}'
238
+ f'{Colors.YELLOW_LIGHT} ({Version.get()})'
239
+ f'{Colors.RESET}')
240
+ Platform.flush()
241
+
242
+ # CLI entrypoint
243
+ if result != Entrypoint.Result.CRITICAL:
244
+ result = Entrypoint.cli(options)
245
+
246
+ # CLI helper
247
+ else:
248
+ parser.print_help()
249
+
250
+ # Footer
251
+ print(' ')
252
+ Platform.flush()
253
+
254
+ # Check for daily updates
255
+ if updates.enabled and updates.daily:
256
+ updates.check()
257
+
258
+ # Result
259
+ if result in [
260
+ Entrypoint.Result.SUCCESS,
261
+ Entrypoint.Result.FINALIZE,
262
+ ]:
263
+ sys_exit(0)
264
+ else:
265
+ sys_exit(1)
266
+
267
+ # Entrypoint
268
+ if __name__ == '__main__': # pragma: no cover
269
+ main()
File without changes
@@ -0,0 +1,322 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Standard libraries
4
+ from typing import List, NamedTuple
5
+
6
+ # Changes regex type
7
+ ChangesRegex = str
8
+
9
+ # Changes parsers class
10
+ class ChangesParsers(NamedTuple):
11
+ match: str
12
+ groups: List[int]
13
+ commit_type: str
14
+
15
+ # Changes evaluator class
16
+ class ChangesEvaluator(NamedTuple):
17
+ changes: List[ChangesRegex]
18
+ parsers: List[ChangesParsers]
19
+
20
+ # Changes types class
21
+ class ChangesType(NamedTuple):
22
+ commit_type: str
23
+ changes: List[ChangesRegex]
24
+
25
+ # Changes matcher class
26
+ class ChangesMatcher(NamedTuple):
27
+ commit_scope: str
28
+ types: List[ChangesType]
29
+
30
+ # Commits changes constants
31
+ COMMITS_CHANGES_PATTERN: str = r'^#\s*(new file|modified|deleted|renamed|copied):\s*(.+)$'
32
+ COMMITS_CHANGES_SECTION: str = '# Changes to be committed:'
33
+
34
+ # Commits comments constants
35
+ COMMITS_COMMENTS_PREFIX: str = '#'
36
+
37
+ # Commits default constants
38
+ COMMITS_DEFAULT_BODY: str = '# Issue: #...'
39
+ COMMITS_DEFAULT_SCOPE: str = 'scope'
40
+ COMMITS_DEFAULT_SUBJECT: str = ''
41
+ COMMITS_DEFAULT_TYPE: str = 'type'
42
+
43
+ # Commits footers constants
44
+ COMMITS_FOOTER_SIGNOFF: str = 'Signed-off-by: '
45
+
46
+ # Commits message constants
47
+ COMMITS_MESSAGE_EOL: str = '\n'
48
+
49
+ # Regex constants
50
+ REGEX_EXT: str = r'[^/.]*'
51
+ REGEX_FOLDER: str = r'[^/]+?'
52
+ REGEX_STEM: str = r'[^/]+?'
53
+ REGEX_STEM_VISIBLE: str = r'[^/_\.]{1}[^/]+?'
54
+
55
+ # Changes evaluators constants # pylint: disable=line-too-long
56
+ CHANGES_EVALUATORS: List[ChangesEvaluator] = [
57
+ # Sources
58
+ ChangesEvaluator(
59
+ changes=[
60
+ r'^sources|^src',
61
+ ],
62
+ parsers=[
63
+ ChangesParsers(
64
+ match=
65
+ fr'(({REGEX_FOLDER})/)??(({REGEX_FOLDER})/)?({REGEX_STEM_VISIBLE})\.{REGEX_EXT}$',
66
+ groups=[5, 4, 2],
67
+ commit_type='fix',
68
+ ),
69
+ ],
70
+ ),
71
+ # Documentations
72
+ ChangesEvaluator(
73
+ changes=[
74
+ r'^docs/',
75
+ ],
76
+ parsers=[
77
+ ChangesParsers(
78
+ match=
79
+ fr'(({REGEX_FOLDER})/)??(({REGEX_FOLDER})/)?({REGEX_STEM_VISIBLE})(\.{REGEX_EXT})?$',
80
+ groups=[5, 4, 2],
81
+ commit_type='docs',
82
+ ),
83
+ ],
84
+ ),
85
+ # Containers
86
+ ChangesEvaluator(
87
+ changes=[
88
+ r'^containers/',
89
+ ],
90
+ parsers=[
91
+ ChangesParsers(
92
+ match=
93
+ fr'(({REGEX_FOLDER})/)??(({REGEX_FOLDER})/)?({REGEX_STEM_VISIBLE})(\.{REGEX_EXT})?$',
94
+ groups=[4, 2],
95
+ commit_type='build',
96
+ ),
97
+ ],
98
+ ),
99
+ # Templates
100
+ ChangesEvaluator(
101
+ changes=[
102
+ r'^templates/',
103
+ ],
104
+ parsers=[
105
+ ChangesParsers(
106
+ match=
107
+ fr'(({REGEX_FOLDER})/)??(({REGEX_FOLDER})/)?({REGEX_STEM_VISIBLE})(\.{REGEX_EXT})?$',
108
+ groups=[5, 4, 2],
109
+ commit_type='ci',
110
+ ),
111
+ ],
112
+ ),
113
+ # Tests
114
+ ChangesEvaluator(
115
+ changes=[
116
+ r'^test[s]?/',
117
+ ],
118
+ parsers=[
119
+ ChangesParsers(
120
+ match=
121
+ fr'(({REGEX_FOLDER})/)??(({REGEX_FOLDER})/)?({REGEX_STEM_VISIBLE})(\.{REGEX_EXT})?$',
122
+ groups=[5, 4, 2],
123
+ commit_type='test',
124
+ ),
125
+ ],
126
+ ),
127
+ # Yocto
128
+ ChangesEvaluator(
129
+ changes=[
130
+ fr'conf/(distro|machine)|recipes-{REGEX_STEM}',
131
+ ],
132
+ parsers=[
133
+ ChangesParsers(
134
+ match=fr'conf/(distro|machine)/{REGEX_STEM}.conf$',
135
+ groups=[1],
136
+ commit_type='fix',
137
+ ),
138
+ ChangesParsers(
139
+ match=fr'({REGEX_STEM})/{REGEX_STEM}\.(bb[^/.]*|inc)$',
140
+ groups=[1],
141
+ commit_type='fix',
142
+ ),
143
+ ChangesParsers(
144
+ match=fr'recipes-{REGEX_STEM}/({REGEX_STEM})/.*',
145
+ groups=[1],
146
+ commit_type='fix',
147
+ ),
148
+ ],
149
+ ),
150
+ ]
151
+
152
+ # Changes matchers constant
153
+ CHANGES_MATCHERS: List[ChangesMatcher] = [
154
+ ChangesMatcher(
155
+ commit_scope='gitlab-ci',
156
+ types=[
157
+ ChangesType(
158
+ commit_type='ci',
159
+ changes=[
160
+ r'\.gitlab-ci\.yml$',
161
+ r'\.gitlab-ci\.d$',
162
+ ],
163
+ ),
164
+ ],
165
+ ),
166
+ ChangesMatcher(
167
+ commit_scope='hooks',
168
+ types=[
169
+ ChangesType(
170
+ commit_type='chore',
171
+ changes=[
172
+ r'^\.hooks',
173
+ ],
174
+ ),
175
+ ],
176
+ ),
177
+ ChangesMatcher(
178
+ commit_scope='gitignore',
179
+ types=[
180
+ ChangesType(
181
+ commit_type='chore',
182
+ changes=[
183
+ r'\.gitignore$',
184
+ ],
185
+ ),
186
+ ],
187
+ ),
188
+ ChangesMatcher(
189
+ commit_scope='makefile',
190
+ types=[
191
+ ChangesType(
192
+ commit_type='build',
193
+ changes=[
194
+ r'Makefile$',
195
+ r'\.make$',
196
+ ],
197
+ ),
198
+ ],
199
+ ),
200
+ ChangesMatcher(
201
+ commit_scope='commitizen',
202
+ types=[
203
+ ChangesType(
204
+ commit_type='chore',
205
+ changes=[
206
+ r'\.cz.*$',
207
+ ],
208
+ ),
209
+ ],
210
+ ),
211
+ ChangesMatcher(
212
+ commit_scope='coveragerc',
213
+ types=[
214
+ ChangesType(
215
+ commit_type='chore',
216
+ changes=[
217
+ r'.coveragerc$',
218
+ ],
219
+ ),
220
+ ],
221
+ ),
222
+ ChangesMatcher(
223
+ commit_scope='mkdocs',
224
+ types=[
225
+ ChangesType(
226
+ commit_type='docs',
227
+ changes=[
228
+ r'^mkdocs\.yml$',
229
+ ],
230
+ ),
231
+ ],
232
+ ),
233
+ ChangesMatcher(
234
+ commit_scope='mypy',
235
+ types=[
236
+ ChangesType(
237
+ commit_type='chore',
238
+ changes=[
239
+ r'mypy\.ini$',
240
+ ],
241
+ ),
242
+ ],
243
+ ),
244
+ ChangesMatcher(
245
+ commit_scope='pre-commit',
246
+ types=[
247
+ ChangesType(
248
+ commit_type='chore',
249
+ changes=[
250
+ r'\.pre-commit.*$',
251
+ r'^pre_commit_hooks/',
252
+ ],
253
+ ),
254
+ ],
255
+ ),
256
+ ChangesMatcher(
257
+ commit_scope='requirements',
258
+ types=[
259
+ ChangesType(
260
+ commit_type='build',
261
+ changes=[
262
+ r'^requirements/',
263
+ ],
264
+ ),
265
+ ],
266
+ ),
267
+ ChangesMatcher(
268
+ commit_scope='setup',
269
+ types=[
270
+ ChangesType(
271
+ commit_type='chore',
272
+ changes=[
273
+ r'setup\.py$',
274
+ ],
275
+ ),
276
+ ],
277
+ ),
278
+ ChangesMatcher(
279
+ commit_scope='vscode',
280
+ types=[
281
+ ChangesType(
282
+ commit_type='chore',
283
+ changes=[
284
+ r'\.vscode/',
285
+ ],
286
+ ),
287
+ ],
288
+ ),
289
+ ChangesMatcher(
290
+ commit_scope='license',
291
+ types=[
292
+ ChangesType(
293
+ commit_type='docs',
294
+ changes=[
295
+ r'LICENSE.*$',
296
+ ],
297
+ ),
298
+ ],
299
+ ),
300
+ ChangesMatcher(
301
+ commit_scope='readme',
302
+ types=[
303
+ ChangesType(
304
+ commit_type='docs',
305
+ changes=[
306
+ r'README.*$',
307
+ ],
308
+ ),
309
+ ],
310
+ ),
311
+ ChangesMatcher(
312
+ commit_scope='changelog',
313
+ types=[
314
+ ChangesType(
315
+ commit_type='docs',
316
+ changes=[
317
+ r'CHANGELOG.*$',
318
+ ],
319
+ ),
320
+ ],
321
+ ),
322
+ ]