dycw-pre-commit-hooks 0.10.24__py3-none-any.whl → 0.11.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.10.24.dist-info → dycw_pre_commit_hooks-0.11.1.dist-info}/METADATA +5 -5
- dycw_pre_commit_hooks-0.11.1.dist-info/RECORD +13 -0
- {dycw_pre_commit_hooks-0.10.24.dist-info → dycw_pre_commit_hooks-0.11.1.dist-info}/entry_points.txt +1 -1
- pre_commit_hooks/__init__.py +1 -1
- pre_commit_hooks/common.py +1 -64
- pre_commit_hooks/replace_sequence_str/__init__.py +55 -0
- pre_commit_hooks/{run_bump2version → replace_sequence_str}/__main__.py +1 -1
- pre_commit_hooks/run_bump_my_version/__init__.py +10 -1
- pre_commit_hooks/run_ruff_format/__init__.py +3 -0
- dycw_pre_commit_hooks-0.10.24.dist-info/RECORD +0 -13
- pre_commit_hooks/run_bump2version/__init__.py +0 -46
- {dycw_pre_commit_hooks-0.10.24.dist-info → dycw_pre_commit_hooks-0.11.1.dist-info}/WHEEL +0 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dycw-pre-commit-hooks
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.1
|
|
4
4
|
Author-email: Derek Wan <d.wan@icloud.com>
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
|
-
Requires-Dist: click<8.
|
|
7
|
-
Requires-Dist: dycw-utilities<0.
|
|
6
|
+
Requires-Dist: click<8.3,>=8.2.1
|
|
7
|
+
Requires-Dist: dycw-utilities<0.126,>=0.125.10
|
|
8
|
+
Requires-Dist: libcst<1.9,>=1.8.2
|
|
8
9
|
Requires-Dist: loguru<0.8,>=0.7.3
|
|
9
|
-
Requires-Dist: semver<3.1,>=3.0.4
|
|
10
10
|
Requires-Dist: tomlkit<0.14,>=0.13.2
|
|
11
|
-
Requires-Dist: xdg-base-dirs<6.1,>=6.0.2
|
|
12
11
|
Description-Content-Type: text/markdown
|
|
13
12
|
|
|
14
13
|
# pre-commit-hooks
|
|
@@ -28,6 +27,7 @@ My [`pre-commit`](https://pre-commit.com/) hooks.
|
|
|
28
27
|
- repo: https://github.com/dycw/pre-commit-hooks
|
|
29
28
|
rev: master
|
|
30
29
|
hooks:
|
|
30
|
+
- id: replace-sequence-str
|
|
31
31
|
- id: run-bump-my-version
|
|
32
32
|
- id: run-ruff-format
|
|
33
33
|
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
pre_commit_hooks/__init__.py,sha256=IWWm5-glkVVtfXOLWV-9Tpv8zpUi5iBJpqgf9lTpzdw,59
|
|
2
|
+
pre_commit_hooks/common.py,sha256=sApXaiGpUrPfzlneJQYPYonm8ikWQWNdI6BK7Is8bcA,691
|
|
3
|
+
pre_commit_hooks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
pre_commit_hooks/replace_sequence_str/__init__.py,sha256=bPkc3KHbu8RMFykIsegW06hAKUXtXjJD36KtECDsNR8,1607
|
|
5
|
+
pre_commit_hooks/replace_sequence_str/__main__.py,sha256=B1dxOxngV4vUVnDVrXSywiySOs1P_zF30_4ZMRsOSaY,157
|
|
6
|
+
pre_commit_hooks/run_bump_my_version/__init__.py,sha256=9RpVVqTmtmKkV8rMR4sMfI-i_7gaLOmNrfi2GWgtNSk,1953
|
|
7
|
+
pre_commit_hooks/run_bump_my_version/__main__.py,sha256=w2V3y61jrSau-zxjl8ciHtWPlJQwXbYxNJ2tGYVyI4s,156
|
|
8
|
+
pre_commit_hooks/run_ruff_format/__init__.py,sha256=4QYVE-ktOZjJZGqLMpy4_Te1dASzEkEYVBHzpa1EdGM,2062
|
|
9
|
+
pre_commit_hooks/run_ruff_format/__main__.py,sha256=faesqqpMaesg5r-LvkkQt1W9kahvNr-60K3SMYv1NgY,152
|
|
10
|
+
dycw_pre_commit_hooks-0.11.1.dist-info/METADATA,sha256=c30f9Q_gR8FZBOA3VWdKRcGT_SV5xuvORuLWY6TkhHU,847
|
|
11
|
+
dycw_pre_commit_hooks-0.11.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
12
|
+
dycw_pre_commit_hooks-0.11.1.dist-info/entry_points.txt,sha256=wqBOwmRmDu4artpmdD8KSdWyi_8HqtZiSiopHaXuUi0,204
|
|
13
|
+
dycw_pre_commit_hooks-0.11.1.dist-info/RECORD,,
|
pre_commit_hooks/__init__.py
CHANGED
pre_commit_hooks/common.py
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass
|
|
4
|
-
from hashlib import md5
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
from re import MULTILINE, findall
|
|
7
|
-
from subprocess import check_output
|
|
8
|
-
from typing import Literal
|
|
9
4
|
|
|
10
5
|
from loguru import logger
|
|
11
|
-
from semver import VersionInfo
|
|
12
6
|
from tomlkit import TOMLDocument, parse
|
|
13
7
|
from utilities.git import get_repo_root
|
|
14
|
-
from xdg_base_dirs import xdg_cache_home
|
|
15
8
|
|
|
16
9
|
_ROOT = get_repo_root()
|
|
17
10
|
PYPROJECT_TOML = _ROOT.joinpath("pyproject.toml")
|
|
@@ -20,55 +13,6 @@ PYPROJECT_TOML = _ROOT.joinpath("pyproject.toml")
|
|
|
20
13
|
##
|
|
21
14
|
|
|
22
15
|
|
|
23
|
-
_VERSION_BUMP_SCRIPTS = Literal[
|
|
24
|
-
"run-bump-my-version", "run-bump2version", "run-hatch-version"
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def check_versions(
|
|
29
|
-
path: Path, pattern: str, name: _VERSION_BUMP_SCRIPTS, /
|
|
30
|
-
) -> VersionInfo | None:
|
|
31
|
-
"""Check the versions: current & master.
|
|
32
|
-
|
|
33
|
-
If the current is a correct bumping of master, then return `None`. Else,
|
|
34
|
-
return the patch-bumped master.
|
|
35
|
-
"""
|
|
36
|
-
with path.open() as fh:
|
|
37
|
-
current = _parse_version(pattern, fh.read())
|
|
38
|
-
master = _get_master_version(name, path, pattern)
|
|
39
|
-
patched = master.bump_patch()
|
|
40
|
-
if current in {master.bump_major(), master.bump_minor(), patched}:
|
|
41
|
-
return None
|
|
42
|
-
return patched
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def _parse_version(pattern: str, text: str, /) -> VersionInfo:
|
|
46
|
-
"""Parse the version from a block of text."""
|
|
47
|
-
(match,) = findall(pattern, text, flags=MULTILINE)
|
|
48
|
-
return VersionInfo.parse(match)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def _get_master_version(
|
|
52
|
-
name: _VERSION_BUMP_SCRIPTS, path: Path, pattern: str, /
|
|
53
|
-
) -> VersionInfo:
|
|
54
|
-
repo = md5(Path.cwd().as_posix().encode(), usedforsecurity=False).hexdigest()
|
|
55
|
-
commit = check_output(["git", "rev-parse", "origin/master"], text=True).rstrip("\n")
|
|
56
|
-
cache = xdg_cache_home().joinpath("pre-commit-hooks", name, repo, commit)
|
|
57
|
-
try:
|
|
58
|
-
with cache.open() as fh:
|
|
59
|
-
return VersionInfo.parse(fh.read())
|
|
60
|
-
except FileNotFoundError:
|
|
61
|
-
cache.parent.mkdir(parents=True, exist_ok=True)
|
|
62
|
-
text = check_output(["git", "show", f"{commit}:{path}"], text=True)
|
|
63
|
-
version = _parse_version(pattern, text)
|
|
64
|
-
with cache.open(mode="w") as fh:
|
|
65
|
-
_ = fh.write(str(version))
|
|
66
|
-
return version
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
##
|
|
70
|
-
|
|
71
|
-
|
|
72
16
|
@dataclass(kw_only=True)
|
|
73
17
|
class PyProject:
|
|
74
18
|
contents: str
|
|
@@ -86,11 +30,4 @@ def read_pyproject() -> PyProject:
|
|
|
86
30
|
return PyProject(contents=contents, doc=doc)
|
|
87
31
|
|
|
88
32
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def trim_trailing_whitespaces(path: Path, /) -> None:
|
|
93
|
-
with path.open() as fh:
|
|
94
|
-
lines = fh.readlines()
|
|
95
|
-
with path.open(mode="w") as fh:
|
|
96
|
-
fh.writelines([line.rstrip(" ") for line in lines])
|
|
33
|
+
__all__ = ["PYPROJECT_TOML", "read_pyproject"]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, override
|
|
4
|
+
|
|
5
|
+
from click import argument, command
|
|
6
|
+
from libcst import CSTTransformer, Name, Subscript, parse_module
|
|
7
|
+
from libcst.matchers import Index as MIndex
|
|
8
|
+
from libcst.matchers import Name as MName
|
|
9
|
+
from libcst.matchers import Subscript as MSubscript
|
|
10
|
+
from libcst.matchers import SubscriptElement as MSubscriptElement
|
|
11
|
+
from libcst.matchers import matches
|
|
12
|
+
from libcst.metadata import MetadataWrapper
|
|
13
|
+
from utilities.click import FilePath
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@command()
|
|
20
|
+
@argument("paths", nargs=-1, type=FilePath)
|
|
21
|
+
def main(*, paths: tuple[Path, ...]) -> bool:
|
|
22
|
+
"""CLI for the `replace_sequence_str` hook."""
|
|
23
|
+
results = list(map(_process, paths))
|
|
24
|
+
return all(results)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _process(path: Path, /) -> bool:
|
|
28
|
+
existing = path.read_text()
|
|
29
|
+
wrapper = MetadataWrapper(parse_module(existing))
|
|
30
|
+
transformed = wrapper.module.visit(SequenceToListTransformer())
|
|
31
|
+
new = transformed.code
|
|
32
|
+
if existing == new:
|
|
33
|
+
return True
|
|
34
|
+
_ = path.write_text(new)
|
|
35
|
+
return False
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class SequenceToListTransformer(CSTTransformer):
|
|
39
|
+
@override
|
|
40
|
+
def leave_Subscript(
|
|
41
|
+
self, original_node: Subscript, updated_node: Subscript
|
|
42
|
+
) -> Subscript:
|
|
43
|
+
_ = original_node
|
|
44
|
+
if matches(
|
|
45
|
+
updated_node,
|
|
46
|
+
MSubscript(
|
|
47
|
+
value=MName("Sequence"),
|
|
48
|
+
slice=[MSubscriptElement(slice=MIndex(value=MName("str")))],
|
|
49
|
+
),
|
|
50
|
+
):
|
|
51
|
+
return updated_node.with_changes(value=Name("list"))
|
|
52
|
+
return updated_node
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
__all__ = ["main"]
|
|
@@ -26,7 +26,13 @@ def _process() -> bool:
|
|
|
26
26
|
master = _parse_version_from_file_or_text(contents)
|
|
27
27
|
if current in {master.bump_patch(), master.bump_minor(), master.bump_major()}:
|
|
28
28
|
return True
|
|
29
|
-
cmd = [
|
|
29
|
+
cmd = [
|
|
30
|
+
"bump-my-version",
|
|
31
|
+
"replace",
|
|
32
|
+
"--new-version",
|
|
33
|
+
str(master.bump_patch()),
|
|
34
|
+
str(path),
|
|
35
|
+
]
|
|
30
36
|
try:
|
|
31
37
|
_ = check_call(cmd, stdout=PIPE, stderr=STDOUT)
|
|
32
38
|
except CalledProcessError as error:
|
|
@@ -53,3 +59,6 @@ def _parse_version_from_file_or_text(path_or_text: Path | str, /) -> Version:
|
|
|
53
59
|
case str() as text:
|
|
54
60
|
(match,) = _PATTERN.findall(text)
|
|
55
61
|
return parse_version(match)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
__all__ = ["main"]
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
pre_commit_hooks/__init__.py,sha256=A2CO8YXbK_4wM9T4MjB9ER7186mt_3IDyyFvBxYjBc4,60
|
|
2
|
-
pre_commit_hooks/common.py,sha256=v2pUvEMLMfAXg2nNJOH9LYHbFWkdOssLFwnDXsIEkqk,2703
|
|
3
|
-
pre_commit_hooks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
pre_commit_hooks/run_bump2version/__init__.py,sha256=1Qgt7njFfTlH39ZY4TucZREUJgqtGMe37U5mLkFmupc,1433
|
|
5
|
-
pre_commit_hooks/run_bump2version/__main__.py,sha256=BZy8mDElAK3-X2iKvqg1XnGbCiYXcLoMDefaPanWx4g,153
|
|
6
|
-
pre_commit_hooks/run_bump_my_version/__init__.py,sha256=cl6KTxPaKPmHuebddgfs_OqPK_oYI3R15AbLo8kcFRY,1837
|
|
7
|
-
pre_commit_hooks/run_bump_my_version/__main__.py,sha256=w2V3y61jrSau-zxjl8ciHtWPlJQwXbYxNJ2tGYVyI4s,156
|
|
8
|
-
pre_commit_hooks/run_ruff_format/__init__.py,sha256=4qLSMmPwS50Uqo3FW9joYXaiQ5uKwlvjmk4Vzu6PLrI,2041
|
|
9
|
-
pre_commit_hooks/run_ruff_format/__main__.py,sha256=faesqqpMaesg5r-LvkkQt1W9kahvNr-60K3SMYv1NgY,152
|
|
10
|
-
dycw_pre_commit_hooks-0.10.24.dist-info/METADATA,sha256=orT7e-hcorSV7yk0rxVT6BXcxfYRF1pOZwe3BiBS_5g,852
|
|
11
|
-
dycw_pre_commit_hooks-0.10.24.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
12
|
-
dycw_pre_commit_hooks-0.10.24.dist-info/entry_points.txt,sha256=URODtkWLHrg6PagXnVbubNWnEUjExjCM_lCPf2LEllo,196
|
|
13
|
-
dycw_pre_commit_hooks-0.10.24.dist-info/RECORD,,
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from subprocess import PIPE, STDOUT, CalledProcessError, check_call
|
|
5
|
-
from typing import Literal
|
|
6
|
-
|
|
7
|
-
from click import command, option
|
|
8
|
-
from loguru import logger
|
|
9
|
-
|
|
10
|
-
from pre_commit_hooks.common import (
|
|
11
|
-
PYPROJECT_TOML,
|
|
12
|
-
check_versions,
|
|
13
|
-
trim_trailing_whitespaces,
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@command()
|
|
18
|
-
@option(
|
|
19
|
-
"--setup-cfg", is_flag=True, help="Read `setup.cfg` instead of `bumpversion.cfg`"
|
|
20
|
-
)
|
|
21
|
-
def main(*, setup_cfg: bool) -> bool:
|
|
22
|
-
"""CLI for the `run_bump2version` hook."""
|
|
23
|
-
filename = "setup.cfg" if setup_cfg else ".bumpversion.cfg"
|
|
24
|
-
return _process(filename=filename)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def _process(*, filename: Literal["setup.cfg", ".bumpversion.cfg"]) -> bool:
|
|
28
|
-
path = Path(filename)
|
|
29
|
-
pattern = r"current_version = (\d+\.\d+\.\d+)$"
|
|
30
|
-
version = check_versions(PYPROJECT_TOML, pattern, "run-bump2version")
|
|
31
|
-
if version is None:
|
|
32
|
-
return True
|
|
33
|
-
cmd = ["bump2version", "--allow-dirty", f"--new-version={version}", "patch"]
|
|
34
|
-
try:
|
|
35
|
-
_ = check_call(cmd, stdout=PIPE, stderr=STDOUT)
|
|
36
|
-
except CalledProcessError as error:
|
|
37
|
-
if error.returncode != 1:
|
|
38
|
-
logger.exception("Failed to run {cmd!r}", cmd=" ".join(cmd))
|
|
39
|
-
except FileNotFoundError:
|
|
40
|
-
logger.exception(
|
|
41
|
-
"Failed to run {cmd!r}. Is `bump2version` installed?", cmd=" ".join(cmd)
|
|
42
|
-
)
|
|
43
|
-
else:
|
|
44
|
-
trim_trailing_whitespaces(path)
|
|
45
|
-
return True
|
|
46
|
-
return False
|
|
File without changes
|