dycw-pre-commit-hooks 0.12.6__py3-none-any.whl → 0.12.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-pre-commit-hooks
3
- Version: 0.12.6
3
+ Version: 0.12.8
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  Requires-Python: >=3.12
6
6
  Requires-Dist: click<8.3,>=8.2.1
@@ -1,11 +1,11 @@
1
- pre_commit_hooks/__init__.py,sha256=f7j9CKh6qa4dv2HE4qSzoAuOP22bVouHzH7TeyszKBQ,59
1
+ pre_commit_hooks/__init__.py,sha256=YLG1ztMLECr37VVZERdQ_nviI-TnuwzwSfl9cBayIv8,59
2
2
  pre_commit_hooks/common.py,sha256=Ovg0kK5CBSBEalGdVxLKjvRX3gbjpzTFRNRopB8tEiw,4247
3
3
  pre_commit_hooks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  pre_commit_hooks/check_submodules/__init__.py,sha256=8aJ6sbDclOML5uahK4TNf80Sxf6gCx1kIOYwkv37g9s,1092
5
5
  pre_commit_hooks/check_submodules/__main__.py,sha256=foSVebwCfSkKcAc3cD5YTzkmrWd7Wso9_mR9-zuyG-o,153
6
6
  pre_commit_hooks/format_requirements/__init__.py,sha256=dORQ5sNZaOWYY6cw0X1YIic4OHZeTt9EhI21D1uQFyE,3322
7
7
  pre_commit_hooks/format_requirements/__main__.py,sha256=15JSp_rhjI_Ddoj4MRkHFShfnYxs6GggUhLRlGtrQ0E,156
8
- pre_commit_hooks/mirror_files/__init__.py,sha256=aKS3D72os4lTku8t2nxjlMm_ZiOrTj3034f1CuenlVQ,984
8
+ pre_commit_hooks/mirror_files/__init__.py,sha256=XUmUYHz4otEF5wIK8X0ntH0vkYFBmJwJfXkI8Bz3n0I,1682
9
9
  pre_commit_hooks/mirror_files/__main__.py,sha256=YzOSNKR2XrVST5dgIVJrpRL28QkcziciOomuKtVX7Jo,149
10
10
  pre_commit_hooks/replace_sequence_str/__init__.py,sha256=nDjiKV14th2uWbnte1rSvXckysl7ooaLgWo6IP4HI2s,1618
11
11
  pre_commit_hooks/replace_sequence_str/__main__.py,sha256=B1dxOxngV4vUVnDVrXSywiySOs1P_zF30_4ZMRsOSaY,157
@@ -13,7 +13,7 @@ pre_commit_hooks/run_bump_my_version/__init__.py,sha256=OsMY0boz3VTqAtgLCHtC8AvC
13
13
  pre_commit_hooks/run_bump_my_version/__main__.py,sha256=w2V3y61jrSau-zxjl8ciHtWPlJQwXbYxNJ2tGYVyI4s,156
14
14
  pre_commit_hooks/tag_commits/__init__.py,sha256=097p0gfZcykpOPUgGYsrLePe8Nar04eKlCMn_mqPepg,2945
15
15
  pre_commit_hooks/tag_commits/__main__.py,sha256=qefgYw7LWbvmzZS45-ym6olS4cHqw1Emw2wlqZBXN_o,148
16
- dycw_pre_commit_hooks-0.12.6.dist-info/METADATA,sha256=UXnXIc5VwoA-M2qwRarK9-SGTs_ldwm6nrhUwVN4E0k,1105
17
- dycw_pre_commit_hooks-0.12.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
18
- dycw_pre_commit_hooks-0.12.6.dist-info/entry_points.txt,sha256=0xGzim6HTjeOXJpusYjBk0aEYkXQR2IwrmfzM6KT_r0,368
19
- dycw_pre_commit_hooks-0.12.6.dist-info/RECORD,,
16
+ dycw_pre_commit_hooks-0.12.8.dist-info/METADATA,sha256=SPMmd6uxKS3rmwv3zR0RGgv44Py_NYMGWom8R7kIlcI,1105
17
+ dycw_pre_commit_hooks-0.12.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
18
+ dycw_pre_commit_hooks-0.12.8.dist-info/entry_points.txt,sha256=0xGzim6HTjeOXJpusYjBk0aEYkXQR2IwrmfzM6KT_r0,368
19
+ dycw_pre_commit_hooks-0.12.8.dist-info/RECORD,,
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.12.6"
3
+ __version__ = "0.12.8"
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING
3
+ from typing import TYPE_CHECKING, Literal
4
4
 
5
5
  import utilities.click
6
6
  from click import argument, command
@@ -8,28 +8,49 @@ from loguru import logger
8
8
  from more_itertools import chunked
9
9
  from utilities.atomicwrites import writer
10
10
 
11
+ from pre_commit_hooks.common import run_every_option, throttled_run
12
+
11
13
  if TYPE_CHECKING:
14
+ from collections.abc import Iterable
12
15
  from pathlib import Path
13
16
 
17
+ from whenever import DateTimeDelta
18
+
14
19
 
15
20
  @command()
16
21
  @argument("paths", nargs=-1, type=utilities.click.Path())
17
- def main(*, paths: tuple[Path, ...]) -> bool:
22
+ @run_every_option
23
+ def main(*, paths: tuple[Path, ...], run_every: DateTimeDelta | None = None) -> bool:
18
24
  """CLI for the `format-requirements` hook."""
25
+ return throttled_run("mirror-files", run_every, _process, paths)
26
+
27
+
28
+ def _process(paths: Iterable[Path], /) -> bool:
29
+ paths = list(paths)
19
30
  if len(paths) % 2 == 1:
20
31
  logger.exception(f"Expected an even number of paths; got {len(paths)}")
21
32
  raise RuntimeError
22
- results = list(map(_process, chunked(paths, 2, strict=True))) # run all
33
+ results = list(map(_process_pair, chunked(paths, 2, strict=True))) # run all
23
34
  return all(results)
24
35
 
25
36
 
26
- def _process(paths: list[Path], /) -> bool:
27
- text_from, text_to = [p.read_text() for p in paths]
28
- if text_from == text_to:
29
- return True
30
- _, path_to = paths
31
- with writer(path_to, overwrite=True) as temp:
32
- _ = temp.write_text(text_from)
37
+ def _process_pair(paths: Iterable[Path], /) -> bool:
38
+ path_from, path_to = paths
39
+ try:
40
+ text_from = path_from.read_text()
41
+ except FileNotFoundError:
42
+ logger.exception(f"Source file {str(path_from)!r} not found")
43
+ raise
44
+ try:
45
+ text_to = path_to.read_text()
46
+ except FileNotFoundError:
47
+ return _write_text(text_from, path_to)
48
+ return True if text_from == text_to else _write_text(text_from, path_to)
49
+
50
+
51
+ def _write_text(text: str, path: Path, /) -> Literal[False]:
52
+ with writer(path, overwrite=True) as temp:
53
+ _ = temp.write_text(text)
33
54
  return False
34
55
 
35
56