dycw-pre-commit-hooks 0.12.2__py3-none-any.whl → 0.12.3__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.2.dist-info → dycw_pre_commit_hooks-0.12.3.dist-info}/METADATA +1 -1
- dycw_pre_commit_hooks-0.12.3.dist-info/RECORD +15 -0
- pre_commit_hooks/__init__.py +1 -1
- pre_commit_hooks/common.py +27 -4
- pre_commit_hooks/format_requirements/__init__.py +1 -3
- pre_commit_hooks/run_bump_my_version/__init__.py +13 -29
- pre_commit_hooks/tag_commits/__init__.py +23 -9
- dycw_pre_commit_hooks-0.12.2.dist-info/RECORD +0 -15
- {dycw_pre_commit_hooks-0.12.2.dist-info → dycw_pre_commit_hooks-0.12.3.dist-info}/WHEEL +0 -0
- {dycw_pre_commit_hooks-0.12.2.dist-info → dycw_pre_commit_hooks-0.12.3.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
pre_commit_hooks/__init__.py,sha256=RyHKY4eur1WrQClEx1VZcd3k4R32k5_2gsEPKMgYMXE,59
|
|
2
|
+
pre_commit_hooks/common.py,sha256=OanSspv8rs4OA8u5PVHdS7e0tz_BQ2hHfdKM0poMcx8,2869
|
|
3
|
+
pre_commit_hooks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
pre_commit_hooks/format_requirements/__init__.py,sha256=zcvOH839MHGxVNvbBt4KZKDW2MXdtnu6OuxP6P0IqL4,3322
|
|
5
|
+
pre_commit_hooks/format_requirements/__main__.py,sha256=15JSp_rhjI_Ddoj4MRkHFShfnYxs6GggUhLRlGtrQ0E,156
|
|
6
|
+
pre_commit_hooks/replace_sequence_str/__init__.py,sha256=a-pCAcBaa7FDsGDNLzMiD-xG20wKl-SRmhWSbm9hrvo,1618
|
|
7
|
+
pre_commit_hooks/replace_sequence_str/__main__.py,sha256=B1dxOxngV4vUVnDVrXSywiySOs1P_zF30_4ZMRsOSaY,157
|
|
8
|
+
pre_commit_hooks/run_bump_my_version/__init__.py,sha256=alaQx34H_pUfJypv9f0UmXIb3Ht3YS29pxcfodVtaTM,1444
|
|
9
|
+
pre_commit_hooks/run_bump_my_version/__main__.py,sha256=w2V3y61jrSau-zxjl8ciHtWPlJQwXbYxNJ2tGYVyI4s,156
|
|
10
|
+
pre_commit_hooks/tag_commits/__init__.py,sha256=E9aOurHbD_K3zr8YgBQkiIJo05d2BMUZdecqzz92iJo,3982
|
|
11
|
+
pre_commit_hooks/tag_commits/__main__.py,sha256=qefgYw7LWbvmzZS45-ym6olS4cHqw1Emw2wlqZBXN_o,148
|
|
12
|
+
dycw_pre_commit_hooks-0.12.3.dist-info/METADATA,sha256=AyAWP2a6CTbevtMdYABgRQUap-F7fagsv1h5OESUFuw,1029
|
|
13
|
+
dycw_pre_commit_hooks-0.12.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
14
|
+
dycw_pre_commit_hooks-0.12.3.dist-info/entry_points.txt,sha256=r1tnPzaGvOrSdX-ZRriidf8AhZgUtXfjdTpwpkTBA8U,260
|
|
15
|
+
dycw_pre_commit_hooks-0.12.3.dist-info/RECORD,,
|
pre_commit_hooks/__init__.py
CHANGED
pre_commit_hooks/common.py
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from pathlib import Path
|
|
4
|
-
from typing import assert_never
|
|
4
|
+
from typing import Literal, assert_never
|
|
5
5
|
|
|
6
|
+
from click import Choice, option
|
|
6
7
|
from loguru import logger
|
|
7
8
|
from tomlkit import TOMLDocument, parse
|
|
8
9
|
from tomlkit.items import Table
|
|
9
10
|
from utilities.pathlib import get_repo_root
|
|
11
|
+
from utilities.typing import get_literal_elements
|
|
10
12
|
from utilities.version import Version, parse_version
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
type Mode = Literal["pyproject", "bumpversion"]
|
|
15
|
+
DEFAULT_MODE: Mode = "pyproject"
|
|
16
|
+
mode_option = option(
|
|
17
|
+
"--mode",
|
|
18
|
+
type=Choice(get_literal_elements(Mode), case_sensitive=False),
|
|
19
|
+
default=DEFAULT_MODE,
|
|
20
|
+
show_default=True,
|
|
21
|
+
)
|
|
13
22
|
|
|
14
23
|
|
|
15
|
-
def get_version(source: Path | str | bytes | TOMLDocument, /) -> Version:
|
|
24
|
+
def get_version(source: Mode | Path | str | bytes | TOMLDocument, /) -> Version:
|
|
16
25
|
"""Get the `[tool.bumpversion]` version from a TOML file."""
|
|
17
26
|
match source:
|
|
27
|
+
case "pyproject" | "bumpversion" as mode:
|
|
28
|
+
return get_version(get_toml_path(mode))
|
|
18
29
|
case Path() as path:
|
|
19
30
|
return get_version(path.read_text())
|
|
20
31
|
case str() | bytes() as text:
|
|
@@ -53,4 +64,16 @@ def get_version(source: Path | str | bytes | TOMLDocument, /) -> Version:
|
|
|
53
64
|
assert_never(never)
|
|
54
65
|
|
|
55
66
|
|
|
56
|
-
|
|
67
|
+
def get_toml_path(mode: Mode = DEFAULT_MODE, /) -> Path:
|
|
68
|
+
root = get_repo_root()
|
|
69
|
+
match mode:
|
|
70
|
+
case "pyproject":
|
|
71
|
+
filename = "pyproject.toml"
|
|
72
|
+
case "bumpversion":
|
|
73
|
+
filename = ".bumpversion.toml"
|
|
74
|
+
case never: # pyright: ignore[reportUnnecessaryComparison]
|
|
75
|
+
assert_never(never)
|
|
76
|
+
return root.relative_to(filename)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
__all__ = ["DEFAULT_MODE", "Mode", "get_toml_path", "get_version", "mode_option"]
|
|
@@ -15,8 +15,6 @@ from tomlkit import array, dumps, loads, string
|
|
|
15
15
|
from tomlkit.items import Array, Table
|
|
16
16
|
from utilities.atomicwrites import writer
|
|
17
17
|
|
|
18
|
-
from pre_commit_hooks.common import PYPROJECT_TOML
|
|
19
|
-
|
|
20
18
|
if TYPE_CHECKING:
|
|
21
19
|
from collections.abc import Iterator
|
|
22
20
|
from pathlib import Path
|
|
@@ -106,4 +104,4 @@ class _CustomSpecifierSet(SpecifierSet):
|
|
|
106
104
|
return [">=", "<"].index(spec.operator)
|
|
107
105
|
|
|
108
106
|
|
|
109
|
-
__all__ = ["
|
|
107
|
+
__all__ = ["main"]
|
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from pathlib import Path
|
|
4
3
|
from subprocess import PIPE, STDOUT, CalledProcessError, check_call, check_output
|
|
5
|
-
from typing import Literal, assert_never
|
|
6
4
|
|
|
7
|
-
from click import
|
|
5
|
+
from click import command
|
|
8
6
|
from loguru import logger
|
|
9
|
-
from utilities.pathlib import get_repo_root
|
|
10
7
|
|
|
11
|
-
from pre_commit_hooks.common import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
from pre_commit_hooks.common import (
|
|
9
|
+
DEFAULT_MODE,
|
|
10
|
+
Mode,
|
|
11
|
+
get_toml_path,
|
|
12
|
+
get_version,
|
|
13
|
+
mode_option,
|
|
14
|
+
)
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
@command()
|
|
18
|
-
@
|
|
19
|
-
|
|
20
|
-
type=Choice(["pyproject", "bumpversion"], case_sensitive=False),
|
|
21
|
-
default=_MODE,
|
|
22
|
-
show_default=True,
|
|
23
|
-
)
|
|
24
|
-
def main(*, mode: _Mode = _MODE) -> bool:
|
|
18
|
+
@mode_option
|
|
19
|
+
def main(*, mode: Mode = DEFAULT_MODE) -> bool:
|
|
25
20
|
"""CLI for the `run_bump_my_version` hook."""
|
|
26
21
|
return _process(mode=mode)
|
|
27
22
|
|
|
28
23
|
|
|
29
|
-
def _process(*, mode:
|
|
30
|
-
|
|
31
|
-
current = get_version(path)
|
|
24
|
+
def _process(*, mode: Mode = DEFAULT_MODE) -> bool:
|
|
25
|
+
current = get_version(mode)
|
|
32
26
|
commit = check_output(["git", "rev-parse", "origin/master"], text=True).rstrip("\n")
|
|
27
|
+
path = get_toml_path(mode)
|
|
33
28
|
contents = check_output(["git", "show", f"{commit}:{path}"], text=True)
|
|
34
29
|
master = get_version(contents)
|
|
35
30
|
if current in {master.bump_patch(), master.bump_minor(), master.bump_major()}:
|
|
@@ -55,15 +50,4 @@ def _process(*, mode: _Mode = _MODE) -> bool:
|
|
|
55
50
|
return False
|
|
56
51
|
|
|
57
52
|
|
|
58
|
-
def _get_rel_path(*, mode: _Mode = _MODE) -> Path:
|
|
59
|
-
match mode:
|
|
60
|
-
case "pyproject":
|
|
61
|
-
path = PYPROJECT_TOML
|
|
62
|
-
case "bumpversion":
|
|
63
|
-
path = get_repo_root().joinpath(".bumpversion.toml")
|
|
64
|
-
case never: # pyright: ignore[reportUnnecessaryComparison]
|
|
65
|
-
assert_never(never)
|
|
66
|
-
return path.relative_to(Path.cwd())
|
|
67
|
-
|
|
68
|
-
|
|
69
53
|
__all__ = ["main"]
|
|
@@ -13,7 +13,13 @@ from utilities.whenever import from_timestamp, get_now_local
|
|
|
13
13
|
from whenever import DateTimeDelta, ZonedDateTime
|
|
14
14
|
from xdg_base_dirs import xdg_cache_home
|
|
15
15
|
|
|
16
|
-
from pre_commit_hooks.common import
|
|
16
|
+
from pre_commit_hooks.common import (
|
|
17
|
+
DEFAULT_MODE,
|
|
18
|
+
Mode,
|
|
19
|
+
get_toml_path,
|
|
20
|
+
get_version,
|
|
21
|
+
mode_option,
|
|
22
|
+
)
|
|
17
23
|
|
|
18
24
|
if TYPE_CHECKING:
|
|
19
25
|
from collections.abc import Set as AbstractSet
|
|
@@ -35,26 +41,29 @@ _MAX_AGE: DateTimeDelta | None = None
|
|
|
35
41
|
default=_MAX_AGE,
|
|
36
42
|
show_default=True,
|
|
37
43
|
)
|
|
44
|
+
@mode_option
|
|
38
45
|
def main(
|
|
39
46
|
*,
|
|
40
47
|
run_every: DateTimeDelta | None = _RUN_EVERY,
|
|
41
48
|
max_age: DateTimeDelta | None = _MAX_AGE,
|
|
49
|
+
mode: Mode = DEFAULT_MODE,
|
|
42
50
|
) -> bool:
|
|
43
51
|
"""CLI for the `tag_commits` hook."""
|
|
44
|
-
return _process(run_every=run_every, max_age=max_age)
|
|
52
|
+
return _process(run_every=run_every, max_age=max_age, mode=mode)
|
|
45
53
|
|
|
46
54
|
|
|
47
55
|
def _process(
|
|
48
56
|
*,
|
|
49
57
|
run_every: DateTimeDelta | None = _RUN_EVERY,
|
|
50
58
|
max_age: DateTimeDelta | None = _MAX_AGE,
|
|
59
|
+
mode: Mode = DEFAULT_MODE,
|
|
51
60
|
) -> bool:
|
|
52
61
|
if run_every is not None:
|
|
53
62
|
last = _get_last_run()
|
|
54
63
|
min_date_time = get_now_local() - run_every
|
|
55
64
|
if (last is not None) and (min_date_time <= last):
|
|
56
65
|
return True
|
|
57
|
-
return _process_commits(max_age=max_age)
|
|
66
|
+
return _process_commits(max_age=max_age, mode=mode)
|
|
58
67
|
|
|
59
68
|
|
|
60
69
|
def _get_last_run() -> ZonedDateTime | None:
|
|
@@ -70,13 +79,16 @@ def _get_last_run() -> ZonedDateTime | None:
|
|
|
70
79
|
return None
|
|
71
80
|
|
|
72
81
|
|
|
73
|
-
def _process_commits(
|
|
82
|
+
def _process_commits(
|
|
83
|
+
*, max_age: DateTimeDelta | None = None, mode: Mode = DEFAULT_MODE
|
|
84
|
+
) -> bool:
|
|
74
85
|
repo = Repo(".", search_parent_directories=True)
|
|
75
86
|
tagged = {tag.commit.hexsha for tag in repo.tags}
|
|
76
87
|
min_date_time = None if max_age is None else (get_now_local() - max_age)
|
|
77
88
|
commits = reversed(list(repo.iter_commits(repo.refs["origin/master"])))
|
|
78
89
|
results = [
|
|
79
|
-
_process_commit(c, tagged, repo, min_date_time=min_date_time)
|
|
90
|
+
_process_commit(c, tagged, repo, min_date_time=min_date_time, mode=mode)
|
|
91
|
+
for c in commits
|
|
80
92
|
] # run all
|
|
81
93
|
return all(results)
|
|
82
94
|
|
|
@@ -88,13 +100,14 @@ def _process_commit(
|
|
|
88
100
|
/,
|
|
89
101
|
*,
|
|
90
102
|
min_date_time: ZonedDateTime | None = None,
|
|
103
|
+
mode: Mode = DEFAULT_MODE,
|
|
91
104
|
) -> bool:
|
|
92
105
|
if (commit.hexsha in tagged) or (
|
|
93
106
|
(min_date_time is not None) and (_get_date_time(commit) < min_date_time)
|
|
94
107
|
):
|
|
95
108
|
return True
|
|
96
109
|
try:
|
|
97
|
-
_tag_commit(commit, repo)
|
|
110
|
+
_tag_commit(commit, repo, mode=mode)
|
|
98
111
|
except GitCommandError:
|
|
99
112
|
return False
|
|
100
113
|
return True
|
|
@@ -104,13 +117,14 @@ def _get_date_time(commit: Commit, /) -> ZonedDateTime:
|
|
|
104
117
|
return from_timestamp(commit.committed_date, time_zone=LOCAL_TIME_ZONE_NAME)
|
|
105
118
|
|
|
106
119
|
|
|
107
|
-
def _tag_commit(commit: Commit, repo: Repo,
|
|
120
|
+
def _tag_commit(commit: Commit, repo: Repo, /, *, mode: Mode = DEFAULT_MODE) -> None:
|
|
108
121
|
sha = commit.hexsha[:7]
|
|
109
122
|
date = _get_date_time(commit)
|
|
123
|
+
path = get_toml_path(mode)
|
|
110
124
|
try:
|
|
111
|
-
joined = commit.tree.join(
|
|
125
|
+
joined = commit.tree.join(str(path))
|
|
112
126
|
except KeyError:
|
|
113
|
-
logger.exception(f"`
|
|
127
|
+
logger.exception(f"`{str(path)!r}` not found; failed to tag {sha!r} ({date})")
|
|
114
128
|
return
|
|
115
129
|
text = joined.data_stream.read()
|
|
116
130
|
version = get_version(text)
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
pre_commit_hooks/__init__.py,sha256=tiNQ40NwKZSP_S-wg-yypkGWxyH5-ueuWipPiizKx8U,59
|
|
2
|
-
pre_commit_hooks/common.py,sha256=rIfVTUYfmeQq7Vk4m_Of-JGqABZlB7dfCyGo2WTibas,2078
|
|
3
|
-
pre_commit_hooks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
pre_commit_hooks/format_requirements/__init__.py,sha256=bn1JsblINCf0ro2QrhsM8XtTOHnPFSZC2t-Hx5AJDfA,3392
|
|
5
|
-
pre_commit_hooks/format_requirements/__main__.py,sha256=15JSp_rhjI_Ddoj4MRkHFShfnYxs6GggUhLRlGtrQ0E,156
|
|
6
|
-
pre_commit_hooks/replace_sequence_str/__init__.py,sha256=a-pCAcBaa7FDsGDNLzMiD-xG20wKl-SRmhWSbm9hrvo,1618
|
|
7
|
-
pre_commit_hooks/replace_sequence_str/__main__.py,sha256=B1dxOxngV4vUVnDVrXSywiySOs1P_zF30_4ZMRsOSaY,157
|
|
8
|
-
pre_commit_hooks/run_bump_my_version/__init__.py,sha256=EOKRq04eIKojyfgfvlaPfWeKxOWkEBjmz2UOcuk6U_o,2068
|
|
9
|
-
pre_commit_hooks/run_bump_my_version/__main__.py,sha256=w2V3y61jrSau-zxjl8ciHtWPlJQwXbYxNJ2tGYVyI4s,156
|
|
10
|
-
pre_commit_hooks/tag_commits/__init__.py,sha256=AmHKjIAMfXZ6T0nw6CiOFTjFzmmVSOonmKyhASZ_sgE,3665
|
|
11
|
-
pre_commit_hooks/tag_commits/__main__.py,sha256=qefgYw7LWbvmzZS45-ym6olS4cHqw1Emw2wlqZBXN_o,148
|
|
12
|
-
dycw_pre_commit_hooks-0.12.2.dist-info/METADATA,sha256=DdndJ2NzELgAG-gBuL1cvnDLTEPCAe04GMhKLjju-zs,1029
|
|
13
|
-
dycw_pre_commit_hooks-0.12.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
14
|
-
dycw_pre_commit_hooks-0.12.2.dist-info/entry_points.txt,sha256=r1tnPzaGvOrSdX-ZRriidf8AhZgUtXfjdTpwpkTBA8U,260
|
|
15
|
-
dycw_pre_commit_hooks-0.12.2.dist-info/RECORD,,
|
|
File without changes
|
{dycw_pre_commit_hooks-0.12.2.dist-info → dycw_pre_commit_hooks-0.12.3.dist-info}/entry_points.txt
RENAMED
|
File without changes
|