dycw-pre-commit-hooks 0.12.0__py3-none-any.whl → 0.12.1__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.0.dist-info → dycw_pre_commit_hooks-0.12.1.dist-info}/METADATA +3 -1
- {dycw_pre_commit_hooks-0.12.0.dist-info → dycw_pre_commit_hooks-0.12.1.dist-info}/RECORD +6 -6
- pre_commit_hooks/__init__.py +1 -1
- pre_commit_hooks/tag_commits/__init__.py +67 -10
- {dycw_pre_commit_hooks-0.12.0.dist-info → dycw_pre_commit_hooks-0.12.1.dist-info}/WHEEL +0 -0
- {dycw_pre_commit_hooks-0.12.0.dist-info → dycw_pre_commit_hooks-0.12.1.dist-info}/entry_points.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dycw-pre-commit-hooks
|
|
3
|
-
Version: 0.12.
|
|
3
|
+
Version: 0.12.1
|
|
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,8 +8,10 @@ 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: orjson<3.12,>=3.11.3
|
|
11
12
|
Requires-Dist: packaging<25.1,>=25.0
|
|
12
13
|
Requires-Dist: tomlkit<0.14,>=0.13.2
|
|
14
|
+
Requires-Dist: xdg-base-dirs<6.1,>=6.0.2
|
|
13
15
|
Description-Content-Type: text/markdown
|
|
14
16
|
|
|
15
17
|
# pre-commit-hooks
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
pre_commit_hooks/__init__.py,sha256=
|
|
1
|
+
pre_commit_hooks/__init__.py,sha256=bMyIveYyxCjAv2_JH9Hd38cd4RL7NmCC4HiW8Td0nQU,59
|
|
2
2
|
pre_commit_hooks/common.py,sha256=x-a-v0esyBPJqPZf6uypbrFaxUKEgfnuAxiUvYSaLbA,2350
|
|
3
3
|
pre_commit_hooks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
pre_commit_hooks/format_requirements/__init__.py,sha256=bn1JsblINCf0ro2QrhsM8XtTOHnPFSZC2t-Hx5AJDfA,3392
|
|
@@ -7,9 +7,9 @@ pre_commit_hooks/replace_sequence_str/__init__.py,sha256=a-pCAcBaa7FDsGDNLzMiD-x
|
|
|
7
7
|
pre_commit_hooks/replace_sequence_str/__main__.py,sha256=B1dxOxngV4vUVnDVrXSywiySOs1P_zF30_4ZMRsOSaY,157
|
|
8
8
|
pre_commit_hooks/run_bump_my_version/__init__.py,sha256=UGaOu7Ie5LRGsMe34eygSgMWteKfDRGNX49R3kafczk,1353
|
|
9
9
|
pre_commit_hooks/run_bump_my_version/__main__.py,sha256=w2V3y61jrSau-zxjl8ciHtWPlJQwXbYxNJ2tGYVyI4s,156
|
|
10
|
-
pre_commit_hooks/tag_commits/__init__.py,sha256=
|
|
10
|
+
pre_commit_hooks/tag_commits/__init__.py,sha256=BvpAqdRDw06Gab3jNXYO6BgosnMybowZUsXV8wQA2gU,3699
|
|
11
11
|
pre_commit_hooks/tag_commits/__main__.py,sha256=qefgYw7LWbvmzZS45-ym6olS4cHqw1Emw2wlqZBXN_o,148
|
|
12
|
-
dycw_pre_commit_hooks-0.12.
|
|
13
|
-
dycw_pre_commit_hooks-0.12.
|
|
14
|
-
dycw_pre_commit_hooks-0.12.
|
|
15
|
-
dycw_pre_commit_hooks-0.12.
|
|
12
|
+
dycw_pre_commit_hooks-0.12.1.dist-info/METADATA,sha256=CvLbPZLgmY-MZS2dZulcvQHAmS64lk64xP96uvC-dVY,1029
|
|
13
|
+
dycw_pre_commit_hooks-0.12.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
14
|
+
dycw_pre_commit_hooks-0.12.1.dist-info/entry_points.txt,sha256=r1tnPzaGvOrSdX-ZRriidf8AhZgUtXfjdTpwpkTBA8U,260
|
|
15
|
+
dycw_pre_commit_hooks-0.12.1.dist-info/RECORD,,
|
pre_commit_hooks/__init__.py
CHANGED
|
@@ -2,39 +2,96 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from typing import TYPE_CHECKING
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import utilities.click
|
|
6
|
+
from click import command, option
|
|
6
7
|
from git import Commit, GitCommandError, Repo
|
|
7
8
|
from loguru import logger
|
|
9
|
+
from utilities.hashlib import md5_hash
|
|
10
|
+
from utilities.pathlib import get_repo_root
|
|
8
11
|
from utilities.tzlocal import LOCAL_TIME_ZONE_NAME
|
|
9
|
-
from utilities.whenever import
|
|
12
|
+
from utilities.whenever import from_timestamp, get_now_local
|
|
13
|
+
from whenever import DateTimeDelta, ZonedDateTime
|
|
14
|
+
from xdg_base_dirs import xdg_cache_home
|
|
10
15
|
|
|
11
16
|
from pre_commit_hooks.common import get_version
|
|
12
17
|
|
|
13
18
|
if TYPE_CHECKING:
|
|
14
19
|
from collections.abc import Set as AbstractSet
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
_RUN_EVERY: DateTimeDelta | None = None
|
|
22
|
+
_MAX_AGE: DateTimeDelta | None = None
|
|
17
23
|
|
|
18
24
|
|
|
19
25
|
@command()
|
|
20
|
-
|
|
26
|
+
@option(
|
|
27
|
+
"--run-every",
|
|
28
|
+
type=utilities.click.DateTimeDelta(),
|
|
29
|
+
default=_RUN_EVERY,
|
|
30
|
+
show_default=True,
|
|
31
|
+
)
|
|
32
|
+
@option(
|
|
33
|
+
"--max-age",
|
|
34
|
+
type=utilities.click.DateTimeDelta(),
|
|
35
|
+
default=_MAX_AGE,
|
|
36
|
+
show_default=True,
|
|
37
|
+
)
|
|
38
|
+
def main(
|
|
39
|
+
*,
|
|
40
|
+
run_every: DateTimeDelta | None = _RUN_EVERY,
|
|
41
|
+
max_age: DateTimeDelta | None = _MAX_AGE,
|
|
42
|
+
) -> bool:
|
|
21
43
|
"""CLI for the `tag_commits` hook."""
|
|
22
|
-
return _process()
|
|
44
|
+
return _process(run_every=run_every, max_age=max_age)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _process(
|
|
48
|
+
*,
|
|
49
|
+
run_every: DateTimeDelta | None = _RUN_EVERY,
|
|
50
|
+
max_age: DateTimeDelta | None = _MAX_AGE,
|
|
51
|
+
) -> bool:
|
|
52
|
+
if run_every is not None:
|
|
53
|
+
last = _get_last_run()
|
|
54
|
+
min_date_time = get_now_local() - run_every
|
|
55
|
+
if (last is not None) and (min_date_time <= last):
|
|
56
|
+
return True
|
|
57
|
+
return _process_commits(max_age=max_age)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _get_last_run() -> ZonedDateTime | None:
|
|
61
|
+
hash_ = md5_hash(get_repo_root())
|
|
62
|
+
path = xdg_cache_home().joinpath("tag-commits", hash_)
|
|
63
|
+
try:
|
|
64
|
+
text = path.read_text()
|
|
65
|
+
except FileNotFoundError:
|
|
66
|
+
return None
|
|
67
|
+
try:
|
|
68
|
+
return ZonedDateTime.parse_common_iso(text.strip("\n"))
|
|
69
|
+
except ValueError:
|
|
70
|
+
return None
|
|
23
71
|
|
|
24
72
|
|
|
25
|
-
def
|
|
73
|
+
def _process_commits(*, max_age: DateTimeDelta | None = None) -> bool:
|
|
26
74
|
repo = Repo(".", search_parent_directories=True)
|
|
27
75
|
tagged = {tag.commit.hexsha for tag in repo.tags}
|
|
28
|
-
|
|
76
|
+
min_date_time = None if max_age is None else (get_now_local() - max_age)
|
|
29
77
|
commits = reversed(list(repo.iter_commits(repo.refs["origin/master"])))
|
|
30
|
-
results = [
|
|
78
|
+
results = [
|
|
79
|
+
_process_commit(c, tagged, repo, min_date_time=min_date_time) for c in commits
|
|
80
|
+
] # run all
|
|
31
81
|
return all(results)
|
|
32
82
|
|
|
33
83
|
|
|
34
84
|
def _process_commit(
|
|
35
|
-
commit: Commit,
|
|
85
|
+
commit: Commit,
|
|
86
|
+
tagged: AbstractSet[str],
|
|
87
|
+
repo: Repo,
|
|
88
|
+
/,
|
|
89
|
+
*,
|
|
90
|
+
min_date_time: ZonedDateTime | None = None,
|
|
36
91
|
) -> bool:
|
|
37
|
-
if (commit.hexsha in tagged) or (
|
|
92
|
+
if (commit.hexsha in tagged) or (
|
|
93
|
+
(min_date_time is not None) and (_get_date_time(commit) < min_date_time)
|
|
94
|
+
):
|
|
38
95
|
return True
|
|
39
96
|
try:
|
|
40
97
|
_tag_commit(commit, repo)
|
|
File without changes
|
{dycw_pre_commit_hooks-0.12.0.dist-info → dycw_pre_commit_hooks-0.12.1.dist-info}/entry_points.txt
RENAMED
|
File without changes
|