dycw-pre-commit-hooks 0.10.22__tar.gz → 0.11.0__tar.gz
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.10.22 → dycw_pre_commit_hooks-0.11.0}/PKG-INFO +3 -5
- {dycw_pre_commit_hooks-0.10.22 → dycw_pre_commit_hooks-0.11.0}/pyproject.toml +6 -6
- {dycw_pre_commit_hooks-0.10.22 → dycw_pre_commit_hooks-0.11.0}/src/pre_commit_hooks/__init__.py +1 -1
- dycw_pre_commit_hooks-0.11.0/src/pre_commit_hooks/common.py +33 -0
- {dycw_pre_commit_hooks-0.10.22 → dycw_pre_commit_hooks-0.11.0}/src/pre_commit_hooks/run_bump_my_version/__init__.py +10 -1
- {dycw_pre_commit_hooks-0.10.22 → dycw_pre_commit_hooks-0.11.0}/src/pre_commit_hooks/run_ruff_format/__init__.py +12 -7
- dycw_pre_commit_hooks-0.10.22/src/pre_commit_hooks/common.py +0 -96
- dycw_pre_commit_hooks-0.10.22/src/pre_commit_hooks/run_bump2version/__init__.py +0 -46
- dycw_pre_commit_hooks-0.10.22/src/pre_commit_hooks/run_bump2version/__main__.py +0 -6
- {dycw_pre_commit_hooks-0.10.22 → dycw_pre_commit_hooks-0.11.0}/.gitignore +0 -0
- {dycw_pre_commit_hooks-0.10.22 → dycw_pre_commit_hooks-0.11.0}/README.md +0 -0
- {dycw_pre_commit_hooks-0.10.22 → dycw_pre_commit_hooks-0.11.0}/src/pre_commit_hooks/py.typed +0 -0
- {dycw_pre_commit_hooks-0.10.22 → dycw_pre_commit_hooks-0.11.0}/src/pre_commit_hooks/run_bump_my_version/__main__.py +0 -0
- {dycw_pre_commit_hooks-0.10.22 → dycw_pre_commit_hooks-0.11.0}/src/pre_commit_hooks/run_ruff_format/__main__.py +0 -0
- {dycw_pre_commit_hooks-0.10.22 → dycw_pre_commit_hooks-0.11.0}/src/tests/__init__.py +0 -0
- {dycw_pre_commit_hooks-0.10.22 → dycw_pre_commit_hooks-0.11.0}/src/tests/test_main.py +0 -0
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dycw-pre-commit-hooks
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0
|
|
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
8
|
Requires-Dist: loguru<0.8,>=0.7.3
|
|
9
|
-
Requires-Dist: semver<3.1,>=3.0.4
|
|
10
9
|
Requires-Dist: tomlkit<0.14,>=0.13.2
|
|
11
|
-
Requires-Dist: xdg-base-dirs<6.1,>=6.0.2
|
|
12
10
|
Description-Content-Type: text/markdown
|
|
13
11
|
|
|
14
12
|
# pre-commit-hooks
|
|
@@ -9,23 +9,22 @@ requires = ["hatchling"]
|
|
|
9
9
|
[dependency-groups]
|
|
10
10
|
dev = [
|
|
11
11
|
"dycw-utilities[test]",
|
|
12
|
+
"pyright[nodejs]>=1.1.401",
|
|
12
13
|
]
|
|
13
14
|
|
|
14
15
|
# project
|
|
15
16
|
[project]
|
|
16
17
|
authors = [{name = "Derek Wan", email = "d.wan@icloud.com"}]
|
|
17
18
|
dependencies = [
|
|
18
|
-
"click >= 8.1
|
|
19
|
-
"dycw-utilities >= 0.
|
|
19
|
+
"click >= 8.2.1, < 8.3",
|
|
20
|
+
"dycw-utilities >= 0.125.10, < 0.126",
|
|
20
21
|
"loguru >= 0.7.3, < 0.8",
|
|
21
|
-
"semver >= 3.0.4, < 3.1",
|
|
22
22
|
"tomlkit >= 0.13.2, < 0.14",
|
|
23
|
-
"xdg-base-dirs >= 6.0.2, < 6.1",
|
|
24
23
|
]
|
|
25
24
|
name = "dycw-pre-commit-hooks"
|
|
26
25
|
readme = "README.md"
|
|
27
26
|
requires-python = ">= 3.12"
|
|
28
|
-
version = "0.
|
|
27
|
+
version = "0.11.0"
|
|
29
28
|
|
|
30
29
|
[project.scripts]
|
|
31
30
|
run-bump-my-version = "pre_commit_hooks.run_bump_my_version:main"
|
|
@@ -35,7 +34,7 @@ run-ruff-format = "pre_commit_hooks.run_ruff_format:main"
|
|
|
35
34
|
# bump-my-version
|
|
36
35
|
[tool.bumpversion]
|
|
37
36
|
allow_dirty = true
|
|
38
|
-
current_version = "0.
|
|
37
|
+
current_version = "0.11.0"
|
|
39
38
|
|
|
40
39
|
[[tool.bumpversion.files]]
|
|
41
40
|
filename = "src/pre_commit_hooks/__init__.py"
|
|
@@ -79,6 +78,7 @@ style = [
|
|
|
79
78
|
[tool.pyright]
|
|
80
79
|
deprecateTypingAliases = true
|
|
81
80
|
enableReachabilityAnalysis = false
|
|
81
|
+
ignore = ["**/_typeshed/**"]
|
|
82
82
|
pythonVersion = "3.12"
|
|
83
83
|
reportAny = false
|
|
84
84
|
reportCallInDefaultInitializer = true
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
from loguru import logger
|
|
6
|
+
from tomlkit import TOMLDocument, parse
|
|
7
|
+
from utilities.git import get_repo_root
|
|
8
|
+
|
|
9
|
+
_ROOT = get_repo_root()
|
|
10
|
+
PYPROJECT_TOML = _ROOT.joinpath("pyproject.toml")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(kw_only=True)
|
|
17
|
+
class PyProject:
|
|
18
|
+
contents: str
|
|
19
|
+
doc: TOMLDocument
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def read_pyproject() -> PyProject:
|
|
23
|
+
try:
|
|
24
|
+
with PYPROJECT_TOML.open(mode="r") as fh:
|
|
25
|
+
contents = fh.read()
|
|
26
|
+
except FileNotFoundError:
|
|
27
|
+
logger.exception("pyproject.toml not found")
|
|
28
|
+
raise
|
|
29
|
+
doc = parse(contents)
|
|
30
|
+
return PyProject(contents=contents, doc=doc)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
__all__ = ["PYPROJECT_TOML", "read_pyproject"]
|
|
@@ -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,15 +1,17 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from subprocess import CalledProcessError, check_call
|
|
4
|
-
from typing import cast
|
|
4
|
+
from typing import TYPE_CHECKING, cast
|
|
5
5
|
|
|
6
6
|
from click import command
|
|
7
7
|
from loguru import logger
|
|
8
8
|
from tomlkit import dumps, table
|
|
9
|
-
from tomlkit.container import Container
|
|
10
9
|
|
|
11
10
|
from pre_commit_hooks.common import PYPROJECT_TOML, PyProject, read_pyproject
|
|
12
11
|
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from tomlkit.container import Container
|
|
14
|
+
|
|
13
15
|
|
|
14
16
|
@command()
|
|
15
17
|
def main() -> bool:
|
|
@@ -30,25 +32,25 @@ def _get_modified_pyproject() -> PyProject:
|
|
|
30
32
|
pyproject = read_pyproject()
|
|
31
33
|
doc = pyproject.doc
|
|
32
34
|
try:
|
|
33
|
-
tool = cast(Container, doc["tool"])
|
|
35
|
+
tool = cast("Container", doc["tool"])
|
|
34
36
|
except KeyError:
|
|
35
37
|
tool = table()
|
|
36
38
|
try:
|
|
37
|
-
ruff = cast(Container, tool["ruff"])
|
|
39
|
+
ruff = cast("Container", tool["ruff"])
|
|
38
40
|
except KeyError:
|
|
39
41
|
ruff = table()
|
|
40
42
|
ruff["line-length"] = 320
|
|
41
43
|
try:
|
|
42
|
-
format_ = cast(Container, ruff["format"])
|
|
44
|
+
format_ = cast("Container", ruff["format"])
|
|
43
45
|
except KeyError:
|
|
44
46
|
format_ = table()
|
|
45
47
|
format_["skip-magic-trailing-comma"] = True
|
|
46
48
|
try:
|
|
47
|
-
lint = cast(Container, ruff["lint"])
|
|
49
|
+
lint = cast("Container", ruff["lint"])
|
|
48
50
|
except KeyError:
|
|
49
51
|
lint = table()
|
|
50
52
|
try:
|
|
51
|
-
isort = cast(Container, lint["isort"])
|
|
53
|
+
isort = cast("Container", lint["isort"])
|
|
52
54
|
except KeyError:
|
|
53
55
|
isort = table()
|
|
54
56
|
isort["split-on-trailing-comma"] = False
|
|
@@ -74,3 +76,6 @@ def _run_ruff_format(pyproject: PyProject, /) -> bool:
|
|
|
74
76
|
def _write_pyproject(pyproject: PyProject, /) -> None:
|
|
75
77
|
with PYPROJECT_TOML.open(mode="w") as fh:
|
|
76
78
|
_ = fh.write(pyproject.contents)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
__all__ = ["main"]
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
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
|
-
|
|
10
|
-
from loguru import logger
|
|
11
|
-
from semver import VersionInfo
|
|
12
|
-
from tomlkit import TOMLDocument, parse
|
|
13
|
-
from utilities.git import get_repo_root
|
|
14
|
-
from xdg_base_dirs import xdg_cache_home
|
|
15
|
-
|
|
16
|
-
_ROOT = get_repo_root()
|
|
17
|
-
PYPROJECT_TOML = _ROOT.joinpath("pyproject.toml")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
##
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
@dataclass(kw_only=True)
|
|
73
|
-
class PyProject:
|
|
74
|
-
contents: str
|
|
75
|
-
doc: TOMLDocument
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def read_pyproject() -> PyProject:
|
|
79
|
-
try:
|
|
80
|
-
with PYPROJECT_TOML.open(mode="r") as fh:
|
|
81
|
-
contents = fh.read()
|
|
82
|
-
except FileNotFoundError:
|
|
83
|
-
logger.exception("pyproject.toml not found")
|
|
84
|
-
raise
|
|
85
|
-
doc = parse(contents)
|
|
86
|
-
return PyProject(contents=contents, doc=doc)
|
|
87
|
-
|
|
88
|
-
|
|
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])
|
|
@@ -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
|
|
File without changes
|
{dycw_pre_commit_hooks-0.10.22 → dycw_pre_commit_hooks-0.11.0}/src/pre_commit_hooks/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|