conventional-pre-commit 3.1.0__tar.gz → 3.3.0__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 (41) hide show
  1. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/.github/workflows/release.yml +1 -1
  2. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/.pre-commit-config.yaml +4 -4
  3. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/PKG-INFO +8 -7
  4. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/README.md +7 -6
  5. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/conventional_pre_commit/format.py +26 -3
  6. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/conventional_pre_commit/hook.py +11 -1
  7. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/conventional_pre_commit.egg-info/PKG-INFO +8 -7
  8. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/conventional_pre_commit.egg-info/SOURCES.txt +1 -0
  9. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/conftest.py +5 -0
  10. conventional_pre_commit-3.3.0/tests/messages/conventional_commit_with_multiple_scopes +1 -0
  11. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/test_format.py +81 -0
  12. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/test_hook.py +10 -0
  13. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/.devcontainer/Dockerfile +0 -0
  14. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/.devcontainer/compose.yml +0 -0
  15. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/.devcontainer/devcontainer.json +0 -0
  16. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/.dockerignore +0 -0
  17. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/.flake8 +0 -0
  18. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/.github/dependabot.yaml +0 -0
  19. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/.github/workflows/tests.yml +0 -0
  20. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/.gitignore +0 -0
  21. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/.pre-commit-hooks.yaml +0 -0
  22. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/.vscode/settings.json +0 -0
  23. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/LICENSE +0 -0
  24. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/conventional_pre_commit/__init__.py +0 -0
  25. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/conventional_pre_commit.egg-info/dependency_links.txt +0 -0
  26. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/conventional_pre_commit.egg-info/entry_points.txt +0 -0
  27. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/conventional_pre_commit.egg-info/requires.txt +0 -0
  28. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/conventional_pre_commit.egg-info/top_level.txt +0 -0
  29. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/pyproject.toml +0 -0
  30. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/setup.cfg +0 -0
  31. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/__init__.py +0 -0
  32. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/messages/bad_commit +0 -0
  33. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/messages/conventional_commit +0 -0
  34. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/messages/conventional_commit_bad_multi_line +0 -0
  35. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/messages/conventional_commit_gbk +0 -0
  36. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/messages/conventional_commit_multi_line +0 -0
  37. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/messages/conventional_commit_utf-8 +0 -0
  38. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/messages/conventional_commit_with_scope +0 -0
  39. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/messages/custom_commit +0 -0
  40. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/messages/fixup_commit +0 -0
  41. {conventional_pre_commit-3.1.0 → conventional_pre_commit-3.3.0}/tests/run.sh +0 -0
@@ -38,7 +38,7 @@ jobs:
38
38
 
39
39
  - name: Release
40
40
  id: release
41
- uses: softprops/action-gh-release@v1
41
+ uses: softprops/action-gh-release@v2
42
42
  with:
43
43
  files: |
44
44
  ./dist/*.whl
@@ -8,7 +8,7 @@ default_install_hook_types:
8
8
 
9
9
  repos:
10
10
  - repo: https://github.com/pre-commit/pre-commit-hooks
11
- rev: v4.5.0
11
+ rev: v4.6.0
12
12
  hooks:
13
13
  - id: trailing-whitespace
14
14
  - id: mixed-line-ending
@@ -18,21 +18,21 @@ repos:
18
18
  - id: check-added-large-files
19
19
 
20
20
  - repo: https://github.com/psf/black
21
- rev: 23.12.1
21
+ rev: 24.4.2
22
22
  hooks:
23
23
  - id: black
24
24
  types:
25
25
  - python
26
26
 
27
27
  - repo: https://github.com/PyCQA/flake8
28
- rev: 7.0.0
28
+ rev: 7.1.0
29
29
  hooks:
30
30
  - id: flake8
31
31
  types:
32
32
  - python
33
33
 
34
34
  - repo: https://github.com/pycqa/bandit
35
- rev: 1.7.6
35
+ rev: 1.7.9
36
36
  hooks:
37
37
  - id: bandit
38
38
  args: ["-ll"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: conventional_pre_commit
3
- Version: 3.1.0
3
+ Version: 3.3.0
4
4
  Summary: A pre-commit hook that checks commit messages for Conventional Commits formatting.
5
5
  Author-email: Compiler LLC <dev@compiler.la>
6
6
  License: Apache License
@@ -352,18 +352,19 @@ print(is_conventional("custom: this is a conventional commit", types=["custom"])
352
352
 
353
353
  ```shell
354
354
  $ conventional-pre-commit -h
355
- usage: conventional-pre-commit [-h] [--force-scope] [--strict] [types ...] input
355
+ usage: conventional-pre-commit [-h] [--force-scope] [--scopes SCOPES] [--strict] [types ...] input
356
356
 
357
357
  Check a git commit message for Conventional Commits formatting.
358
358
 
359
359
  positional arguments:
360
- types Optional list of types to support
361
- input A file containing a git commit message
360
+ types Optional list of types to support
361
+ input A file containing a git commit message
362
362
 
363
363
  options:
364
- -h, --help show this help message and exit
365
- --force-scope Force commit to have scope defined.
366
- --strict Force commit to strictly follow Conventional Commits formatting. Disallows fixup! style commits.
364
+ -h, --help show this help message and exit
365
+ --force-scope Force commit to have scope defined.
366
+ --scopes SCOPES Optional list of scopes to support. Scopes should be separated by commas with no spaces (e.g. api,client)
367
+ --strict Force commit to strictly follow Conventional Commits formatting. Disallows fixup! style commits.
367
368
  ```
368
369
 
369
370
  Supply arguments on the command-line, or via the pre-commit `hooks.args` property:
@@ -129,18 +129,19 @@ print(is_conventional("custom: this is a conventional commit", types=["custom"])
129
129
 
130
130
  ```shell
131
131
  $ conventional-pre-commit -h
132
- usage: conventional-pre-commit [-h] [--force-scope] [--strict] [types ...] input
132
+ usage: conventional-pre-commit [-h] [--force-scope] [--scopes SCOPES] [--strict] [types ...] input
133
133
 
134
134
  Check a git commit message for Conventional Commits formatting.
135
135
 
136
136
  positional arguments:
137
- types Optional list of types to support
138
- input A file containing a git commit message
137
+ types Optional list of types to support
138
+ input A file containing a git commit message
139
139
 
140
140
  options:
141
- -h, --help show this help message and exit
142
- --force-scope Force commit to have scope defined.
143
- --strict Force commit to strictly follow Conventional Commits formatting. Disallows fixup! style commits.
141
+ -h, --help show this help message and exit
142
+ --force-scope Force commit to have scope defined.
143
+ --scopes SCOPES Optional list of scopes to support. Scopes should be separated by commas with no spaces (e.g. api,client)
144
+ --strict Force commit to strictly follow Conventional Commits formatting. Disallows fixup! style commits.
144
145
  ```
145
146
 
146
147
  Supply arguments on the command-line, or via the pre-commit `hooks.args` property:
@@ -1,4 +1,5 @@
1
1
  import re
2
+ from typing import List, Optional
2
3
 
3
4
  CONVENTIONAL_TYPES = ["feat", "fix"]
4
5
  DEFAULT_TYPES = [
@@ -26,8 +27,20 @@ def r_types(types):
26
27
  return "|".join(types)
27
28
 
28
29
 
29
- def r_scope(optional=True):
30
+ def _get_scope_pattern(scopes: Optional[List[str]] = None):
31
+ scopes_str = r_types(scopes)
32
+ escaped_delimiters = list(map(re.escape, [":", ",", "-", "/"])) # type: ignore
33
+ delimiters_pattern = r_types(escaped_delimiters)
34
+ return rf"\(\s*(?:{scopes_str})(?:\s*(?:{delimiters_pattern})\s*(?:{scopes_str}))*\s*\)"
35
+
36
+
37
+ def r_scope(optional=True, scopes: Optional[List[str]] = None):
30
38
  """Regex str for an optional (scope)."""
39
+
40
+ if scopes:
41
+ scopes_pattern = _get_scope_pattern(scopes)
42
+ return scopes_pattern
43
+
31
44
  if optional:
32
45
  return r"(\([\w \/:,-]+\))?"
33
46
  else:
@@ -54,6 +67,15 @@ def r_autosquash_prefixes():
54
67
  return "|".join(AUTOSQUASH_PREFIXES)
55
68
 
56
69
 
70
+ def r_verbose_diff():
71
+ """Regex str for verbose diff"""
72
+ return r"(?P<diff>(^# -* >8 -*$\r?\n)(^# .*$\r?\n)+(diff ){1}(.*\r?\n)*)"
73
+
74
+
75
+ def strip_verbose_diff(input):
76
+ return re.sub(r_verbose_diff(), "", input, flags=re.MULTILINE)
77
+
78
+
57
79
  def r_comment():
58
80
  """Regex str for comment"""
59
81
  return r"^#.*\r?\n?"
@@ -70,16 +92,17 @@ def conventional_types(types=[]):
70
92
  return types
71
93
 
72
94
 
73
- def is_conventional(input, types=DEFAULT_TYPES, optional_scope=True):
95
+ def is_conventional(input, types=DEFAULT_TYPES, optional_scope=True, scopes: Optional[List[str]] = None):
74
96
  """
75
97
  Returns True if input matches Conventional Commits formatting
76
98
  https://www.conventionalcommits.org
77
99
 
78
100
  Optionally provide a list of additional custom types.
79
101
  """
102
+ input = strip_verbose_diff(input)
80
103
  input = strip_comments(input)
81
104
  types = conventional_types(types)
82
- pattern = f"^({r_types(types)}){r_scope(optional_scope)}{r_delim()}{r_subject()}{r_body()}"
105
+ pattern = f"^({r_types(types)}){r_scope(optional_scope, scopes=scopes)}{r_delim()}{r_subject()}{r_body()}"
83
106
  regex = re.compile(pattern, re.MULTILINE)
84
107
 
85
108
  result = regex.match(input)
@@ -23,6 +23,12 @@ def main(argv=[]):
23
23
  parser.add_argument(
24
24
  "--force-scope", action="store_false", default=True, dest="optional_scope", help="Force commit to have scope defined."
25
25
  )
26
+ parser.add_argument(
27
+ "--scopes",
28
+ type=str,
29
+ default=None,
30
+ help="Optional list of scopes to support. Scopes should be separated by commas with no spaces (e.g. api,client)",
31
+ )
26
32
  parser.add_argument(
27
33
  "--strict",
28
34
  action="store_true",
@@ -51,12 +57,16 @@ See {Colors.LBLUE}https://git-scm.com/docs/git-commit/#_discussion{Colors.RESTOR
51
57
  """
52
58
  )
53
59
  return RESULT_FAIL
60
+ if args.scopes:
61
+ scopes = args.scopes.split(",")
62
+ else:
63
+ scopes = args.scopes
54
64
 
55
65
  if not args.strict:
56
66
  if format.has_autosquash_prefix(message):
57
67
  return RESULT_SUCCESS
58
68
 
59
- if format.is_conventional(message, args.types, args.optional_scope):
69
+ if format.is_conventional(message, args.types, args.optional_scope, scopes):
60
70
  return RESULT_SUCCESS
61
71
  else:
62
72
  print(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: conventional_pre_commit
3
- Version: 3.1.0
3
+ Version: 3.3.0
4
4
  Summary: A pre-commit hook that checks commit messages for Conventional Commits formatting.
5
5
  Author-email: Compiler LLC <dev@compiler.la>
6
6
  License: Apache License
@@ -352,18 +352,19 @@ print(is_conventional("custom: this is a conventional commit", types=["custom"])
352
352
 
353
353
  ```shell
354
354
  $ conventional-pre-commit -h
355
- usage: conventional-pre-commit [-h] [--force-scope] [--strict] [types ...] input
355
+ usage: conventional-pre-commit [-h] [--force-scope] [--scopes SCOPES] [--strict] [types ...] input
356
356
 
357
357
  Check a git commit message for Conventional Commits formatting.
358
358
 
359
359
  positional arguments:
360
- types Optional list of types to support
361
- input A file containing a git commit message
360
+ types Optional list of types to support
361
+ input A file containing a git commit message
362
362
 
363
363
  options:
364
- -h, --help show this help message and exit
365
- --force-scope Force commit to have scope defined.
366
- --strict Force commit to strictly follow Conventional Commits formatting. Disallows fixup! style commits.
364
+ -h, --help show this help message and exit
365
+ --force-scope Force commit to have scope defined.
366
+ --scopes SCOPES Optional list of scopes to support. Scopes should be separated by commas with no spaces (e.g. api,client)
367
+ --strict Force commit to strictly follow Conventional Commits formatting. Disallows fixup! style commits.
367
368
  ```
368
369
 
369
370
  Supply arguments on the command-line, or via the pre-commit `hooks.args` property:
@@ -33,6 +33,7 @@ tests/messages/conventional_commit_bad_multi_line
33
33
  tests/messages/conventional_commit_gbk
34
34
  tests/messages/conventional_commit_multi_line
35
35
  tests/messages/conventional_commit_utf-8
36
+ tests/messages/conventional_commit_with_multiple_scopes
36
37
  tests/messages/conventional_commit_with_scope
37
38
  tests/messages/custom_commit
38
39
  tests/messages/fixup_commit
@@ -52,3 +52,8 @@ def conventional_commit_bad_multi_line_path():
52
52
  @pytest.fixture
53
53
  def conventional_commit_multi_line_path():
54
54
  return get_message_path("conventional_commit_multi_line")
55
+
56
+
57
+ @pytest.fixture
58
+ def conventional_commit_with_multiple_scopes_path():
59
+ return get_message_path("conventional_commit_with_multiple_scopes")
@@ -0,0 +1 @@
1
+ feat(api,client): added new endpoint with client support
@@ -64,6 +64,20 @@ def test_r_scope__special_chars():
64
64
  assert regex.match("(some,thing)")
65
65
 
66
66
 
67
+ def test_r_scope__scopes():
68
+ scopes_input = ["api", "client"]
69
+ result = format.r_scope(scopes=scopes_input)
70
+ regex = re.compile(result)
71
+ assert regex.match("(api)")
72
+ assert regex.match("(client)")
73
+ assert regex.match("(api, client)")
74
+ assert regex.match("(api: client)")
75
+ assert regex.match("(api/client)")
76
+ assert regex.match("(api-client)")
77
+ assert not regex.match("(test)")
78
+ assert not regex.match("(api; client)")
79
+
80
+
67
81
  def test_r_delim():
68
82
  result = format.r_delim()
69
83
  regex = re.compile(result)
@@ -151,6 +165,73 @@ def test_strip_comments__spaced():
151
165
  assert result.strip() == "feat(scope): message"
152
166
 
153
167
 
168
+ def test_r_verbose_diff__has_diff():
169
+ regex = re.compile(format.r_verbose_diff(), re.MULTILINE)
170
+ input = """# ----------- >8 -----------
171
+ # Some comment
172
+ # Some comment
173
+ diff --git a/file b/file
174
+ """
175
+
176
+ assert regex.match(input)
177
+
178
+
179
+ def test_r_verbose_diff__no_diff():
180
+ regex = re.compile(format.r_verbose_diff(), re.MULTILINE)
181
+ input = """# ----------- >8 -----------
182
+ # Some comment
183
+ # Some comment
184
+ """
185
+
186
+ assert not regex.match(input)
187
+
188
+
189
+ def test_r_verbose_diff__no_extra_comments():
190
+ regex = re.compile(format.r_verbose_diff(), re.MULTILINE)
191
+ input = """# ----------- >8 -----------
192
+ diff --git a/file b/file
193
+ """
194
+
195
+ assert not regex.match(input)
196
+
197
+
198
+ def test_strip_verbose_diff__has_diff():
199
+ input = """feat(scope): message
200
+ # Please enter the commit message for your changes.
201
+
202
+ # These are comments usually added by editors, f.ex. with export EDITOR=vim
203
+ # ----------- >8 -----------
204
+ # Some comment
205
+ # Some comment
206
+ diff --git a/file b/file
207
+ """
208
+
209
+ result = format.strip_verbose_diff(input)
210
+ assert result.count("\n") == 4
211
+ assert (
212
+ result
213
+ == """feat(scope): message
214
+ # Please enter the commit message for your changes.
215
+
216
+ # These are comments usually added by editors, f.ex. with export EDITOR=vim
217
+ """
218
+ )
219
+
220
+
221
+ def test_strip_verbose_diff__no_diff():
222
+ input = """feat(scope): message
223
+ # Please enter the commit message for your changes.
224
+
225
+ # These are comments usually added by editors, f.ex. with export EDITOR=vim
226
+ # ----------- >8 -----------
227
+ # Some comment
228
+ # Some comment
229
+ """
230
+
231
+ result = format.strip_verbose_diff(input)
232
+ assert result == input
233
+
234
+
154
235
  @pytest.mark.parametrize("type", format.DEFAULT_TYPES)
155
236
  def test_is_conventional__default_type(type):
156
237
  input = f"{type}: message"
@@ -142,6 +142,16 @@ def test_subprocess_success__conventional_with_scope(cmd, conventional_commit_wi
142
142
  assert result == RESULT_SUCCESS
143
143
 
144
144
 
145
+ def test_subprocess_success__conventional_with_multiple_scopes(cmd, conventional_commit_with_multiple_scopes_path):
146
+ result = subprocess.call((cmd, "--scopes", "api,client", conventional_commit_with_multiple_scopes_path))
147
+ assert result == RESULT_SUCCESS
148
+
149
+
150
+ def test_subprocess_fail__conventional_with_multiple_scopes(cmd, conventional_commit_with_multiple_scopes_path):
151
+ result = subprocess.call((cmd, "--scopes", "api", conventional_commit_with_multiple_scopes_path))
152
+ assert result == RESULT_FAIL
153
+
154
+
145
155
  def test_subprocess_success__fixup_commit(cmd, fixup_commit_path):
146
156
  result = subprocess.call((cmd, fixup_commit_path))
147
157