dycw-pre-commit-hooks 0.9.24__py3-none-any.whl → 0.10.4__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.

@@ -1,18 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-pre-commit-hooks
3
- Version: 0.9.24
3
+ Version: 0.10.4
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: click<8.2,>=8.1.8
7
- Requires-Dist: dycw-utilities<0.93,>=0.92.10
7
+ Requires-Dist: dycw-utilities<0.96,>=0.95.21
8
8
  Requires-Dist: loguru<0.8,>=0.7.3
9
9
  Requires-Dist: semver<3.1,>=3.0.4
10
10
  Requires-Dist: tomlkit<0.14,>=0.13.2
11
11
  Requires-Dist: xdg-base-dirs<6.1,>=6.0.2
12
- Provides-Extra: dev
13
- Requires-Dist: dycw-utilities[test]; extra == 'dev'
14
- Requires-Dist: hatch<1.15,>=1.14.0; extra == 'dev'
15
- Requires-Dist: setuptools<75.9,>=75.8.0; extra == 'dev'
16
12
  Description-Content-Type: text/markdown
17
13
 
18
14
  # pre-commit-hooks
@@ -0,0 +1,4 @@
1
+ dycw_pre_commit_hooks-0.10.4.dist-info/METADATA,sha256=i6XLf47H_8gLTX2f3CE5b8-D2SJFldJRb2_U4vl2XHo,1012
2
+ dycw_pre_commit_hooks-0.10.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
3
+ dycw_pre_commit_hooks-0.10.4.dist-info/entry_points.txt,sha256=MxQ24qIL7DfnorSw_zyRpivSVT1uZMELf-0GUjVHau4,366
4
+ dycw_pre_commit_hooks-0.10.4.dist-info/RECORD,,
@@ -1,4 +1,5 @@
1
1
  [console_scripts]
2
+ run-bump-my-version = pre_commit_hooks.run_bump-my-version:main
2
3
  run-bump2version = pre_commit_hooks.run_bump2version:main
3
4
  run-dockfmt = pre_commit_hooks.run_dockfmt:main
4
5
  run-hatch-version = pre_commit_hooks.run_hatch_version:main
@@ -1,17 +0,0 @@
1
- pre_commit_hooks/__init__.py,sha256=8htHZiLvonAgGUCn5pG6fCqd7Rbi5TnNa8BoWJQcVKU,59
2
- pre_commit_hooks/common.py,sha256=H8RJkUXKQ7vHbCsi6oDq7XAdggjOij5R1xGoQ1UXhKA,2512
3
- pre_commit_hooks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- pre_commit_hooks/run_bump2version/__init__.py,sha256=nhJ2kdUjSteGVjatTfMSeQb92zIlfiwyeHll_7_nzvM,1581
5
- pre_commit_hooks/run_bump2version/__main__.py,sha256=BZy8mDElAK3-X2iKvqg1XnGbCiYXcLoMDefaPanWx4g,153
6
- pre_commit_hooks/run_dockfmt/__init__.py,sha256=REJG8A77H1VbPvIhStlsIWEqqYeaK4h7q17kbLTK3TE,1070
7
- pre_commit_hooks/run_dockfmt/__main__.py,sha256=aE0DIrzWy4mnQ04_n5U6znbmJwJBkjZUXv9Th3OqQ7Y,148
8
- pre_commit_hooks/run_hatch_version/__init__.py,sha256=bADWwm3tTgUrDMynBag2Z_hVknlbfOsoYl7ghxTc_hY,1714
9
- pre_commit_hooks/run_hatch_version/__main__.py,sha256=XeMLmgm1HMujkYhaF9LcMygBrwa2KqIGMzznY106gd8,154
10
- pre_commit_hooks/run_ruff_format/__init__.py,sha256=Lr_9M0WHhJl6WARAf8Lr830PG9bMbkDXvNSmEkrSxK8,1993
11
- pre_commit_hooks/run_ruff_format/__main__.py,sha256=faesqqpMaesg5r-LvkkQt1W9kahvNr-60K3SMYv1NgY,152
12
- pre_commit_hooks/run_uv_pip_compile/__init__.py,sha256=HJHsMgOuxAtWQKzK-J-MGRFtuvr9eHfopfgaW1I_uGo,2368
13
- pre_commit_hooks/run_uv_pip_compile/__main__.py,sha256=LLlM3xVN7l5cxZ0yD_8He8n_GEmQqn_d-2wl6BQtqoA,155
14
- dycw_pre_commit_hooks-0.9.24.dist-info/METADATA,sha256=IpZTg06Rjm0YBXXJ2q3j1KpxlW_QPAarkUOJa9q2khQ,1191
15
- dycw_pre_commit_hooks-0.9.24.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
- dycw_pre_commit_hooks-0.9.24.dist-info/entry_points.txt,sha256=E5ZGYo3x6IF71IHDEhXJYfTHRRIrjzzuxsiYgVkCDQE,302
17
- dycw_pre_commit_hooks-0.9.24.dist-info/RECORD,,
@@ -1,3 +0,0 @@
1
- from __future__ import annotations
2
-
3
- __version__ = "0.9.24"
@@ -1,84 +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
- REQUIREMENTS_TXT = _ROOT.joinpath("requirements.txt")
19
-
20
-
21
- def check_versions(
22
- path: Path,
23
- pattern: str,
24
- /,
25
- *,
26
- name: Literal["run-bump2version", "run-hatch-version"],
27
- ) -> VersionInfo | None:
28
- """Check the versions: current & master.
29
-
30
- If the current is a correct bumping of master, then return `None`. Else,
31
- return the patch-bumped master.
32
- """
33
- with path.open() as fh:
34
- current = _parse_version(pattern, fh.read())
35
- master = _get_master_version(path, pattern, name=name)
36
- patched = master.bump_patch()
37
- if current in {master.bump_major(), master.bump_minor(), patched}:
38
- return None
39
- return patched
40
-
41
-
42
- def _parse_version(pattern: str, text: str, /) -> VersionInfo:
43
- """Parse the version from a block of text."""
44
- (match,) = findall(pattern, text, flags=MULTILINE)
45
- return VersionInfo.parse(match)
46
-
47
-
48
- def _get_master_version(
49
- path: Path,
50
- pattern: str,
51
- /,
52
- *,
53
- name: Literal["run-bump2version", "run-hatch-version"],
54
- ) -> VersionInfo:
55
- repo = md5(Path.cwd().as_posix().encode(), usedforsecurity=False).hexdigest()
56
- commit = check_output(["git", "rev-parse", "origin/master"], text=True).rstrip("\n")
57
- cache = xdg_cache_home().joinpath("pre-commit-hooks", name, repo, commit)
58
- try:
59
- with cache.open() as fh:
60
- return VersionInfo.parse(fh.read())
61
- except FileNotFoundError:
62
- cache.parent.mkdir(parents=True, exist_ok=True)
63
- text = check_output(["git", "show", f"{commit}:{path}"], text=True)
64
- version = _parse_version(pattern, text)
65
- with cache.open(mode="w") as fh:
66
- _ = fh.write(str(version))
67
- return version
68
-
69
-
70
- @dataclass
71
- class PyProject:
72
- contents: str
73
- doc: TOMLDocument
74
-
75
-
76
- def read_pyproject() -> PyProject:
77
- try:
78
- with PYPROJECT_TOML.open(mode="r") as fh:
79
- contents = fh.read()
80
- except FileNotFoundError:
81
- logger.exception("pyproject.toml not found")
82
- raise
83
- doc = parse(contents)
84
- return PyProject(contents=contents, doc=doc)
pre_commit_hooks/py.typed DELETED
File without changes
@@ -1,49 +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 check_versions
11
-
12
-
13
- @command()
14
- @option(
15
- "--setup-cfg", is_flag=True, help="Read `setup.cfg` instead of `bumpversion.cfg`"
16
- )
17
- def main(*, setup_cfg: bool) -> bool:
18
- """CLI for the `run_bump2version` hook."""
19
- filename = "setup.cfg" if setup_cfg else ".bumpversion.cfg"
20
- return _process(filename=filename)
21
-
22
-
23
- def _process(*, filename: Literal["setup.cfg", ".bumpversion.cfg"]) -> bool:
24
- path = Path(filename)
25
- pattern = r"current_version = (\d+\.\d+\.\d+)$"
26
- version = check_versions(path, pattern, name="run-bump2version")
27
- if version is None:
28
- return True
29
- cmd = ["bump2version", "--allow-dirty", f"--new-version={version}", "patch"]
30
- try:
31
- _ = check_call(cmd, stdout=PIPE, stderr=STDOUT)
32
- except CalledProcessError as error:
33
- if error.returncode != 1:
34
- logger.exception("Failed to run {cmd!r}", cmd=" ".join(cmd))
35
- except FileNotFoundError:
36
- logger.exception(
37
- "Failed to run {cmd!r}. Is `bump2version` installed?", cmd=" ".join(cmd)
38
- )
39
- else:
40
- _trim_trailing_whitespaces(path)
41
- return True
42
- return False
43
-
44
-
45
- def _trim_trailing_whitespaces(path: Path, /) -> None:
46
- with path.open() as fh:
47
- lines = fh.readlines()
48
- with path.open(mode="w") as fh:
49
- fh.writelines([line.rstrip(" ") for line in lines])
@@ -1,6 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from pre_commit_hooks.run_bump2version import main
4
-
5
- if __name__ == "__main__":
6
- raise SystemExit(int(not main()))
@@ -1,45 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from pathlib import Path
4
- from subprocess import check_output
5
- from typing import TYPE_CHECKING
6
-
7
- import click
8
- from click import argument, command
9
-
10
- if TYPE_CHECKING:
11
- from collections.abc import Iterator
12
-
13
-
14
- @command()
15
- @argument(
16
- "paths",
17
- nargs=-1,
18
- type=click.Path(
19
- exists=True, file_okay=True, dir_okay=False, readable=True, path_type=Path
20
- ),
21
- )
22
- def main(paths: tuple[Path, ...], /) -> bool:
23
- """CLI for the `run-dockfmt` hook."""
24
- results = list(_yield_outcomes(*paths)) # run all
25
- return all(results)
26
-
27
-
28
- def _yield_outcomes(*paths: Path) -> Iterator[bool]:
29
- for path in paths:
30
- if path.name == "Dockerfile":
31
- yield _process(path)
32
-
33
-
34
- def _process(path: Path, /) -> bool:
35
- with path.open() as fh:
36
- current = fh.read()
37
- strip = "\t\n"
38
- proposed = check_output(["dockfmt", "fmt", path.as_posix()], text=True).lstrip(
39
- strip
40
- )
41
- if current == proposed:
42
- return True
43
- with path.open(mode="w") as fh:
44
- _ = fh.write(proposed)
45
- return False
@@ -1,6 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from pre_commit_hooks.run_dockfmt import main
4
-
5
- if __name__ == "__main__":
6
- raise SystemExit(int(not main()))
@@ -1,58 +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 Any, cast
6
-
7
- from click import command
8
- from loguru import logger
9
- from tomlkit.container import Container
10
-
11
- from pre_commit_hooks.common import check_versions, read_pyproject
12
-
13
-
14
- @command()
15
- def main() -> bool:
16
- """CLI for the `run-hatch-version` hook."""
17
- return _process()
18
-
19
-
20
- def _process() -> bool:
21
- path = _get_path_version_file()
22
- pattern = r'^__version__ = "(\d+\.\d+\.\d+)"$'
23
- version = check_versions(path, pattern, name="run-hatch-version")
24
- if version is None:
25
- return True
26
- cmd = ["hatch", "version", str(version)]
27
- try:
28
- _ = check_call(cmd, stdout=PIPE, stderr=STDOUT)
29
- except CalledProcessError as error:
30
- if error.returncode != 1:
31
- logger.exception("Failed to run {cmd!r}", cmd=" ".join(cmd))
32
- except FileNotFoundError:
33
- logger.exception(
34
- "Failed to run {cmd!r}. Is `hatch` installed?", cmd=" ".join(cmd)
35
- )
36
- else:
37
- return True
38
- return False
39
-
40
-
41
- def _get_path_version_file() -> Path:
42
- pyproject = read_pyproject()
43
- try:
44
- tool = cast(Container, pyproject.doc["tool"])
45
- except KeyError:
46
- logger.exception('pyproject.toml has no "tool" section')
47
- raise
48
- try:
49
- hatch = cast(Container, tool["hatch"])
50
- except KeyError:
51
- logger.exception('pyproject.toml has no "tool.hatch" section')
52
- raise
53
- try:
54
- version = cast(Container, hatch["version"])
55
- except KeyError:
56
- logger.exception('pyproject.toml has no "tool.hatch.version" section')
57
- raise
58
- return Path(cast(Any, version["path"]))
@@ -1,6 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from pre_commit_hooks.run_hatch_version import main
4
-
5
- if __name__ == "__main__":
6
- raise SystemExit(int(not main()))
@@ -1,76 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from subprocess import CalledProcessError, check_call
4
- from typing import cast
5
-
6
- from click import command
7
- from loguru import logger
8
- from tomlkit import dumps, table
9
- from tomlkit.container import Container
10
-
11
- from pre_commit_hooks.common import PYPROJECT_TOML, PyProject, read_pyproject
12
-
13
-
14
- @command()
15
- def main() -> bool:
16
- """CLI for the `run-ruff-format` hook."""
17
- return _process()
18
-
19
-
20
- def _process() -> bool:
21
- curr = read_pyproject()
22
- new = _get_modified_pyproject()
23
- result1 = _run_ruff_format(new)
24
- result2 = _run_ruff_format(curr)
25
- _write_pyproject(curr)
26
- return result1 and result2
27
-
28
-
29
- def _get_modified_pyproject() -> PyProject:
30
- pyproject = read_pyproject()
31
- doc = pyproject.doc
32
- try:
33
- tool = cast(Container, doc["tool"])
34
- except KeyError:
35
- tool = table()
36
- try:
37
- ruff = cast(Container, tool["ruff"])
38
- except KeyError:
39
- ruff = table()
40
- ruff["line-length"] = 320
41
- try:
42
- format_ = cast(Container, ruff["format"])
43
- except KeyError:
44
- format_ = table()
45
- format_["skip-magic-trailing-comma"] = True
46
- try:
47
- lint = cast(Container, ruff["lint"])
48
- except KeyError:
49
- lint = table()
50
- try:
51
- isort = cast(Container, lint["isort"])
52
- except KeyError:
53
- isort = table()
54
- isort["split-on-trailing-comma"] = False
55
- doc["tool"] = tool
56
- tool["ruff"] = ruff
57
- ruff["format"] = format_
58
- ruff["lint"] = lint
59
- lint["isort"] = isort
60
- return PyProject(contents=dumps(doc), doc=doc)
61
-
62
-
63
- def _run_ruff_format(pyproject: PyProject, /) -> bool:
64
- _write_pyproject(pyproject)
65
- cmd = ["ruff", "format", "."]
66
- try:
67
- code = check_call(cmd)
68
- except CalledProcessError:
69
- logger.exception("Failed to run {cmd!r}", cmd=" ".join(cmd))
70
- return False
71
- return code == 0
72
-
73
-
74
- def _write_pyproject(pyproject: PyProject, /) -> None:
75
- with PYPROJECT_TOML.open(mode="w") as fh:
76
- _ = fh.write(pyproject.contents)
@@ -1,6 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from pre_commit_hooks.run_ruff_format import main
4
-
5
- if __name__ == "__main__":
6
- raise SystemExit(int(not main()))
@@ -1,80 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from pathlib import Path
4
- from re import sub
5
- from subprocess import CalledProcessError, check_call
6
- from tempfile import TemporaryDirectory
7
-
8
- from click import command, option
9
- from loguru import logger
10
-
11
- from pre_commit_hooks.common import REQUIREMENTS_TXT
12
-
13
-
14
- @command()
15
- @option(
16
- "--python-version",
17
- help="The minimum Python version that should be supported by the compiled requirements",
18
- )
19
- def main(*, python_version: str | None) -> bool:
20
- """CLI for the `run-uv-pip-compile` hook."""
21
- return _process(python_version=python_version)
22
-
23
-
24
- def _process(*, python_version: str | None) -> bool:
25
- curr = _read_requirements_txt(REQUIREMENTS_TXT)
26
- latest = _run_uv_pip_compile(python_version=python_version)
27
- if curr == latest:
28
- return True
29
- _write_requirements_txt(latest)
30
- return False
31
-
32
-
33
- def _read_requirements_txt(path: Path, /) -> str | None:
34
- try:
35
- with path.open() as fh:
36
- return fh.read()
37
- except FileNotFoundError:
38
- return None
39
-
40
-
41
- def _run_uv_pip_compile(*, python_version: str | None) -> str:
42
- with TemporaryDirectory() as temp:
43
- temp_file = Path(temp, "requirements.txt")
44
- cmd = (
45
- [
46
- "uv",
47
- "pip",
48
- "compile",
49
- "--extra=dev",
50
- "--prerelease=explicit",
51
- "--quiet",
52
- f"--output-file={temp_file.as_posix()}",
53
- "--upgrade",
54
- ]
55
- + ([] if python_version is None else [f"--python-version={python_version}"])
56
- + [
57
- "pyproject.toml" # don't use absolute path
58
- ]
59
- )
60
- try:
61
- _ = check_call(cmd)
62
- except CalledProcessError:
63
- logger.exception("Failed to run {cmd!r}", cmd=" ".join(cmd))
64
- raise
65
- with temp_file.open(mode="r") as fh:
66
- contents = fh.read()
67
- return _fix_header(contents, temp_file) + "\n"
68
-
69
-
70
- def _fix_header(text: str, temp_file: Path, /) -> str:
71
- return "\n".join(_fix_header_line(line, temp_file) for line in text.splitlines())
72
-
73
-
74
- def _fix_header_line(line: str, temp_file: Path, /) -> str:
75
- return sub(str(temp_file), temp_file.name, line)
76
-
77
-
78
- def _write_requirements_txt(contents: str, /) -> None:
79
- with REQUIREMENTS_TXT.open(mode="w") as fh:
80
- _ = fh.write(contents)
@@ -1,6 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from pre_commit_hooks.run_uv_pip_compile import main
4
-
5
- if __name__ == "__main__":
6
- raise SystemExit(int(not main()))