dycw-pre-commit-hooks 0.12.9__py3-none-any.whl → 0.13.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.
Potentially problematic release.
This version of dycw-pre-commit-hooks might be problematic. Click here for more details.
- {dycw_pre_commit_hooks-0.12.9.dist-info → dycw_pre_commit_hooks-0.13.0.dist-info}/METADATA +3 -3
- dycw_pre_commit_hooks-0.13.0.dist-info/RECORD +17 -0
- {dycw_pre_commit_hooks-0.12.9.dist-info → dycw_pre_commit_hooks-0.13.0.dist-info}/entry_points.txt +0 -1
- pre_commit_hooks/__init__.py +1 -1
- pre_commit_hooks/common.py +32 -20
- pre_commit_hooks/format_requirements/__init__.py +4 -8
- pre_commit_hooks/mirror_files/__init__.py +15 -16
- pre_commit_hooks/replace_sequence_str/__init__.py +3 -2
- pre_commit_hooks/run_bump_my_version/__init__.py +23 -9
- pre_commit_hooks/tag_commits/__init__.py +27 -15
- dycw_pre_commit_hooks-0.12.9.dist-info/RECORD +0 -19
- pre_commit_hooks/check_submodules/__init__.py +0 -57
- pre_commit_hooks/check_submodules/__main__.py +0 -6
- {dycw_pre_commit_hooks-0.12.9.dist-info → dycw_pre_commit_hooks-0.13.0.dist-info}/WHEEL +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dycw-pre-commit-hooks
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.13.0
|
|
4
4
|
Author-email: Derek Wan <d.wan@icloud.com>
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
6
|
Requires-Dist: click<8.3,>=8.2.1
|
|
@@ -8,7 +8,7 @@ Requires-Dist: dycw-utilities<0.167,>=0.166.5
|
|
|
8
8
|
Requires-Dist: gitpython<3.2,>=3.1.45
|
|
9
9
|
Requires-Dist: libcst<1.9,>=1.8.2
|
|
10
10
|
Requires-Dist: loguru<0.8,>=0.7.3
|
|
11
|
-
Requires-Dist: more-itertools<10.
|
|
11
|
+
Requires-Dist: more-itertools<10.9,>=10.8.0
|
|
12
12
|
Requires-Dist: orjson<3.12,>=3.11.3
|
|
13
13
|
Requires-Dist: packaging<25.1,>=25.0
|
|
14
14
|
Requires-Dist: tomlkit<0.14,>=0.13.2
|
|
@@ -32,8 +32,8 @@ My [`pre-commit`](https://pre-commit.com/) hooks.
|
|
|
32
32
|
- repo: https://github.com/dycw/pre-commit-hooks
|
|
33
33
|
rev: master
|
|
34
34
|
hooks:
|
|
35
|
-
- id: check-submodules
|
|
36
35
|
- id: format-requirements
|
|
36
|
+
- id: mirror-files
|
|
37
37
|
- id: replace-sequence-str
|
|
38
38
|
- id: run-bump-my-version
|
|
39
39
|
- id: tag-commits
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
pre_commit_hooks/__init__.py,sha256=VX99Js9MSUXrTMe_OSKIYhYYPRRvI_8mU7_0pIpdJmw,59
|
|
2
|
+
pre_commit_hooks/common.py,sha256=BkGWepSj_y_y6pOrvKX4G8259o5Klp1C-Yg2cdDTi0s,4482
|
|
3
|
+
pre_commit_hooks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
pre_commit_hooks/format_requirements/__init__.py,sha256=ByGP9oCf5c5-55Tayp8BvnT6O-_Fi5om1AAva1BzLvg,3223
|
|
5
|
+
pre_commit_hooks/format_requirements/__main__.py,sha256=15JSp_rhjI_Ddoj4MRkHFShfnYxs6GggUhLRlGtrQ0E,156
|
|
6
|
+
pre_commit_hooks/mirror_files/__init__.py,sha256=GSoFXo_og3d7NkQcmzdWOZyxQJPCO1nr4JtMVVcNJOI,1646
|
|
7
|
+
pre_commit_hooks/mirror_files/__main__.py,sha256=YzOSNKR2XrVST5dgIVJrpRL28QkcziciOomuKtVX7Jo,149
|
|
8
|
+
pre_commit_hooks/replace_sequence_str/__init__.py,sha256=IUyhpYh89PF9fX65zYe5Pt3cIvvWa0HiUDng0deL0Nw,1628
|
|
9
|
+
pre_commit_hooks/replace_sequence_str/__main__.py,sha256=B1dxOxngV4vUVnDVrXSywiySOs1P_zF30_4ZMRsOSaY,157
|
|
10
|
+
pre_commit_hooks/run_bump_my_version/__init__.py,sha256=FhvLQEEoFm21_2c_12Loy_lc8gfNv2wtwAOrdtBEqrs,2028
|
|
11
|
+
pre_commit_hooks/run_bump_my_version/__main__.py,sha256=w2V3y61jrSau-zxjl8ciHtWPlJQwXbYxNJ2tGYVyI4s,156
|
|
12
|
+
pre_commit_hooks/tag_commits/__init__.py,sha256=6HWjXOcTd9gjiZwXmy2lIhZzru-zeRgbpEYxKi1z5sg,3294
|
|
13
|
+
pre_commit_hooks/tag_commits/__main__.py,sha256=qefgYw7LWbvmzZS45-ym6olS4cHqw1Emw2wlqZBXN_o,148
|
|
14
|
+
dycw_pre_commit_hooks-0.13.0.dist-info/METADATA,sha256=iEdyGf05U2B_FOypZ9Um7DknncrbYhHIdA9_zskLIzU,1101
|
|
15
|
+
dycw_pre_commit_hooks-0.13.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
16
|
+
dycw_pre_commit_hooks-0.13.0.dist-info/entry_points.txt,sha256=OTVj55u2A6hqtbiPa_h9Zd9pTToCsI9P5xpzE3g4NZc,310
|
|
17
|
+
dycw_pre_commit_hooks-0.13.0.dist-info/RECORD,,
|
pre_commit_hooks/__init__.py
CHANGED
pre_commit_hooks/common.py
CHANGED
|
@@ -5,10 +5,10 @@ from typing import TYPE_CHECKING, Literal, assert_never
|
|
|
5
5
|
|
|
6
6
|
import utilities.click
|
|
7
7
|
from click import Choice, option
|
|
8
|
-
from loguru import logger
|
|
9
8
|
from tomlkit import TOMLDocument, parse
|
|
10
9
|
from tomlkit.items import Table
|
|
11
10
|
from utilities.atomicwrites import writer
|
|
11
|
+
from utilities.functions import get_class_name
|
|
12
12
|
from utilities.hashlib import md5_hash
|
|
13
13
|
from utilities.pathlib import get_repo_root
|
|
14
14
|
from utilities.typing import get_literal_elements
|
|
@@ -17,7 +17,7 @@ from utilities.whenever import get_now_local, to_zoned_date_time
|
|
|
17
17
|
from xdg_base_dirs import xdg_cache_home
|
|
18
18
|
|
|
19
19
|
if TYPE_CHECKING:
|
|
20
|
-
from collections.abc import Callable
|
|
20
|
+
from collections.abc import Callable, Iterator
|
|
21
21
|
|
|
22
22
|
from whenever import DateTimeDelta
|
|
23
23
|
|
|
@@ -47,36 +47,35 @@ def get_version(source: Mode | Path | str | bytes | TOMLDocument, /) -> Version:
|
|
|
47
47
|
try:
|
|
48
48
|
tool = doc["tool"]
|
|
49
49
|
except KeyError:
|
|
50
|
-
|
|
51
|
-
raise
|
|
50
|
+
msg = "Key 'tool' does not exist"
|
|
51
|
+
raise GetVersionError(msg) from None
|
|
52
52
|
if not isinstance(tool, Table):
|
|
53
|
-
|
|
54
|
-
raise
|
|
53
|
+
msg = "`tool` is not a Table"
|
|
54
|
+
raise GetVersionError(msg)
|
|
55
55
|
try:
|
|
56
56
|
bumpversion = tool["bumpversion"]
|
|
57
57
|
except KeyError:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)
|
|
61
|
-
raise
|
|
58
|
+
msg = "Key 'bumpversion' does not exist"
|
|
59
|
+
raise GetVersionError(msg) from None
|
|
62
60
|
if not isinstance(bumpversion, Table):
|
|
63
|
-
|
|
64
|
-
raise
|
|
61
|
+
msg = "`bumpversion` is not a Table"
|
|
62
|
+
raise GetVersionError(msg)
|
|
65
63
|
try:
|
|
66
64
|
version = bumpversion["current_version"]
|
|
67
65
|
except KeyError:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
)
|
|
71
|
-
raise
|
|
66
|
+
msg = "Key 'current_version' does not exist"
|
|
67
|
+
raise GetVersionError(msg) from None
|
|
72
68
|
if not isinstance(version, str):
|
|
73
|
-
|
|
74
|
-
raise
|
|
69
|
+
msg = f"`version` is not a string; got {get_class_name(version)!r}"
|
|
70
|
+
raise GetVersionError(msg)
|
|
75
71
|
return parse_version(version)
|
|
76
72
|
case never: # pyright: ignore[reportUnnecessaryComparison]
|
|
77
73
|
assert_never(never)
|
|
78
74
|
|
|
79
75
|
|
|
76
|
+
class GetVersionError(Exception): ...
|
|
77
|
+
|
|
78
|
+
|
|
80
79
|
def get_toml_path(mode: Mode = DEFAULT_MODE, /) -> Path:
|
|
81
80
|
"""Get the path of the TOML file with the version."""
|
|
82
81
|
match mode:
|
|
@@ -88,6 +87,11 @@ def get_toml_path(mode: Mode = DEFAULT_MODE, /) -> Path:
|
|
|
88
87
|
assert_never(never)
|
|
89
88
|
|
|
90
89
|
|
|
90
|
+
def run_all(iterator: Iterator[bool], /) -> bool:
|
|
91
|
+
"""Run all of a set of jobs."""
|
|
92
|
+
return all(list(iterator))
|
|
93
|
+
|
|
94
|
+
|
|
91
95
|
def throttled_run[**P](
|
|
92
96
|
name: str,
|
|
93
97
|
run_every: DateTimeDelta | None,
|
|
@@ -116,8 +120,14 @@ def throttled_run[**P](
|
|
|
116
120
|
try:
|
|
117
121
|
return func(*args, **kwargs)
|
|
118
122
|
finally:
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
_ = write_text(path, str(get_now_local()))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def write_text(path: Path, text: str, /) -> Literal[False]:
|
|
127
|
+
"""Write text to a file."""
|
|
128
|
+
with writer(path, overwrite=True) as temp:
|
|
129
|
+
_ = temp.write_text(text)
|
|
130
|
+
return False
|
|
121
131
|
|
|
122
132
|
|
|
123
133
|
__all__ = [
|
|
@@ -126,6 +136,8 @@ __all__ = [
|
|
|
126
136
|
"get_toml_path",
|
|
127
137
|
"get_version",
|
|
128
138
|
"mode_option",
|
|
139
|
+
"run_all",
|
|
129
140
|
"run_every_option",
|
|
130
141
|
"throttled_run",
|
|
142
|
+
"write_text",
|
|
131
143
|
]
|
|
@@ -13,7 +13,8 @@ from packaging.requirements import (
|
|
|
13
13
|
from packaging.specifiers import Specifier, SpecifierSet
|
|
14
14
|
from tomlkit import array, dumps, loads, string
|
|
15
15
|
from tomlkit.items import Array, Table
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
from pre_commit_hooks.common import run_all, write_text
|
|
17
18
|
|
|
18
19
|
if TYPE_CHECKING:
|
|
19
20
|
from collections.abc import Iterator
|
|
@@ -26,18 +27,13 @@ if TYPE_CHECKING:
|
|
|
26
27
|
@argument("paths", nargs=-1, type=utilities.click.Path())
|
|
27
28
|
def main(*, paths: tuple[Path, ...]) -> bool:
|
|
28
29
|
"""CLI for the `format-requirements` hook."""
|
|
29
|
-
|
|
30
|
-
return all(results)
|
|
30
|
+
return run_all(map(_process, paths))
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
def _process(path: Path, /) -> bool:
|
|
34
34
|
doc = loads(path.read_text())
|
|
35
35
|
expected = _format_path(path)
|
|
36
|
-
if doc == expected
|
|
37
|
-
return True
|
|
38
|
-
with writer(path, overwrite=True) as temp:
|
|
39
|
-
_ = temp.write_text(dumps(expected))
|
|
40
|
-
return False
|
|
36
|
+
return True if doc == expected else write_text(path, dumps(expected))
|
|
41
37
|
|
|
42
38
|
|
|
43
39
|
def _format_path(path: Path, /) -> TOMLDocument:
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import TYPE_CHECKING
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
4
|
|
|
5
5
|
import utilities.click
|
|
6
6
|
from click import argument, command
|
|
7
7
|
from loguru import logger
|
|
8
8
|
from more_itertools import chunked
|
|
9
|
-
from utilities.atomicwrites import writer
|
|
10
9
|
|
|
11
|
-
from pre_commit_hooks.common import run_every_option, throttled_run
|
|
10
|
+
from pre_commit_hooks.common import run_all, run_every_option, throttled_run, write_text
|
|
12
11
|
|
|
13
12
|
if TYPE_CHECKING:
|
|
14
13
|
from collections.abc import Iterable
|
|
@@ -22,16 +21,19 @@ if TYPE_CHECKING:
|
|
|
22
21
|
@run_every_option
|
|
23
22
|
def main(*, paths: tuple[Path, ...], run_every: DateTimeDelta | None = None) -> bool:
|
|
24
23
|
"""CLI for the `format-requirements` hook."""
|
|
25
|
-
|
|
24
|
+
try:
|
|
25
|
+
return throttled_run("mirror-files", run_every, _process, paths)
|
|
26
|
+
except MirrorFilesError as error:
|
|
27
|
+
logger.exception("%s", error.args[0])
|
|
28
|
+
return False
|
|
26
29
|
|
|
27
30
|
|
|
28
31
|
def _process(paths: Iterable[Path], /) -> bool:
|
|
29
32
|
paths = list(paths)
|
|
30
33
|
if len(paths) % 2 == 1:
|
|
31
|
-
|
|
32
|
-
raise
|
|
33
|
-
|
|
34
|
-
return all(results)
|
|
34
|
+
msg = f"Expected an even number of paths; got {len(paths)}"
|
|
35
|
+
raise MirrorFilesError(msg)
|
|
36
|
+
return run_all(map(_process_pair, chunked(paths, 2, strict=True)))
|
|
35
37
|
|
|
36
38
|
|
|
37
39
|
def _process_pair(paths: Iterable[Path], /) -> bool:
|
|
@@ -39,19 +41,16 @@ def _process_pair(paths: Iterable[Path], /) -> bool:
|
|
|
39
41
|
try:
|
|
40
42
|
text_from = path_from.read_text()
|
|
41
43
|
except FileNotFoundError:
|
|
42
|
-
|
|
43
|
-
raise
|
|
44
|
+
msg = f"Failed to mirror {str(path_from)!r}; path does not exist"
|
|
45
|
+
raise MirrorFilesError(msg) from None
|
|
44
46
|
try:
|
|
45
47
|
text_to = path_to.read_text()
|
|
46
48
|
except FileNotFoundError:
|
|
47
|
-
return
|
|
48
|
-
return True if text_from == text_to else
|
|
49
|
+
return write_text(path_to, text_from)
|
|
50
|
+
return True if text_from == text_to else write_text(path_to, text_from)
|
|
49
51
|
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
with writer(path, overwrite=True) as temp:
|
|
53
|
-
_ = temp.write_text(text)
|
|
54
|
-
return False
|
|
53
|
+
class MirrorFilesError(Exception): ...
|
|
55
54
|
|
|
56
55
|
|
|
57
56
|
__all__ = ["main"]
|
|
@@ -12,6 +12,8 @@ from libcst.matchers import SubscriptElement as MSubscriptElement
|
|
|
12
12
|
from libcst.matchers import matches
|
|
13
13
|
from libcst.metadata import MetadataWrapper
|
|
14
14
|
|
|
15
|
+
from pre_commit_hooks.common import run_all
|
|
16
|
+
|
|
15
17
|
if TYPE_CHECKING:
|
|
16
18
|
from pathlib import Path
|
|
17
19
|
|
|
@@ -20,8 +22,7 @@ if TYPE_CHECKING:
|
|
|
20
22
|
@argument("paths", nargs=-1, type=utilities.click.Path())
|
|
21
23
|
def main(*, paths: tuple[Path, ...]) -> bool:
|
|
22
24
|
"""CLI for the `replace-sequence-str` hook."""
|
|
23
|
-
|
|
24
|
-
return all(results)
|
|
25
|
+
return run_all(map(_process, paths))
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
def _process(path: Path, /) -> bool:
|
|
@@ -7,6 +7,7 @@ from loguru import logger
|
|
|
7
7
|
|
|
8
8
|
from pre_commit_hooks.common import (
|
|
9
9
|
DEFAULT_MODE,
|
|
10
|
+
GetVersionError,
|
|
10
11
|
Mode,
|
|
11
12
|
get_toml_path,
|
|
12
13
|
get_version,
|
|
@@ -18,15 +19,27 @@ from pre_commit_hooks.common import (
|
|
|
18
19
|
@mode_option
|
|
19
20
|
def main(*, mode: Mode = DEFAULT_MODE) -> bool:
|
|
20
21
|
"""CLI for the `run-bump-my-version` hook."""
|
|
21
|
-
|
|
22
|
+
try:
|
|
23
|
+
return _process(mode=mode)
|
|
24
|
+
except RunBumpMyVersionError as error:
|
|
25
|
+
logger.exception("%s", error.args[0])
|
|
26
|
+
return False
|
|
22
27
|
|
|
23
28
|
|
|
24
29
|
def _process(*, mode: Mode = DEFAULT_MODE) -> bool:
|
|
25
|
-
|
|
30
|
+
try:
|
|
31
|
+
current = get_version(mode)
|
|
32
|
+
except GetVersionError as error:
|
|
33
|
+
msg = f"Failed to bump version; error getting current verison: {error.args[0]}"
|
|
34
|
+
raise RunBumpMyVersionError(msg) from None
|
|
26
35
|
commit = check_output(["git", "rev-parse", "origin/master"], text=True).rstrip("\n")
|
|
27
36
|
path = get_toml_path(mode)
|
|
28
37
|
contents = check_output(["git", "show", f"{commit}:{path}"], text=True)
|
|
29
|
-
|
|
38
|
+
try:
|
|
39
|
+
master = get_version(contents)
|
|
40
|
+
except GetVersionError as error:
|
|
41
|
+
msg = f"Failed to bump version; error getting master verison: {error.args[0]}"
|
|
42
|
+
raise RunBumpMyVersionError(msg) from None
|
|
30
43
|
if current in {master.bump_patch(), master.bump_minor(), master.bump_major()}:
|
|
31
44
|
return True
|
|
32
45
|
cmd = [
|
|
@@ -39,15 +52,16 @@ def _process(*, mode: Mode = DEFAULT_MODE) -> bool:
|
|
|
39
52
|
try:
|
|
40
53
|
_ = check_call(cmd, stdout=PIPE, stderr=STDOUT)
|
|
41
54
|
except CalledProcessError as error:
|
|
42
|
-
|
|
43
|
-
|
|
55
|
+
msg = f"Failed to bump version; error running `bump-my-version`: {error.stderr.strip()}"
|
|
56
|
+
raise GetVersionError(msg) from None
|
|
44
57
|
except FileNotFoundError:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
58
|
+
msg = "Failed to bump version; is `bump-my-version` installed?"
|
|
59
|
+
raise RunBumpMyVersionError(msg) from None
|
|
48
60
|
else:
|
|
49
61
|
return True
|
|
50
|
-
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class RunBumpMyVersionError(Exception): ...
|
|
51
65
|
|
|
52
66
|
|
|
53
67
|
__all__ = ["main"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import TYPE_CHECKING
|
|
3
|
+
from typing import TYPE_CHECKING, Literal
|
|
4
4
|
|
|
5
5
|
import utilities.click
|
|
6
6
|
from click import command, option
|
|
@@ -11,10 +11,12 @@ from utilities.whenever import from_timestamp, get_now_local
|
|
|
11
11
|
|
|
12
12
|
from pre_commit_hooks.common import (
|
|
13
13
|
DEFAULT_MODE,
|
|
14
|
+
GetVersionError,
|
|
14
15
|
Mode,
|
|
15
16
|
get_toml_path,
|
|
16
17
|
get_version,
|
|
17
18
|
mode_option,
|
|
19
|
+
run_all,
|
|
18
20
|
run_every_option,
|
|
19
21
|
throttled_run,
|
|
20
22
|
)
|
|
@@ -48,11 +50,11 @@ def _process(
|
|
|
48
50
|
tagged = {tag.commit.hexsha for tag in repo.tags}
|
|
49
51
|
min_date_time = None if max_age is None else (get_now_local() - max_age)
|
|
50
52
|
commits = reversed(list(repo.iter_commits(repo.refs["origin/master"])))
|
|
51
|
-
results =
|
|
53
|
+
results = (
|
|
52
54
|
_process_commit(c, tagged, repo, min_date_time=min_date_time, mode=mode)
|
|
53
55
|
for c in commits
|
|
54
|
-
|
|
55
|
-
return
|
|
56
|
+
)
|
|
57
|
+
return run_all(results)
|
|
56
58
|
|
|
57
59
|
|
|
58
60
|
def _process_commit(
|
|
@@ -69,35 +71,45 @@ def _process_commit(
|
|
|
69
71
|
):
|
|
70
72
|
return True
|
|
71
73
|
try:
|
|
72
|
-
_tag_commit(commit, repo, mode=mode)
|
|
73
|
-
except
|
|
74
|
+
return _tag_commit(commit, repo, mode=mode)
|
|
75
|
+
except TagCommitsError as error:
|
|
76
|
+
logger.exception("%s", error.args[0])
|
|
74
77
|
return False
|
|
75
|
-
return True
|
|
76
78
|
|
|
77
79
|
|
|
78
80
|
def _get_date_time(commit: Commit, /) -> ZonedDateTime:
|
|
79
81
|
return from_timestamp(commit.committed_date, time_zone=LOCAL_TIME_ZONE_NAME)
|
|
80
82
|
|
|
81
83
|
|
|
82
|
-
def _tag_commit(
|
|
84
|
+
def _tag_commit(
|
|
85
|
+
commit: Commit, repo: Repo, /, *, mode: Mode = DEFAULT_MODE
|
|
86
|
+
) -> Literal[True]:
|
|
83
87
|
sha = commit.hexsha[:7]
|
|
84
88
|
date = _get_date_time(commit)
|
|
89
|
+
desc = f"{sha!r} ({date})"
|
|
85
90
|
path = get_toml_path(mode)
|
|
86
91
|
try:
|
|
87
92
|
joined = commit.tree.join(str(path))
|
|
88
93
|
except KeyError:
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
msg = f"Failed to tag {desc}; {str(path)!r} does not exist"
|
|
95
|
+
raise TagCommitsError(msg) from None
|
|
91
96
|
text = joined.data_stream.read()
|
|
92
|
-
|
|
97
|
+
try:
|
|
98
|
+
version = get_version(text)
|
|
99
|
+
except GetVersionError as error:
|
|
100
|
+
msg = f"Failed to tag {desc}; error getting veresion: {error.args[0]}"
|
|
101
|
+
raise TagCommitsError(msg) from None
|
|
93
102
|
try:
|
|
94
103
|
tag = repo.create_tag(str(version), ref=sha)
|
|
95
104
|
except GitCommandError as error:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
logger.info(f"Tagging {sha!r} ({date}) as {str(version)!r}...")
|
|
105
|
+
msg = f"Failed to tag {desc}; error creating tag: {error.stderr.strip()}"
|
|
106
|
+
raise TagCommitsError(msg) from None
|
|
107
|
+
logger.info(f"Tagging {desc} as {str(version)!r}...")
|
|
100
108
|
_ = repo.remotes.origin.push(f"refs/tags/{tag.name}")
|
|
109
|
+
return True
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class TagCommitsError(Exception): ...
|
|
101
113
|
|
|
102
114
|
|
|
103
115
|
__all__ = ["main"]
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
pre_commit_hooks/__init__.py,sha256=_SME_z9OS6vGtaQHag719-IQtmnJ3bfHioDbLCdRoMo,59
|
|
2
|
-
pre_commit_hooks/common.py,sha256=Ovg0kK5CBSBEalGdVxLKjvRX3gbjpzTFRNRopB8tEiw,4247
|
|
3
|
-
pre_commit_hooks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
pre_commit_hooks/check_submodules/__init__.py,sha256=Q9iuPFQvpCJmuHlPbPDzd5zgua3pS0ZBka0JFpNpbOs,1324
|
|
5
|
-
pre_commit_hooks/check_submodules/__main__.py,sha256=foSVebwCfSkKcAc3cD5YTzkmrWd7Wso9_mR9-zuyG-o,153
|
|
6
|
-
pre_commit_hooks/format_requirements/__init__.py,sha256=dORQ5sNZaOWYY6cw0X1YIic4OHZeTt9EhI21D1uQFyE,3322
|
|
7
|
-
pre_commit_hooks/format_requirements/__main__.py,sha256=15JSp_rhjI_Ddoj4MRkHFShfnYxs6GggUhLRlGtrQ0E,156
|
|
8
|
-
pre_commit_hooks/mirror_files/__init__.py,sha256=XUmUYHz4otEF5wIK8X0ntH0vkYFBmJwJfXkI8Bz3n0I,1682
|
|
9
|
-
pre_commit_hooks/mirror_files/__main__.py,sha256=YzOSNKR2XrVST5dgIVJrpRL28QkcziciOomuKtVX7Jo,149
|
|
10
|
-
pre_commit_hooks/replace_sequence_str/__init__.py,sha256=nDjiKV14th2uWbnte1rSvXckysl7ooaLgWo6IP4HI2s,1618
|
|
11
|
-
pre_commit_hooks/replace_sequence_str/__main__.py,sha256=B1dxOxngV4vUVnDVrXSywiySOs1P_zF30_4ZMRsOSaY,157
|
|
12
|
-
pre_commit_hooks/run_bump_my_version/__init__.py,sha256=OsMY0boz3VTqAtgLCHtC8AvCXx6OYvOXA5H-VAwBFoY,1444
|
|
13
|
-
pre_commit_hooks/run_bump_my_version/__main__.py,sha256=w2V3y61jrSau-zxjl8ciHtWPlJQwXbYxNJ2tGYVyI4s,156
|
|
14
|
-
pre_commit_hooks/tag_commits/__init__.py,sha256=097p0gfZcykpOPUgGYsrLePe8Nar04eKlCMn_mqPepg,2945
|
|
15
|
-
pre_commit_hooks/tag_commits/__main__.py,sha256=qefgYw7LWbvmzZS45-ym6olS4cHqw1Emw2wlqZBXN_o,148
|
|
16
|
-
dycw_pre_commit_hooks-0.12.9.dist-info/METADATA,sha256=4FTUextZ5Ocnpgfdr1papnRJS4QvgpP6lOeg-TSpeEY,1105
|
|
17
|
-
dycw_pre_commit_hooks-0.12.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
18
|
-
dycw_pre_commit_hooks-0.12.9.dist-info/entry_points.txt,sha256=0xGzim6HTjeOXJpusYjBk0aEYkXQR2IwrmfzM6KT_r0,368
|
|
19
|
-
dycw_pre_commit_hooks-0.12.9.dist-info/RECORD,,
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import TYPE_CHECKING
|
|
4
|
-
|
|
5
|
-
import utilities.click
|
|
6
|
-
from click import argument, command
|
|
7
|
-
from git import Repo, Submodule
|
|
8
|
-
|
|
9
|
-
from pre_commit_hooks.common import (
|
|
10
|
-
DEFAULT_MODE,
|
|
11
|
-
Mode,
|
|
12
|
-
get_toml_path,
|
|
13
|
-
get_version,
|
|
14
|
-
mode_option,
|
|
15
|
-
run_every_option,
|
|
16
|
-
throttled_run,
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
if TYPE_CHECKING:
|
|
20
|
-
from pathlib import Path
|
|
21
|
-
|
|
22
|
-
from whenever import DateTimeDelta
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@command()
|
|
26
|
-
@argument("paths", nargs=-1, type=utilities.click.Path())
|
|
27
|
-
@run_every_option
|
|
28
|
-
def main(*, paths: tuple[Path, ...], run_every: DateTimeDelta | None = None) -> bool:
|
|
29
|
-
"""CLI for the `check-submodules` hook."""
|
|
30
|
-
results = [
|
|
31
|
-
throttled_run("check-submodules", run_every, _process, p) for p in paths
|
|
32
|
-
] # run all
|
|
33
|
-
return all(results)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def _process(path: Path, /) -> bool:
|
|
37
|
-
repo = Repo(path, search_parent_directories=True)
|
|
38
|
-
results = [_process_submodule(s) for s in repo.submodules] # run all
|
|
39
|
-
return all(results)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def _process_submodule(submodule: Submodule, /) -> bool:
|
|
43
|
-
repo = submodule.module()
|
|
44
|
-
_ = repo.remotes.origin.fetch()
|
|
45
|
-
local = repo.commit("master")
|
|
46
|
-
remote = repo.commit("origin/master")
|
|
47
|
-
return local.hexsha == remote.hexsha
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
__all__ = [
|
|
51
|
-
"DEFAULT_MODE",
|
|
52
|
-
"Mode",
|
|
53
|
-
"get_toml_path",
|
|
54
|
-
"get_version",
|
|
55
|
-
"main",
|
|
56
|
-
"mode_option",
|
|
57
|
-
]
|
|
File without changes
|