dycw-pre-commit-hooks 0.14.26__py3-none-any.whl → 0.14.39__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.
- {dycw_pre_commit_hooks-0.14.26.dist-info → dycw_pre_commit_hooks-0.14.39.dist-info}/METADATA +1 -1
- dycw_pre_commit_hooks-0.14.39.dist-info/RECORD +28 -0
- {dycw_pre_commit_hooks-0.14.26.dist-info → dycw_pre_commit_hooks-0.14.39.dist-info}/entry_points.txt +5 -0
- pre_commit_hooks/__init__.py +1 -1
- pre_commit_hooks/constants.py +18 -1
- pre_commit_hooks/hooks/add_hooks.py +476 -64
- pre_commit_hooks/hooks/check_version_bumped.py +37 -0
- pre_commit_hooks/hooks/check_versions_consistent.py +2 -2
- pre_commit_hooks/hooks/run_version_bump.py +9 -14
- pre_commit_hooks/hooks/setup_bump_my_version.py +99 -0
- pre_commit_hooks/hooks/setup_direnv.py +142 -0
- pre_commit_hooks/hooks/update_ci_action_versions.py +47 -0
- pre_commit_hooks/hooks/update_ci_extensions.py +34 -0
- pre_commit_hooks/utilities.py +38 -97
- dycw_pre_commit_hooks-0.14.26.dist-info/RECORD +0 -23
- {dycw_pre_commit_hooks-0.14.26.dist-info → dycw_pre_commit_hooks-0.14.39.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from click import command
|
|
6
|
+
from utilities.click import CONTEXT_SETTINGS
|
|
7
|
+
from utilities.os import is_pytest
|
|
8
|
+
|
|
9
|
+
from pre_commit_hooks.constants import BUMPVERSION_TOML
|
|
10
|
+
from pre_commit_hooks.utilities import (
|
|
11
|
+
get_version_from_path,
|
|
12
|
+
get_version_origin_master,
|
|
13
|
+
run_all_maybe_raise,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from utilities.types import PathLike
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@command(**CONTEXT_SETTINGS)
|
|
21
|
+
def _main() -> None:
|
|
22
|
+
if is_pytest():
|
|
23
|
+
return
|
|
24
|
+
run_all_maybe_raise(_run)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _run(*, path: PathLike = BUMPVERSION_TOML) -> bool:
|
|
28
|
+
try:
|
|
29
|
+
current = get_version_from_path(path=path)
|
|
30
|
+
prev = get_version_origin_master(path=path)
|
|
31
|
+
except ValueError:
|
|
32
|
+
return False
|
|
33
|
+
return current != prev
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
_main()
|
|
@@ -12,7 +12,7 @@ from pre_commit_hooks.constants import BUMPVERSION_TOML, paths_argument
|
|
|
12
12
|
from pre_commit_hooks.utilities import (
|
|
13
13
|
get_version_from_path,
|
|
14
14
|
run_all_maybe_raise,
|
|
15
|
-
|
|
15
|
+
set_version,
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
if TYPE_CHECKING:
|
|
@@ -32,7 +32,7 @@ def _main(*, paths: tuple[Path, ...]) -> None:
|
|
|
32
32
|
def _run(*, path: PathLike = BUMPVERSION_TOML) -> bool:
|
|
33
33
|
version = get_version_from_path(path=path)
|
|
34
34
|
try:
|
|
35
|
-
|
|
35
|
+
set_version(version, path=path)
|
|
36
36
|
except CalledProcessError:
|
|
37
37
|
return False
|
|
38
38
|
return True
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from functools import partial
|
|
4
|
-
from subprocess import CalledProcessError
|
|
5
4
|
from typing import TYPE_CHECKING
|
|
6
5
|
|
|
7
6
|
from click import command
|
|
8
7
|
from utilities.click import CONTEXT_SETTINGS
|
|
9
8
|
from utilities.os import is_pytest
|
|
10
|
-
from utilities.version import Version3
|
|
9
|
+
from utilities.version import Version3
|
|
11
10
|
|
|
12
11
|
from pre_commit_hooks.constants import BUMPVERSION_TOML, paths_argument
|
|
13
12
|
from pre_commit_hooks.utilities import (
|
|
14
|
-
get_version_from_git_show,
|
|
15
|
-
get_version_from_git_tag,
|
|
16
13
|
get_version_from_path,
|
|
14
|
+
get_version_origin_master,
|
|
17
15
|
run_all_maybe_raise,
|
|
18
|
-
|
|
16
|
+
set_version,
|
|
19
17
|
)
|
|
20
18
|
|
|
21
19
|
if TYPE_CHECKING:
|
|
@@ -34,18 +32,15 @@ def _main(*, paths: tuple[Path, ...]) -> None:
|
|
|
34
32
|
|
|
35
33
|
def _run(*, path: PathLike = BUMPVERSION_TOML) -> bool:
|
|
36
34
|
try:
|
|
37
|
-
prev =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
run_bump_my_version(Version3(0, 1, 0), path=path)
|
|
43
|
-
return False
|
|
44
|
-
current = get_version_from_path(path=path)
|
|
35
|
+
prev = get_version_origin_master(path=path)
|
|
36
|
+
current = get_version_from_path(path=path)
|
|
37
|
+
except ValueError:
|
|
38
|
+
set_version(Version3(0, 1, 0), path=path)
|
|
39
|
+
return False
|
|
45
40
|
patched = prev.bump_patch()
|
|
46
41
|
if current in {patched, prev.bump_minor(), prev.bump_major()}:
|
|
47
42
|
return True
|
|
48
|
-
|
|
43
|
+
set_version(patched, path=path)
|
|
49
44
|
return False
|
|
50
45
|
|
|
51
46
|
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from functools import partial
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from click import command
|
|
8
|
+
from tomlkit import table
|
|
9
|
+
from utilities.click import CONTEXT_SETTINGS
|
|
10
|
+
from utilities.os import is_pytest
|
|
11
|
+
from utilities.string import substitute
|
|
12
|
+
from utilities.version import Version3
|
|
13
|
+
|
|
14
|
+
from pre_commit_hooks.constants import (
|
|
15
|
+
BUMPVERSION_TOML,
|
|
16
|
+
PYPROJECT_TOML,
|
|
17
|
+
paths_argument,
|
|
18
|
+
python_package_name_option,
|
|
19
|
+
)
|
|
20
|
+
from pre_commit_hooks.utilities import (
|
|
21
|
+
ensure_contains,
|
|
22
|
+
get_set_aot,
|
|
23
|
+
get_set_table,
|
|
24
|
+
get_table,
|
|
25
|
+
run_all_maybe_raise,
|
|
26
|
+
yield_toml_doc,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
if TYPE_CHECKING:
|
|
30
|
+
from collections.abc import MutableSet
|
|
31
|
+
|
|
32
|
+
from utilities.types import PathLike
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@command(**CONTEXT_SETTINGS)
|
|
36
|
+
@paths_argument
|
|
37
|
+
@python_package_name_option
|
|
38
|
+
def _main(*, paths: tuple[Path, ...], python_package_name: str | None = None) -> None:
|
|
39
|
+
if is_pytest():
|
|
40
|
+
return
|
|
41
|
+
run_all_maybe_raise(
|
|
42
|
+
*(
|
|
43
|
+
partial(
|
|
44
|
+
_run,
|
|
45
|
+
path=p.parent / BUMPVERSION_TOML,
|
|
46
|
+
python_package_name=python_package_name,
|
|
47
|
+
)
|
|
48
|
+
for p in paths
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _run(
|
|
54
|
+
*, path: PathLike = BUMPVERSION_TOML, python_package_name: str | None = None
|
|
55
|
+
) -> bool:
|
|
56
|
+
path = Path(path)
|
|
57
|
+
modifications: set[Path] = set()
|
|
58
|
+
with yield_toml_doc(path, modifications=modifications) as doc:
|
|
59
|
+
tool = get_set_table(doc, "tool")
|
|
60
|
+
bumpversion = get_set_table(tool, "bumpversion")
|
|
61
|
+
bumpversion["allow_dirty"] = True
|
|
62
|
+
bumpversion.setdefault("current_version", str(Version3(0, 1, 0)))
|
|
63
|
+
if python_package_name is not None:
|
|
64
|
+
_add_file(
|
|
65
|
+
'version = "${version}"',
|
|
66
|
+
path.parent / PYPROJECT_TOML,
|
|
67
|
+
path_bumpversion_toml=path,
|
|
68
|
+
modifications=modifications,
|
|
69
|
+
)
|
|
70
|
+
_add_file(
|
|
71
|
+
'__version__ = "${version}"',
|
|
72
|
+
path.parent / "src" / python_package_name / "__init__.py",
|
|
73
|
+
path_bumpversion_toml=path,
|
|
74
|
+
modifications=modifications,
|
|
75
|
+
)
|
|
76
|
+
return len(modifications) == 0
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _add_file(
|
|
80
|
+
path_data: PathLike,
|
|
81
|
+
template: PathLike,
|
|
82
|
+
/,
|
|
83
|
+
*,
|
|
84
|
+
path_bumpversion_toml: PathLike = BUMPVERSION_TOML,
|
|
85
|
+
modifications: MutableSet[Path] | None = None,
|
|
86
|
+
) -> None:
|
|
87
|
+
with yield_toml_doc(path_bumpversion_toml, modifications=modifications) as doc:
|
|
88
|
+
tool = get_table(doc, "tool")
|
|
89
|
+
bumpversion = get_table(tool, "bumpversion")
|
|
90
|
+
files = get_set_aot(bumpversion, "files")
|
|
91
|
+
tab = table()
|
|
92
|
+
tab["filename"] = str(path_data)
|
|
93
|
+
tab["search"] = substitute(template, version="{current_version}")
|
|
94
|
+
tab["replace"] = substitute(template, version="{new_version}")
|
|
95
|
+
ensure_contains(files, tab)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
_main()
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from functools import partial
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from re import MULTILINE, escape, search
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
from click import command
|
|
9
|
+
from utilities.click import CONTEXT_SETTINGS
|
|
10
|
+
from utilities.iterables import always_iterable
|
|
11
|
+
from utilities.os import is_pytest
|
|
12
|
+
from utilities.text import strip_and_dedent
|
|
13
|
+
from utilities.types import PathLike
|
|
14
|
+
|
|
15
|
+
from pre_commit_hooks.constants import (
|
|
16
|
+
DEFAULT_PYTHON_VERSION,
|
|
17
|
+
ENVRC,
|
|
18
|
+
paths_argument,
|
|
19
|
+
python_option,
|
|
20
|
+
python_uv_index_option,
|
|
21
|
+
python_uv_native_tls_option,
|
|
22
|
+
python_version_option,
|
|
23
|
+
)
|
|
24
|
+
from pre_commit_hooks.utilities import run_all_maybe_raise, yield_text_file
|
|
25
|
+
|
|
26
|
+
if TYPE_CHECKING:
|
|
27
|
+
from collections.abc import MutableSet
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
from utilities.types import MaybeSequenceStr, PathLike
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@command(**CONTEXT_SETTINGS)
|
|
34
|
+
@paths_argument
|
|
35
|
+
@python_option
|
|
36
|
+
@python_uv_index_option
|
|
37
|
+
@python_uv_native_tls_option
|
|
38
|
+
@python_version_option
|
|
39
|
+
def _main(
|
|
40
|
+
*,
|
|
41
|
+
paths: tuple[Path, ...],
|
|
42
|
+
python: bool = False,
|
|
43
|
+
python_uv_index: MaybeSequenceStr | None = None,
|
|
44
|
+
python_uv_native_tls: bool = False,
|
|
45
|
+
python_version: str = DEFAULT_PYTHON_VERSION,
|
|
46
|
+
) -> None:
|
|
47
|
+
if is_pytest():
|
|
48
|
+
return
|
|
49
|
+
run_all_maybe_raise(
|
|
50
|
+
*(
|
|
51
|
+
partial(
|
|
52
|
+
_run,
|
|
53
|
+
path=p.parent / ENVRC,
|
|
54
|
+
python=python,
|
|
55
|
+
python_uv_index=python_uv_index,
|
|
56
|
+
python_uv_native_tls=python_uv_native_tls,
|
|
57
|
+
python_version=python_version,
|
|
58
|
+
)
|
|
59
|
+
for p in paths
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _run(
|
|
65
|
+
*,
|
|
66
|
+
path: PathLike = ENVRC,
|
|
67
|
+
python: bool = False,
|
|
68
|
+
python_uv_index: MaybeSequenceStr | None = None,
|
|
69
|
+
python_uv_native_tls: bool = False,
|
|
70
|
+
python_version: str = DEFAULT_PYTHON_VERSION,
|
|
71
|
+
) -> bool:
|
|
72
|
+
modifications: set[Path] = set()
|
|
73
|
+
with yield_text_file(path, modifications=modifications) as context:
|
|
74
|
+
shebang = strip_and_dedent("""
|
|
75
|
+
#!/usr/bin/env sh
|
|
76
|
+
# shellcheck source=/dev/null
|
|
77
|
+
""")
|
|
78
|
+
if search(escape(shebang), context.output, flags=MULTILINE) is None:
|
|
79
|
+
context.output += f"\n\n{shebang}"
|
|
80
|
+
if python:
|
|
81
|
+
_add_python(
|
|
82
|
+
path=path,
|
|
83
|
+
modifications=modifications,
|
|
84
|
+
uv_index=python_uv_index,
|
|
85
|
+
uv_native_tls=python_uv_native_tls,
|
|
86
|
+
version=python_version,
|
|
87
|
+
)
|
|
88
|
+
return len(modifications) == 0
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _add_python(
|
|
92
|
+
*,
|
|
93
|
+
path: PathLike = ENVRC,
|
|
94
|
+
modifications: MutableSet[Path] | None = None,
|
|
95
|
+
uv_index: MaybeSequenceStr | None = None,
|
|
96
|
+
uv_native_tls: bool = False,
|
|
97
|
+
version: str = DEFAULT_PYTHON_VERSION,
|
|
98
|
+
) -> None:
|
|
99
|
+
with yield_text_file(path, modifications=modifications) as context:
|
|
100
|
+
text = _get_text(
|
|
101
|
+
uv_index=uv_index, uv_native_tls=uv_native_tls, version=version
|
|
102
|
+
)
|
|
103
|
+
if search(escape(text), context.output, flags=MULTILINE) is None:
|
|
104
|
+
context.output += f"\n\n{text}"
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _get_text(
|
|
108
|
+
*,
|
|
109
|
+
uv_index: MaybeSequenceStr | None = None,
|
|
110
|
+
uv_native_tls: bool = False,
|
|
111
|
+
version: str = DEFAULT_PYTHON_VERSION,
|
|
112
|
+
) -> str:
|
|
113
|
+
lines: list[str] = ["# uv", "export UV_MANAGED_PYTHON='true'"]
|
|
114
|
+
if uv_index is not None:
|
|
115
|
+
lines.append(f"export UV_INDEX='{','.join(always_iterable(uv_index))}'")
|
|
116
|
+
if uv_native_tls:
|
|
117
|
+
lines.append("export UV_NATIVE_TLS='true'")
|
|
118
|
+
lines.extend([
|
|
119
|
+
"export UV_PRERELEASE='disallow'",
|
|
120
|
+
f"export UV_PYTHON='{version}'",
|
|
121
|
+
"export UV_RESOLUTION='highest'",
|
|
122
|
+
"export UV_VENV_CLEAR=1",
|
|
123
|
+
strip_and_dedent("""\
|
|
124
|
+
if ! command -v uv >/dev/null 2>&1; then
|
|
125
|
+
\techo_date "ERROR: 'uv' not found" && exit 1
|
|
126
|
+
fi
|
|
127
|
+
"""),
|
|
128
|
+
"activate='.venv/bin/activate'",
|
|
129
|
+
strip_and_dedent("""\
|
|
130
|
+
if [ -f $activate ]; then
|
|
131
|
+
\t. $activate
|
|
132
|
+
else
|
|
133
|
+
\tuv venv
|
|
134
|
+
fi
|
|
135
|
+
"""),
|
|
136
|
+
"uv sync --all-extras --all-groups --active --locked",
|
|
137
|
+
])
|
|
138
|
+
return "\n".join(lines) + "\n"
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
if __name__ == "__main__":
|
|
142
|
+
_main()
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from functools import partial
|
|
4
|
+
from re import MULTILINE, sub
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from click import command
|
|
8
|
+
from utilities.click import CONTEXT_SETTINGS
|
|
9
|
+
from utilities.os import is_pytest
|
|
10
|
+
|
|
11
|
+
from pre_commit_hooks.constants import paths_argument
|
|
12
|
+
from pre_commit_hooks.utilities import run_all_maybe_raise, yield_text_file
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
from utilities.types import PathLike
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@command(**CONTEXT_SETTINGS)
|
|
21
|
+
@paths_argument
|
|
22
|
+
def _main(*, paths: tuple[Path, ...]) -> None:
|
|
23
|
+
if is_pytest():
|
|
24
|
+
return
|
|
25
|
+
run_all_maybe_raise(*(partial(_run, p) for p in paths))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _run(path: PathLike, /) -> bool:
|
|
29
|
+
modifications: set[Path] = set()
|
|
30
|
+
versions = {
|
|
31
|
+
"actions/checkout": "v6",
|
|
32
|
+
"actions/setup-python": "v6",
|
|
33
|
+
"astral-sh/ruff-action": "v3",
|
|
34
|
+
"astral-sh/setup-uv": "v7",
|
|
35
|
+
}
|
|
36
|
+
with yield_text_file(path, modifications=modifications) as context:
|
|
37
|
+
text = context.input
|
|
38
|
+
for action, version in versions.items():
|
|
39
|
+
text = sub(
|
|
40
|
+
rf"^(\s*- uses: {action})@.+$", rf"\1@{version}", text, flags=MULTILINE
|
|
41
|
+
)
|
|
42
|
+
context.output = text
|
|
43
|
+
return len(modifications) == 0
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
_main()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from functools import partial
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from click import command
|
|
8
|
+
from utilities.atomicwrites import move
|
|
9
|
+
from utilities.click import CONTEXT_SETTINGS
|
|
10
|
+
from utilities.os import is_pytest
|
|
11
|
+
|
|
12
|
+
from pre_commit_hooks.constants import paths_argument
|
|
13
|
+
from pre_commit_hooks.utilities import run_all_maybe_raise
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from utilities.types import PathLike
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@command(**CONTEXT_SETTINGS)
|
|
20
|
+
@paths_argument
|
|
21
|
+
def _main(*, paths: tuple[Path, ...]) -> None:
|
|
22
|
+
if is_pytest():
|
|
23
|
+
return
|
|
24
|
+
run_all_maybe_raise(*(partial(_run, p) for p in paths))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _run(path: PathLike, /) -> bool:
|
|
28
|
+
new = Path(path).with_suffix(".yaml")
|
|
29
|
+
move(path, new)
|
|
30
|
+
return False
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == "__main__":
|
|
34
|
+
_main()
|
pre_commit_hooks/utilities.py
CHANGED
|
@@ -7,12 +7,13 @@ from dataclasses import dataclass
|
|
|
7
7
|
from functools import partial
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
from subprocess import CalledProcessError
|
|
10
|
-
from typing import TYPE_CHECKING, Any,
|
|
10
|
+
from typing import TYPE_CHECKING, Any, assert_never, overload
|
|
11
11
|
|
|
12
12
|
import tomlkit
|
|
13
13
|
import yaml
|
|
14
14
|
from libcst import Module, parse_module
|
|
15
15
|
from tomlkit import TOMLDocument, aot, array, document, string, table
|
|
16
|
+
from tomlkit.exceptions import ParseError
|
|
16
17
|
from tomlkit.items import AoT, Array, Table
|
|
17
18
|
from utilities.atomicwrites import writer
|
|
18
19
|
from utilities.concurrent import concurrent_map
|
|
@@ -24,14 +25,7 @@ from utilities.types import PathLike, StrDict
|
|
|
24
25
|
from utilities.typing import is_str_dict
|
|
25
26
|
from utilities.version import Version3, Version3Error
|
|
26
27
|
|
|
27
|
-
from pre_commit_hooks.constants import
|
|
28
|
-
BUMPVERSION_TOML,
|
|
29
|
-
FORMATTER_PRIORITY,
|
|
30
|
-
LINTER_PRIORITY,
|
|
31
|
-
PATH_CACHE,
|
|
32
|
-
PRE_COMMIT_CONFIG_YAML,
|
|
33
|
-
PYPROJECT_TOML,
|
|
34
|
-
)
|
|
28
|
+
from pre_commit_hooks.constants import BUMPVERSION_TOML, PATH_CACHE, PYPROJECT_TOML
|
|
35
29
|
|
|
36
30
|
if TYPE_CHECKING:
|
|
37
31
|
from collections.abc import Callable, Iterable, Iterator, MutableSet
|
|
@@ -46,58 +40,8 @@ if TYPE_CHECKING:
|
|
|
46
40
|
)
|
|
47
41
|
|
|
48
42
|
|
|
49
|
-
def
|
|
50
|
-
|
|
51
|
-
id_: str,
|
|
52
|
-
/,
|
|
53
|
-
*,
|
|
54
|
-
path: PathLike = PRE_COMMIT_CONFIG_YAML,
|
|
55
|
-
modifications: MutableSet[Path] | None = None,
|
|
56
|
-
rev: bool = False,
|
|
57
|
-
name: str | None = None,
|
|
58
|
-
entry: str | None = None,
|
|
59
|
-
language: str | None = None,
|
|
60
|
-
files: str | None = None,
|
|
61
|
-
types_or: list[str] | None = None,
|
|
62
|
-
args: tuple[Literal["add", "exact"], list[str]] | None = None,
|
|
63
|
-
type_: Literal["formatter", "linter"] | None = None,
|
|
64
|
-
) -> None:
|
|
65
|
-
with yield_yaml_dict(path, modifications=modifications) as dict_:
|
|
66
|
-
repos_list = get_set_list_dicts(dict_, "repos")
|
|
67
|
-
repo_dict = ensure_contains_partial_dict(
|
|
68
|
-
repos_list, {"repo": url}, extra={"rev": "master"} if rev else {}
|
|
69
|
-
)
|
|
70
|
-
hooks_list = get_set_list_dicts(repo_dict, "hooks")
|
|
71
|
-
hook_dict = ensure_contains_partial_dict(hooks_list, {"id": id_})
|
|
72
|
-
if name is not None:
|
|
73
|
-
hook_dict["name"] = name
|
|
74
|
-
if entry is not None:
|
|
75
|
-
hook_dict["entry"] = entry
|
|
76
|
-
if language is not None:
|
|
77
|
-
hook_dict["language"] = language
|
|
78
|
-
if files is not None:
|
|
79
|
-
hook_dict["files"] = files
|
|
80
|
-
if types_or is not None:
|
|
81
|
-
hook_dict["types_or"] = types_or
|
|
82
|
-
if args is not None:
|
|
83
|
-
match args:
|
|
84
|
-
case "add", list() as args_i:
|
|
85
|
-
hook_args = get_set_list_strs(hook_dict, "args")
|
|
86
|
-
ensure_contains(hook_args, *args_i)
|
|
87
|
-
case "exact", list() as args_i:
|
|
88
|
-
hook_dict["args"] = args_i
|
|
89
|
-
case never:
|
|
90
|
-
assert_never(never)
|
|
91
|
-
match type_:
|
|
92
|
-
case "formatter":
|
|
93
|
-
hook_dict["priority"] = FORMATTER_PRIORITY
|
|
94
|
-
case "linter":
|
|
95
|
-
hook_dict["priority"] = LINTER_PRIORITY
|
|
96
|
-
case None:
|
|
97
|
-
...
|
|
98
|
-
case never:
|
|
99
|
-
assert_never(never)
|
|
100
|
-
run_prettier(path)
|
|
43
|
+
def apply[T](func: Callable[[], T], /) -> T:
|
|
44
|
+
return func()
|
|
101
45
|
|
|
102
46
|
|
|
103
47
|
##
|
|
@@ -357,30 +301,35 @@ class PyProjectDependencies:
|
|
|
357
301
|
##
|
|
358
302
|
|
|
359
303
|
|
|
360
|
-
def
|
|
361
|
-
text =
|
|
304
|
+
def get_version_from_path(*, path: PathLike = BUMPVERSION_TOML) -> Version3:
|
|
305
|
+
text = Path(path).read_text()
|
|
362
306
|
return _get_version_from_toml_text(text)
|
|
363
307
|
|
|
364
308
|
|
|
365
|
-
def
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
309
|
+
def get_version_origin_master(*, path: PathLike = BUMPVERSION_TOML) -> Version3:
|
|
310
|
+
with suppress(CalledProcessError):
|
|
311
|
+
text = run("git", "tag", "--points-at", "origin/master", return_=True)
|
|
312
|
+
for line in text.splitlines():
|
|
313
|
+
with suppress(Version3Error):
|
|
314
|
+
return Version3.parse(line)
|
|
315
|
+
try:
|
|
316
|
+
text = run("git", "show", f"origin/master:{path}", return_=True)
|
|
317
|
+
except CalledProcessError:
|
|
318
|
+
msg = "Unable to get the version of origin/master"
|
|
319
|
+
raise ValueError(msg) from None
|
|
376
320
|
return _get_version_from_toml_text(text)
|
|
377
321
|
|
|
378
322
|
|
|
379
323
|
def _get_version_from_toml_text(text: str, /) -> Version3:
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
324
|
+
try:
|
|
325
|
+
doc = tomlkit.parse(text)
|
|
326
|
+
tool = get_table(doc, "tool")
|
|
327
|
+
bumpversion = get_table(tool, "bumpversion")
|
|
328
|
+
version = bumpversion["current_version"]
|
|
329
|
+
return Version3.parse(str(version))
|
|
330
|
+
except (ParseError, KeyError, Version3Error):
|
|
331
|
+
msg = f"Unable to get the version from {text!r}"
|
|
332
|
+
raise ValueError(msg) from None
|
|
384
333
|
|
|
385
334
|
|
|
386
335
|
##
|
|
@@ -397,24 +346,11 @@ def path_throttle_cache(name: str, /) -> Path:
|
|
|
397
346
|
def run_all_maybe_raise(*funcs: Callable[[], bool]) -> None:
|
|
398
347
|
"""Run all of a set of jobs."""
|
|
399
348
|
|
|
400
|
-
results = concurrent_map(
|
|
349
|
+
results = concurrent_map(apply, funcs, parallelism="threads")
|
|
401
350
|
if not all(results):
|
|
402
351
|
raise SystemExit(1)
|
|
403
352
|
|
|
404
353
|
|
|
405
|
-
def _apply[T](func: Callable[[], T], /) -> T:
|
|
406
|
-
return func()
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
##
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
def run_bump_my_version(
|
|
413
|
-
version: Version3, /, *, path: PathLike = BUMPVERSION_TOML
|
|
414
|
-
) -> None:
|
|
415
|
-
run("bump-my-version", "replace", "--new-version", str(version), str(path))
|
|
416
|
-
|
|
417
|
-
|
|
418
354
|
##
|
|
419
355
|
|
|
420
356
|
|
|
@@ -441,6 +377,13 @@ def run_taplo(path: PathLike, /) -> None:
|
|
|
441
377
|
##
|
|
442
378
|
|
|
443
379
|
|
|
380
|
+
def set_version(version: Version3, /, *, path: PathLike = BUMPVERSION_TOML) -> None:
|
|
381
|
+
run("bump-my-version", "replace", "--new-version", str(version), str(path))
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
##
|
|
385
|
+
|
|
386
|
+
|
|
444
387
|
def write_text(
|
|
445
388
|
path: PathLike, text: str, /, *, modifications: MutableSet[Path] | None = None
|
|
446
389
|
) -> None:
|
|
@@ -512,7 +455,6 @@ def yield_json_dict(
|
|
|
512
455
|
path, json.loads, dict, json.dumps, modifications=modifications
|
|
513
456
|
) as dict_:
|
|
514
457
|
yield dict_
|
|
515
|
-
run_prettier(path)
|
|
516
458
|
|
|
517
459
|
|
|
518
460
|
##
|
|
@@ -616,7 +558,7 @@ def yield_yaml_dict(
|
|
|
616
558
|
|
|
617
559
|
__all__ = [
|
|
618
560
|
"PyProjectDependencies",
|
|
619
|
-
"
|
|
561
|
+
"apply",
|
|
620
562
|
"are_equal_modulo_new_line",
|
|
621
563
|
"ensure_contains",
|
|
622
564
|
"ensure_contains_partial_dict",
|
|
@@ -638,14 +580,13 @@ __all__ = [
|
|
|
638
580
|
"get_set_list_strs",
|
|
639
581
|
"get_set_table",
|
|
640
582
|
"get_table",
|
|
641
|
-
"get_version_from_git_show",
|
|
642
|
-
"get_version_from_git_tag",
|
|
643
583
|
"get_version_from_path",
|
|
584
|
+
"get_version_origin_master",
|
|
644
585
|
"path_throttle_cache",
|
|
645
586
|
"run_all_maybe_raise",
|
|
646
|
-
"run_bump_my_version",
|
|
647
587
|
"run_prettier",
|
|
648
588
|
"run_taplo",
|
|
589
|
+
"set_version",
|
|
649
590
|
"write_text",
|
|
650
591
|
"yield_immutable_write_context",
|
|
651
592
|
"yield_json_dict",
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
pre_commit_hooks/__init__.py,sha256=wC4VQm-toN3GxegASlI_2t9iCebEI0dtkRlXIjALVfE,60
|
|
2
|
-
pre_commit_hooks/configs/gitignore,sha256=pIcfamKg40Tg2aWiMyY4pxHkSGNITRFD-ByA2wWGHQI,5062
|
|
3
|
-
pre_commit_hooks/constants.py,sha256=Qao_jiJhW9M10hfqlr0bMtPubdg3ksCGsDNXY7jxZC4,3553
|
|
4
|
-
pre_commit_hooks/hooks/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
|
|
5
|
-
pre_commit_hooks/hooks/add_future_import_annotations.py,sha256=vUVaQIMrfPssrP0keiau-o8Jel2rpaXLi6pyT_d-QsU,1701
|
|
6
|
-
pre_commit_hooks/hooks/add_hooks.py,sha256=7Ow5pN-XGMUe3h3kWtVkXqFcZgdw_wHvUffV7ZNvmus,10457
|
|
7
|
-
pre_commit_hooks/hooks/check_versions_consistent.py,sha256=vg7fsrJ4-_dVzyKCgw4KI_QSC2eam7vFjjYbmtM8RjM,996
|
|
8
|
-
pre_commit_hooks/hooks/format_pre_commit_config.py,sha256=Vml8Mq5gFunOigs6l3FkTTMBaImYxtKfIehdMuYMO2E,1984
|
|
9
|
-
pre_commit_hooks/hooks/format_requirements.py,sha256=R_FnEUx7jU3W5rWshLBKO2bX-cReHteF4iqm_mCnyCk,1474
|
|
10
|
-
pre_commit_hooks/hooks/replace_sequence_str.py,sha256=G7JQ4n-hSjW5asM4C77ps8JYv5eV31rvFmmcxQYty1o,1816
|
|
11
|
-
pre_commit_hooks/hooks/run_prek_autoupdate.py,sha256=SItY4GPTde7HXOaNy3zXsfFQFFZsc4hZzGzf380F0aI,1556
|
|
12
|
-
pre_commit_hooks/hooks/run_version_bump.py,sha256=ZvRYfx0E_aFg0T95f5p2mL_8PdJZ7BQuLngKAqrZvaM,1469
|
|
13
|
-
pre_commit_hooks/hooks/setup_git.py,sha256=nB87iKOuCPpc52RvLMRKzP-HZO53NluaX12k1JgxjfE,1193
|
|
14
|
-
pre_commit_hooks/hooks/setup_pyright.py,sha256=DW9QdVE18aMzue8gLXxM4pnCIIooWm4DN-HDwM3A4RM,2565
|
|
15
|
-
pre_commit_hooks/hooks/setup_ruff.py,sha256=GZlEtnc4mj4hAIjHxHQRoi9LQYDYCS4zPcZL8nWFKfg,4651
|
|
16
|
-
pre_commit_hooks/hooks/update_requirements.py,sha256=2AypcOpCnZFhsBFHsHHYbUMBi9P-qtMWrrXlKWcM6B8,5303
|
|
17
|
-
pre_commit_hooks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
-
pre_commit_hooks/types.py,sha256=ObWi-OEEyZHlSYZA3iiJHGMDJ3jADntS_OpR0jXpkDk,515
|
|
19
|
-
pre_commit_hooks/utilities.py,sha256=qwlFv4ffbTBBHrl_Uq7AQLfOM8J4yIvXS94Ix0_IqNQ,17842
|
|
20
|
-
dycw_pre_commit_hooks-0.14.26.dist-info/WHEEL,sha256=XV0cjMrO7zXhVAIyyc8aFf1VjZ33Fen4IiJk5zFlC3g,80
|
|
21
|
-
dycw_pre_commit_hooks-0.14.26.dist-info/entry_points.txt,sha256=QaLSZP2kUPAi9OWYnq9aPpKFcMW6q4lVgh12txUNKKA,839
|
|
22
|
-
dycw_pre_commit_hooks-0.14.26.dist-info/METADATA,sha256=yqLok615QKWky2VZIhap9f1L4WFM4PBL7qNTeH9Hx6o,1501
|
|
23
|
-
dycw_pre_commit_hooks-0.14.26.dist-info/RECORD,,
|
|
File without changes
|