pre-commit-crocodile 4.1.0__tar.gz → 4.2.1__tar.gz

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 (105) hide show
  1. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/.gitlab-ci.yml +0 -1
  2. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/.pre-commit-config.yaml +5 -1
  3. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/CHANGELOG.md +30 -1
  4. {pre_commit_crocodile-4.1.0/pre_commit_crocodile.egg-info → pre_commit_crocodile-4.2.1}/PKG-INFO +2 -2
  5. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/README.md +1 -1
  6. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1/pre_commit_crocodile.egg-info}/PKG-INFO +2 -2
  7. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/assets/.pre-commit-config.yaml +4 -0
  8. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/cli/entrypoint.py +19 -5
  9. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/features/precommit.py +169 -13
  10. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/.coveragerc +0 -0
  11. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/.cz.yaml +0 -0
  12. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/.gitattributes +0 -0
  13. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/.gitignore +0 -0
  14. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/.markdownlint.json +0 -0
  15. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/.pre-commit-hooks.yaml +0 -0
  16. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/.style.yapf +0 -0
  17. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/.vscode/extensions.json +0 -0
  18. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/.vscode/settings.json +0 -0
  19. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/LICENSE +0 -0
  20. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/config/cliff.toml +0 -0
  21. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/containers/build/Dockerfile +0 -0
  22. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/containers/codestyle/Dockerfile +0 -0
  23. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/containers/commits/Dockerfile +0 -0
  24. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/containers/deploy/Dockerfile +0 -0
  25. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/containers/pages/Dockerfile +0 -0
  26. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/containers/preview/Dockerfile +0 -0
  27. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/containers/rehost/images.txt +0 -0
  28. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/containers/test-coverage-linux/Dockerfile +0 -0
  29. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/containers/test-coverage-windows/Dockerfile +0 -0
  30. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/containers/test-linux/Dockerfile +0 -0
  31. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/.pages.in +0 -0
  32. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/assets/images/favicon.png +0 -0
  33. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/assets/scripts/mkdocs-exporter.js +0 -0
  34. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/assets/stylesheets/custom.css +0 -0
  35. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/assets/stylesheets/pdf.scss +0 -0
  36. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/commitizen.md +0 -0
  37. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/commits.md +0 -0
  38. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/components.md +0 -0
  39. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/hooks.md +0 -0
  40. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/pre-commit.md +0 -0
  41. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/prepare.sh +0 -0
  42. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/preview.py +0 -0
  43. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/preview.svg +0 -0
  44. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/robots.txt +0 -0
  45. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/settings.md +0 -0
  46. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/template.svg +0 -0
  47. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/templates/covers/back.html.j2 +0 -0
  48. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/docs/templates/covers/front.html.j2 +0 -0
  49. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/mkdocs.yml +0 -0
  50. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/mypy.ini +0 -0
  51. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/pre_commit_crocodile.egg-info/SOURCES.txt +0 -0
  52. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/pre_commit_crocodile.egg-info/dependency_links.txt +0 -0
  53. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/pre_commit_crocodile.egg-info/entry_points.txt +0 -0
  54. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/pre_commit_crocodile.egg-info/requires.txt +0 -0
  55. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/pre_commit_crocodile.egg-info/top_level.txt +0 -0
  56. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/requirements/build.txt +0 -0
  57. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/requirements/commits.txt +0 -0
  58. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/requirements/coverage.txt +0 -0
  59. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/requirements/deploy.txt +0 -0
  60. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/requirements/docs.txt +0 -0
  61. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/requirements/pages.txt +0 -0
  62. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/requirements/quality.txt +0 -0
  63. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/requirements/runtime.txt +0 -0
  64. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/requirements/tests.txt +0 -0
  65. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/setup.cfg +0 -0
  66. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/setup.py +0 -0
  67. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/sonar-project.properties +0 -0
  68. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/__init__.py +0 -0
  69. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/__main__.py +0 -0
  70. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/assets/.cz.yaml +0 -0
  71. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/assets/__init__.py +0 -0
  72. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/cli/__init__.py +0 -0
  73. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/cli/main.py +0 -0
  74. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/features/__init__.py +0 -0
  75. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/features/argcomplete.py +0 -0
  76. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/features/commitizen.py +0 -0
  77. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/features/gcil.py +0 -0
  78. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/features/git.py +0 -0
  79. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/features/radiandevcore.py +0 -0
  80. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/features/readme.py +0 -0
  81. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/hooks/__init__.py +0 -0
  82. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/hooks/check_yaml_ruamel_pure.py +0 -0
  83. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/hooks/configurations.py +0 -0
  84. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/hooks/prepare_commit_message.py +0 -0
  85. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/package/__init__.py +0 -0
  86. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/package/bundle.py +0 -0
  87. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/package/settings.py +0 -0
  88. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/package/updates.py +0 -0
  89. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/package/version.py +0 -0
  90. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/prints/__init__.py +0 -0
  91. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/prints/boxes.py +0 -0
  92. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/prints/colors.py +0 -0
  93. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/system/__init__.py +0 -0
  94. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/system/commands.py +0 -0
  95. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/system/platform.py +0 -0
  96. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/types/__init__.py +0 -0
  97. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/types/environments.py +0 -0
  98. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/src/types/strings.py +0 -0
  99. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/templates/commits.yml +0 -0
  100. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/tests/arguments/test.sh +0 -0
  101. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/tests/colors/test.sh +0 -0
  102. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/tests/macos/test.sh +0 -0
  103. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/tests/settings/test.sh +0 -0
  104. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/tests/versions/test.sh +0 -0
  105. {pre_commit_crocodile-4.1.0 → pre_commit_crocodile-4.2.1}/tests/windows/test.sh +0 -0
@@ -1034,7 +1034,6 @@ pages:
1034
1034
  pdf:
1035
1035
  extends:
1036
1036
  - pages
1037
- stage: deploy
1038
1037
  artifacts:
1039
1038
  expire_in: 1 hour
1040
1039
  paths:
@@ -63,6 +63,10 @@ repos:
63
63
  - id: mixed-line-ending
64
64
  - id: trailing-whitespace
65
65
  args: ['--markdown-linebreak-ext=md']
66
+ exclude: >
67
+ (?x)(
68
+ .*.md$
69
+ )
66
70
 
67
71
  # Repository: pre-commit-hooks
68
72
  - repo: https://github.com/pre-commit/pygrep-hooks
@@ -111,7 +115,7 @@ repos:
111
115
 
112
116
  # Repository: gcil
113
117
  - repo: https://gitlab.com/RadianDevCore/tools/gcil
114
- rev: 9db7ca21
118
+ rev: 10.2.0
115
119
  hooks:
116
120
  - id: run-gcil-push
117
121
  name: Run GitLab CI job with gcil (codestyle)
@@ -1,7 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ <a name="4.2.1"></a>
4
+ ## [4.2.1](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/compare/4.2.0...4.2.1) (2025-05-31)
5
+
6
+ ### 🐛 Bug Fixes
7
+
8
+ - **precommit:** fix mismatching excludes upon '--configure' ([039a2da](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/commit/039a2da953da11f48e4fa505ddf32f38322b8d98))
9
+
10
+
11
+ <a name="4.2.0"></a>
12
+ ## [4.2.0](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/compare/4.1.0...4.2.0) (2025-05-31)
13
+
14
+ ### ✨ Features
15
+
16
+ - **entrypoint:** avoid 'sleep' calls without user input TTY ([e3ecb29](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/commit/e3ecb29f87fbc505d8eec491733809cc56a8a8a6))
17
+ - **pre-commit-config:** exclude '.md' files from 'trailing-whitespace' ([db98cc2](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/commit/db98cc22984380e4f47f16b3f6cd425db98d57ad))
18
+
19
+ ### 🐛 Bug Fixes
20
+
21
+ - **pre-commit:** fix empty hooks with 'hooks: []' upon '--configure' ([3ef9cbe](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/commit/3ef9cbe3cebcc9627bd4510a519b13ce41cdfd89))
22
+
23
+ ### ⚙️ Cleanups
24
+
25
+ - **pre-commit:** migrate to 'gcil' 10.2.0 ([257ec3a](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/commit/257ec3ac7a0efcce32aa759c049a3977cc485537))
26
+
27
+ ### 🚀 CI
28
+
29
+ - **gitlab-ci:** remove unrequired 'stage: deploy' in 'pdf' job ([e07a8f2](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/commit/e07a8f29b735772357cd1235d7d76a39345ec0f9))
30
+
31
+
3
32
  <a name="4.1.0"></a>
4
- ## [4.1.0](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/compare/4.0.0...4.1.0) (2025-05-30)
33
+ ## [4.1.0](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/compare/4.0.0...4.1.0) (2025-05-31)
5
34
 
6
35
  ### ✨ Features
7
36
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pre-commit-crocodile
3
- Version: 4.1.0
3
+ Version: 4.2.1
4
4
  Summary: Git hooks intended for developers using pre-commit
5
5
  Home-page: https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile
6
6
  Author: Adrian DC
@@ -88,7 +88,7 @@ Git hooks intended for developers using [pre-commit](https://pre-commit.com/) an
88
88
 
89
89
  ## Preview
90
90
 
91
- ![preview.svg](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/raw/4.1.0/docs/preview.svg)
91
+ ![preview.svg](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/raw/4.2.1/docs/preview.svg)
92
92
 
93
93
  ---
94
94
 
@@ -40,7 +40,7 @@ Git hooks intended for developers using [pre-commit](https://pre-commit.com/) an
40
40
 
41
41
  ## Preview
42
42
 
43
- ![preview.svg](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/raw/4.1.0/docs/preview.svg)
43
+ ![preview.svg](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/raw/4.2.1/docs/preview.svg)
44
44
 
45
45
  ---
46
46
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pre-commit-crocodile
3
- Version: 4.1.0
3
+ Version: 4.2.1
4
4
  Summary: Git hooks intended for developers using pre-commit
5
5
  Home-page: https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile
6
6
  Author: Adrian DC
@@ -88,7 +88,7 @@ Git hooks intended for developers using [pre-commit](https://pre-commit.com/) an
88
88
 
89
89
  ## Preview
90
90
 
91
- ![preview.svg](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/raw/4.1.0/docs/preview.svg)
91
+ ![preview.svg](https://gitlab.com/RadianDevCore/tools/pre-commit-crocodile/raw/4.2.1/docs/preview.svg)
92
92
 
93
93
  ---
94
94
 
@@ -63,6 +63,10 @@ repos:
63
63
  - id: mixed-line-ending
64
64
  - id: trailing-whitespace
65
65
  args: ['--markdown-linebreak-ext=md']
66
+ exclude: >
67
+ (?x)(
68
+ .*.md$
69
+ )
66
70
 
67
71
  # Repository: pre-commit-hooks
68
72
  - repo: https://github.com/pre-commit/pygrep-hooks
@@ -118,7 +118,8 @@ class Entrypoint:
118
118
  print(' ')
119
119
  Platform.flush()
120
120
  Argcomplete.configure()
121
- sleep(2)
121
+ if Platform.IS_TTY_STDIN:
122
+ sleep(2)
122
123
 
123
124
  # Install commitizen completion
124
125
  if options.install and not Commitizen.configured():
@@ -130,7 +131,8 @@ class Entrypoint:
130
131
  Platform.flush()
131
132
  commitizen_file: str = Commitizen.configure()
132
133
  print(f'commitizen completion enabled in: {commitizen_file}')
133
- sleep(1)
134
+ if Platform.IS_TTY_STDIN:
135
+ sleep(1)
134
136
 
135
137
  # Bind specific configurations
136
138
  if options.config:
@@ -190,6 +192,12 @@ class Entrypoint:
190
192
  configuration_file=precommit_configuration.name,
191
193
  )
192
194
 
195
+ # Configure useless excludes
196
+ PreCommit.configure_useless_excludes(
197
+ default=options.default,
198
+ configuration_file=precommit_configuration.name,
199
+ )
200
+
193
201
  # Configre gcil hooks
194
202
  Gcil.configure_hooks(configuration_file=precommit_configuration.name)
195
203
 
@@ -222,11 +230,15 @@ class Entrypoint:
222
230
  mode='w',
223
231
  ) as f:
224
232
  f.write(data)
225
- sleep(1)
233
+ if Platform.IS_TTY_STDIN:
234
+ sleep(1)
226
235
 
227
236
  # Configure unused hooks
228
237
  PreCommit.configure_unused_hooks(default=options.default)
229
238
 
239
+ # Configure useless excludes
240
+ PreCommit.configure_useless_excludes(default=options.default)
241
+
230
242
  # Configre gcil hooks
231
243
  Gcil.configure_hooks()
232
244
 
@@ -337,7 +349,8 @@ class Entrypoint:
337
349
  f'{Colors.RESET}')
338
350
 
339
351
  # Delay user interactions
340
- sleep(5)
352
+ if Platform.IS_TTY_STDIN:
353
+ sleep(5)
341
354
 
342
355
  # Configure badges
343
356
  elif options.badges and configurations_files:
@@ -363,7 +376,8 @@ class Entrypoint:
363
376
  f'{Colors.RESET}')
364
377
 
365
378
  # Delay user interactions
366
- sleep(5)
379
+ if Platform.IS_TTY_STDIN:
380
+ sleep(5)
367
381
 
368
382
  # Enable hooks
369
383
  if options.enable:
@@ -3,7 +3,7 @@
3
3
  # Standard libraries
4
4
  from pathlib import Path
5
5
  from shutil import copyfile, move
6
- from typing import List
6
+ from typing import Dict, List
7
7
 
8
8
  # Components
9
9
  from ..features.git import Git
@@ -19,6 +19,8 @@ class PreCommit:
19
19
  CONFIGURATION_EXTENSION: str = '.yaml'
20
20
  CONFIGURATION_FILE: str = '.pre-commit-config.yaml'
21
21
  HOOKS_APPLY_ERROR: str = ' does not apply to this repository'
22
+ HOOKS_EXCLUDE_DELIMITER: str = ' for '
23
+ HOOKS_EXCLUDE_ERROR: str = ' does not match any files'
22
24
  PACKAGE: str = 'pre-commit'
23
25
  REV_TEMPLATE: str = '{PACKAGE_REVISION}'
24
26
 
@@ -46,7 +48,7 @@ class PreCommit:
46
48
  'clean',
47
49
  ])
48
50
 
49
- # Configure unused hooks, pylint: disable=too-many-branches,too-many-statements
51
+ # Configure unused hooks, pylint: disable=too-many-branches,too-many-locals,too-many-statements
50
52
  @staticmethod
51
53
  def configure_unused_hooks(
52
54
  default: bool,
@@ -57,9 +59,14 @@ class PreCommit:
57
59
  configuration_moved: bool = False
58
60
  configuration_tmp: bool = False
59
61
  data_lines: List[str]
60
- hook_id: str
62
+ hook_id: str = '- id: '
61
63
  hook_offset: str
62
64
  hook_section: bool
65
+ hooks_element: str = 'hooks:'
66
+ hooks_empty_flag: Dict[int, bool]
67
+ hooks_ending: str
68
+ hooks_index: int
69
+ hooks_line: str
63
70
  hooks_unused: List[str] = []
64
71
 
65
72
  # Fake pre-commit configuration
@@ -118,36 +125,185 @@ class PreCommit:
118
125
 
119
126
  # Disable pre-commit unused hooks
120
127
  if hooks_unused:
128
+
129
+ # Parse pre-commit hooks
130
+ data_lines = []
131
+ hook_section = False
132
+ hooks_empty_flag = {}
133
+ hooks_index = -1
121
134
  with open(
122
135
  configuration_file,
123
136
  encoding='utf8',
124
137
  mode='r',
125
138
  ) as f:
126
- data_lines = f.readlines()
139
+ for line in f.readlines():
140
+ line_stripped = line.strip()
141
+
142
+ # Parse lines
143
+ if not line_stripped:
144
+ data_lines.append(line)
145
+ hook_section = False
146
+ elif line_stripped.startswith(hooks_element):
147
+ hooks_index = len(data_lines)
148
+ hooks_empty_flag[hooks_index] = True
149
+ data_lines.append(line)
150
+ elif any(
151
+ line_stripped == f'{hook_id}{hook}' for hook in hooks_unused):
152
+ data_lines.append(line.replace(hook_id, f'# {hook_id}'))
153
+ hook_offset = line[0:line.find(hook_id)]
154
+ hook_section = True
155
+ elif line_stripped.startswith(hook_id):
156
+ data_lines.append(line)
157
+ if hooks_index != -1:
158
+ hooks_empty_flag[hooks_index] = False
159
+ hook_section = False
160
+ elif hook_section:
161
+ data_lines.append(f'{hook_offset}# {line.lstrip()}')
162
+ else:
163
+ data_lines.append(line)
164
+ hooks_index = -1
165
+
166
+ # Fix empty hooks
167
+ for index, empty in hooks_empty_flag.items():
168
+ if empty:
169
+ hooks_line = data_lines[index]
170
+ hooks_ending = hooks_line[len(hooks_line.rstrip('\r\n')):]
171
+ data_lines[index] = hooks_line.rstrip('\r\n') + ' []' + hooks_ending
172
+
173
+ # Write pre-commit hooks
127
174
  with open(
128
175
  configuration_file,
129
176
  encoding='utf8',
130
177
  mode='w',
131
178
  ) as f:
132
- hook_section = False
133
- hook_id = '- id: '
134
- for line in data_lines:
179
+ f.writelines(data_lines)
180
+
181
+ # Result
182
+ return True
183
+
184
+ # Configure useless excludes
185
+ @staticmethod
186
+ def configure_useless_excludes(
187
+ default: bool,
188
+ configuration_file: str = CONFIGURATION_FILE,
189
+ ) -> bool:
190
+
191
+ # Variables
192
+ configuration_moved: bool = False
193
+ configuration_tmp: bool = False
194
+ data_lines: List[str]
195
+ hook_exclude: str = 'exclude: '
196
+ hook_id: str = '- id: '
197
+ hook_offset: str
198
+ hook_property: bool
199
+ hook_section: bool
200
+ hooks_unused: List[str] = []
201
+
202
+ # Fake pre-commit configuration
203
+ if default and configuration_file != PreCommit.CONFIGURATION_FILE:
204
+ if Path(PreCommit.CONFIGURATION_FILE).exists():
205
+ move(PreCommit.CONFIGURATION_FILE, f'{PreCommit.CONFIGURATION_FILE}.tmp')
206
+ configuration_moved = True
207
+ else:
208
+ configuration_tmp = True
209
+ copyfile(
210
+ configuration_file,
211
+ PreCommit.CONFIGURATION_FILE,
212
+ )
213
+
214
+ # Prestage pre-commit configuration
215
+ if not default or configuration_moved or configuration_tmp:
216
+ Commands.run(Git.BINARY, [
217
+ 'add',
218
+ PreCommit.CONFIGURATION_FILE,
219
+ ])
220
+
221
+ # Configure pre-commit unused hooks
222
+ print(' ')
223
+ print(f'{Colors.BOLD} - Configure sources: '
224
+ f'{Colors.YELLOW_LIGHT}check-useless-excludes'
225
+ f'{Colors.RESET}')
226
+ print(' ')
227
+ for line in Commands.output(PreCommit.BINARY, [
228
+ 'run',
229
+ ] + PreCommit.__flags_configuration + [
230
+ '--all-files',
231
+ 'check-useless-excludes',
232
+ ]).splitlines():
233
+ if PreCommit.HOOKS_EXCLUDE_ERROR not in line:
234
+ continue
235
+ hooks_unused += [
236
+ line[line.find(PreCommit.HOOKS_EXCLUDE_DELIMITER) \
237
+ + len(PreCommit.HOOKS_EXCLUDE_DELIMITER) \
238
+ :line.find(PreCommit.HOOKS_EXCLUDE_ERROR)]
239
+ ]
240
+
241
+ # Cleanup fake pre-commit configuration
242
+ if configuration_moved or configuration_tmp:
243
+ Path(PreCommit.CONFIGURATION_FILE).unlink()
244
+
245
+ # Restore pre-commit configurations
246
+ if configuration_moved:
247
+ move(f'{PreCommit.CONFIGURATION_FILE}.tmp', PreCommit.CONFIGURATION_FILE)
248
+
249
+ # Reset pre-commit configuration
250
+ if not default or configuration_moved or configuration_tmp:
251
+ Commands.run(Git.BINARY, [
252
+ 'reset',
253
+ 'HEAD',
254
+ PreCommit.CONFIGURATION_FILE,
255
+ ])
256
+
257
+ # Show unused hooks
258
+ print(f'detected unused hooks in configuration: {", ".join(hooks_unused) or "-"}')
259
+
260
+ # Disable pre-commit unused hooks
261
+ if hooks_unused:
262
+
263
+ # Parse pre-commit hooks
264
+ data_lines = []
265
+ hook_property = False
266
+ hook_section = False
267
+ with open(
268
+ configuration_file,
269
+ encoding='utf8',
270
+ mode='r',
271
+ ) as f:
272
+ for line in f.readlines():
135
273
  line_stripped = line.strip()
274
+
275
+ # Parse lines
136
276
  if not line_stripped:
137
- f.write(line)
277
+ data_lines.append(line)
278
+ hook_property = False
138
279
  hook_section = False
139
280
  elif any(
140
281
  line_stripped == f'{hook_id}{hook}' for hook in hooks_unused):
141
- f.write(line.replace(hook_id, f'# {hook_id}'))
282
+ data_lines.append(line)
142
283
  hook_offset = line[0:line.find(hook_id)]
284
+ hook_property = False
143
285
  hook_section = True
144
286
  elif line_stripped.startswith(hook_id):
145
- f.write(line)
287
+ data_lines.append(line)
288
+ hook_property = False
146
289
  hook_section = False
147
- elif hook_section:
148
- f.write(f'{hook_offset}# {line.lstrip()}')
290
+ elif hook_section and line_stripped.startswith(hook_exclude):
291
+ data_lines.append(line.replace(hook_exclude, f'# {hook_exclude}'))
292
+ hook_property = True
293
+ elif hook_property and line.startswith(hook_offset + ' '):
294
+ data_lines.append(
295
+ f'{hook_offset} # {line[len(hook_offset) + 2:]}')
149
296
  else:
150
- f.write(line)
297
+ data_lines.append(line)
298
+ hook_property = False
299
+
300
+ # Write pre-commit hooks
301
+ with open(
302
+ configuration_file,
303
+ encoding='utf8',
304
+ mode='w',
305
+ ) as f:
306
+ f.writelines(data_lines)
151
307
 
152
308
  # Result
153
309
  return True