dycw-pre-commit-hooks 0.14.26__py3-none-any.whl → 0.14.53__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.
@@ -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, Literal, assert_never, overload
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
35
29
 
36
30
  if TYPE_CHECKING:
37
31
  from collections.abc import Callable, Iterable, Iterator, MutableSet
@@ -46,58 +40,17 @@ if TYPE_CHECKING:
46
40
  )
47
41
 
48
42
 
49
- def add_pre_commit_config_repo(
50
- url: str,
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 add_update_certificates(steps: list[StrDict], /) -> None:
44
+ ensure_contains(
45
+ steps, {"name": "Update CA certificates", "run": "sudo update-ca-certificates"}
46
+ )
47
+
48
+
49
+ ##
50
+
51
+
52
+ def apply[T](func: Callable[[], T], /) -> T:
53
+ return func()
101
54
 
102
55
 
103
56
  ##
@@ -123,12 +76,11 @@ def ensure_contains(container: ArrayLike, /, *objs: Any) -> None:
123
76
 
124
77
 
125
78
  def ensure_contains_partial_dict(
126
- container: list[StrDict], partial: StrDict, /, *, extra: StrDict | None = None
79
+ container: list[StrDict], dict_: StrDict, /
127
80
  ) -> StrDict:
128
81
  try:
129
- return get_partial_dict(container, partial)
82
+ return get_partial_dict(container, dict_)
130
83
  except OneEmptyError:
131
- dict_ = partial | ({} if extra is None else extra)
132
84
  container.append(dict_)
133
85
  return dict_
134
86
 
@@ -357,30 +309,35 @@ class PyProjectDependencies:
357
309
  ##
358
310
 
359
311
 
360
- def get_version_from_git_show(*, path: PathLike = BUMPVERSION_TOML) -> Version3:
361
- text = run("git", "show", f"origin/master:{path}", return_=True)
312
+ def get_version_from_path(*, path: PathLike = BUMPVERSION_TOML) -> Version3:
313
+ text = Path(path).read_text()
362
314
  return _get_version_from_toml_text(text)
363
315
 
364
316
 
365
- def get_version_from_git_tag() -> Version3:
366
- text = run("git", "tag", "--points-at", "origin/master", return_=True)
367
- for line in text.splitlines():
368
- with suppress(Version3Error):
369
- return Version3.parse(line)
370
- msg = "No valid version from 'git tag'"
371
- raise ValueError(msg)
372
-
373
-
374
- def get_version_from_path(*, path: PathLike = BUMPVERSION_TOML) -> Version3:
375
- text = Path(path).read_text()
317
+ def get_version_origin_master(*, path: PathLike = BUMPVERSION_TOML) -> Version3:
318
+ with suppress(CalledProcessError):
319
+ text = run("git", "tag", "--points-at", "origin/master", return_=True)
320
+ for line in text.splitlines():
321
+ with suppress(Version3Error):
322
+ return Version3.parse(line)
323
+ try:
324
+ text = run("git", "show", f"origin/master:{path}", return_=True)
325
+ except CalledProcessError:
326
+ msg = "Unable to get the version of origin/master"
327
+ raise ValueError(msg) from None
376
328
  return _get_version_from_toml_text(text)
377
329
 
378
330
 
379
331
  def _get_version_from_toml_text(text: str, /) -> Version3:
380
- doc = tomlkit.parse(text)
381
- tool = get_table(doc, "tool")
382
- bumpversion = get_table(tool, "bumpversion")
383
- return Version3.parse(str(bumpversion["current_version"]))
332
+ try:
333
+ doc = tomlkit.parse(text)
334
+ tool = get_table(doc, "tool")
335
+ bumpversion = get_table(tool, "bumpversion")
336
+ version = bumpversion["current_version"]
337
+ return Version3.parse(str(version))
338
+ except (ParseError, KeyError, Version3Error):
339
+ msg = f"Unable to get the version from {text!r}"
340
+ raise ValueError(msg) from None
384
341
 
385
342
 
386
343
  ##
@@ -397,34 +354,21 @@ def path_throttle_cache(name: str, /) -> Path:
397
354
  def run_all_maybe_raise(*funcs: Callable[[], bool]) -> None:
398
355
  """Run all of a set of jobs."""
399
356
 
400
- results = concurrent_map(_apply, funcs, parallelism="threads")
357
+ results = concurrent_map(apply, funcs, parallelism="threads")
401
358
  if not all(results):
402
359
  raise SystemExit(1)
403
360
 
404
361
 
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
362
  ##
419
363
 
420
364
 
421
365
  def run_prettier(path: PathLike, /) -> None:
422
- with suppress(CalledProcessError):
366
+ with suppress(CalledProcessError, FileNotFoundError):
423
367
  run("prettier", "-w", str(path))
424
368
 
425
369
 
426
370
  def run_taplo(path: PathLike, /) -> None:
427
- with suppress(CalledProcessError):
371
+ with suppress(CalledProcessError, FileNotFoundError):
428
372
  run(
429
373
  "taplo",
430
374
  "format",
@@ -441,6 +385,13 @@ def run_taplo(path: PathLike, /) -> None:
441
385
  ##
442
386
 
443
387
 
388
+ def set_version(version: Version3, /, *, path: PathLike = BUMPVERSION_TOML) -> None:
389
+ run("bump-my-version", "replace", "--new-version", str(version), str(path))
390
+
391
+
392
+ ##
393
+
394
+
444
395
  def write_text(
445
396
  path: PathLike, text: str, /, *, modifications: MutableSet[Path] | None = None
446
397
  ) -> None:
@@ -512,18 +463,6 @@ def yield_json_dict(
512
463
  path, json.loads, dict, json.dumps, modifications=modifications
513
464
  ) as dict_:
514
465
  yield dict_
515
- run_prettier(path)
516
-
517
-
518
- ##
519
-
520
-
521
- @contextmanager
522
- def yield_pyproject_toml(
523
- *, modifications: MutableSet[Path] | None = None
524
- ) -> Iterator[TOMLDocument]:
525
- with yield_toml_doc(PYPROJECT_TOML, modifications=modifications) as doc:
526
- yield doc
527
466
 
528
467
 
529
468
  ##
@@ -616,7 +555,8 @@ def yield_yaml_dict(
616
555
 
617
556
  __all__ = [
618
557
  "PyProjectDependencies",
619
- "add_pre_commit_config_repo",
558
+ "add_update_certificates",
559
+ "apply",
620
560
  "are_equal_modulo_new_line",
621
561
  "ensure_contains",
622
562
  "ensure_contains_partial_dict",
@@ -638,19 +578,17 @@ __all__ = [
638
578
  "get_set_list_strs",
639
579
  "get_set_table",
640
580
  "get_table",
641
- "get_version_from_git_show",
642
- "get_version_from_git_tag",
643
581
  "get_version_from_path",
582
+ "get_version_origin_master",
644
583
  "path_throttle_cache",
645
584
  "run_all_maybe_raise",
646
- "run_bump_my_version",
647
585
  "run_prettier",
648
586
  "run_taplo",
587
+ "set_version",
649
588
  "write_text",
650
589
  "yield_immutable_write_context",
651
590
  "yield_json_dict",
652
591
  "yield_mutable_write_context",
653
- "yield_pyproject_toml",
654
592
  "yield_python_file",
655
593
  "yield_text_file",
656
594
  "yield_toml_doc",
@@ -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,,