dycw-pre-commit-hooks 0.8.26__py3-none-any.whl → 0.8.29__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,17 +1,17 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dycw-pre-commit-hooks
3
- Version: 0.8.26
3
+ Version: 0.8.29
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
- Requires-Python: >=3.9
6
- Requires-Dist: beartype==0.12.0
7
- Requires-Dist: click==8.1.3
8
- Requires-Dist: gitdb==4.0.10
9
- Requires-Dist: gitpython==3.1.31
10
- Requires-Dist: loguru==0.6.0
11
- Requires-Dist: semver==3.0.0
12
- Requires-Dist: smmap==5.0.0
13
- Requires-Dist: tomlkit==0.11.7
14
- Requires-Dist: xdg==6.0.0
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: dycw-utilities[click,loguru,semver]<0.14,>=0.13.3
7
+ Requires-Dist: semver<3.1,>=3.0.1
8
+ Requires-Dist: tomlkit<0.13,>=0.12.1
9
+ Requires-Dist: xdg<6.1,>=6.0.0
10
+ Provides-Extra: dev
11
+ Requires-Dist: dycw-utilities[test]; extra == 'dev'
12
+ Requires-Dist: hatch; extra == 'dev'
13
+ Requires-Dist: pip-tools; extra == 'dev'
14
+ Requires-Dist: pre-commit; extra == 'dev'
15
15
  Description-Content-Type: text/markdown
16
16
 
17
17
  # pre-commit-hooks
@@ -0,0 +1,15 @@
1
+ pre_commit_hooks/__init__.py,sha256=0N4I4EeGKVWv3NB9CMtGzvVHDPM3T39KqzroHi_QmLY,23
2
+ pre_commit_hooks/common.py,sha256=XyHNRJN_NYzImvfGtFsKxZmQquVMf7YJSdhNpexNt2g,2055
3
+ pre_commit_hooks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ pre_commit_hooks/run_bump2version/__init__.py,sha256=DUYGPCFmpCQ_mEyB-0mMzOrPSRsy-TUiq0-hAQH9vBw,1604
5
+ pre_commit_hooks/run_bump2version/__main__.py,sha256=Iw8jbq91sc_vSHO-oQfLJMBhM5K0u282b37XRSch0E8,117
6
+ pre_commit_hooks/run_dockfmt/__init__.py,sha256=BohlOmwv16IJHAFOXcELwgLikzy-E2joKhTQyHCz368,1045
7
+ pre_commit_hooks/run_dockfmt/__main__.py,sha256=4THoW2NxXW-VQYrtd3ea9hZybF7vDDwGlaLETl7j9SI,112
8
+ pre_commit_hooks/run_hatch_version/__init__.py,sha256=fSZWdmHEHZYI-wPh-I_iMEH7O7VlinyIJRYyd_qryKg,1840
9
+ pre_commit_hooks/run_hatch_version/__main__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ pre_commit_hooks/run_pip_compile/__init__.py,sha256=ZddCidJ7L2Hp1q6ysUabJ9XC5aEx_vB8zYO4YpgIR3M,4926
11
+ pre_commit_hooks/run_pip_compile/__main__.py,sha256=DNITyLZnWcqb_BUHDuTmYU4yY9oENv9Y_WtOyuD0r4Y,89
12
+ dycw_pre_commit_hooks-0.8.29.dist-info/METADATA,sha256=RlarZRRpT79bOLrI5oevweqgIXGyTNcR9wS_Ew9TBy4,1073
13
+ dycw_pre_commit_hooks-0.8.29.dist-info/WHEEL,sha256=9QBuHhg6FNW7lppboF2vKVbCGTVzsFykgRQjjlajrhA,87
14
+ dycw_pre_commit_hooks-0.8.29.dist-info/entry_points.txt,sha256=uOkhrPXXksWQu3uJoCNvlqdTJ4exmQtfx_IkpOJIbeY,240
15
+ dycw_pre_commit_hooks-0.8.29.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.14.0
2
+ Generator: hatchling 1.18.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1 +1 @@
1
- __version__ = "0.8.26"
1
+ __version__ = "0.8.29"
@@ -1,22 +1,24 @@
1
1
  from hashlib import md5
2
2
  from pathlib import Path
3
- from re import MULTILINE, findall
3
+ from re import MULTILINE
4
+ from re import findall
4
5
  from subprocess import check_output
5
- from typing import Literal, Optional
6
+ from typing import Literal
6
7
 
7
- from beartype import beartype
8
8
  from semver import VersionInfo
9
+ from utilities.git import get_repo_root
9
10
  from xdg import xdg_cache_home
10
11
 
12
+ PYPROJECT_TOML = get_repo_root().joinpath("pyproject.toml")
13
+
11
14
 
12
- @beartype
13
15
  def check_versions(
14
16
  path: Path,
15
17
  pattern: str,
16
18
  /,
17
19
  *,
18
20
  name: Literal["run-bump2version", "run-hatch-version"],
19
- ) -> Optional[VersionInfo]:
21
+ ) -> VersionInfo | None:
20
22
  """Check the versions: current & master.
21
23
 
22
24
  If the current is a correct bumping of master, then return `None`. Else,
@@ -31,14 +33,12 @@ def check_versions(
31
33
  return patched
32
34
 
33
35
 
34
- @beartype
35
36
  def _parse_version(pattern: str, text: str, /) -> VersionInfo:
36
37
  """Parse the version from a block of text."""
37
38
  (match,) = findall(pattern, text, flags=MULTILINE)
38
39
  return VersionInfo.parse(match)
39
40
 
40
41
 
41
- @beartype
42
42
  def _get_master_version(
43
43
  path: Path,
44
44
  pattern: str,
@@ -46,15 +46,22 @@ def _get_master_version(
46
46
  *,
47
47
  name: Literal["run-bump2version", "run-hatch-version"],
48
48
  ) -> VersionInfo:
49
- repo = md5(Path.cwd().as_posix().encode(), usedforsecurity=False).hexdigest()
50
- commit = check_output(["git", "rev-parse", "origin/master"], text=True).rstrip("\n")
49
+ repo = md5(
50
+ Path.cwd().as_posix().encode(), usedforsecurity=False
51
+ ).hexdigest()
52
+ commit = check_output(
53
+ ["git", "rev-parse", "origin/master"], text=True # noqa: S603, S607
54
+ ).rstrip("\n")
51
55
  cache = xdg_cache_home().joinpath("pre-commit-hooks", name, repo, commit)
52
56
  try:
53
57
  with cache.open() as fh:
54
58
  return VersionInfo.parse(fh.read())
55
59
  except FileNotFoundError:
56
60
  cache.parent.mkdir(parents=True, exist_ok=True)
57
- text = check_output(["git", "show", f"{commit}:{path.as_posix()}"], text=True)
61
+ text = check_output(
62
+ ["git", "show", f"{commit}:{path.as_posix()}"], # noqa: S603, S607
63
+ text=True,
64
+ )
58
65
  version = _parse_version(pattern, text)
59
66
  with cache.open(mode="w") as fh:
60
67
  _ = fh.write(str(version))
@@ -1,8 +1,11 @@
1
1
  from pathlib import Path
2
- from subprocess import PIPE, STDOUT, CalledProcessError, check_call
2
+ from subprocess import PIPE
3
+ from subprocess import STDOUT
4
+ from subprocess import CalledProcessError
5
+ from subprocess import check_call
3
6
 
4
- from beartype import beartype
5
- from click import command, option
7
+ from click import command
8
+ from click import option
6
9
  from loguru import logger
7
10
 
8
11
  from pre_commit_hooks.common import check_versions
@@ -10,15 +13,15 @@ from pre_commit_hooks.common import check_versions
10
13
 
11
14
  @command()
12
15
  @option(
13
- "--setup-cfg", is_flag=True, help="Read `setup.cfg` instead of `bumpversion.cfg`"
16
+ "--setup-cfg",
17
+ is_flag=True,
18
+ help="Read `setup.cfg` instead of `bumpversion.cfg`",
14
19
  )
15
- @beartype
16
20
  def main(*, setup_cfg: bool) -> bool:
17
21
  """CLI for the `run_bump2version` hook."""
18
22
  return _process(setup_cfg=setup_cfg)
19
23
 
20
24
 
21
- @beartype
22
25
  def _process(*, setup_cfg: bool) -> bool:
23
26
  filename = "setup.cfg" if setup_cfg else ".bumpversion.cfg"
24
27
  path = Path(filename)
@@ -28,13 +31,14 @@ def _process(*, setup_cfg: bool) -> bool:
28
31
  return True
29
32
  cmd = ["bump2version", "--allow-dirty", f"--new-version={version}", "patch"]
30
33
  try:
31
- _ = check_call(cmd, stdout=PIPE, stderr=STDOUT)
34
+ _ = check_call(cmd, stdout=PIPE, stderr=STDOUT) # noqa: S603
32
35
  except CalledProcessError as error:
33
36
  if error.returncode != 1:
34
37
  logger.exception("Failed to run {cmd!r}", cmd=" ".join(cmd))
35
38
  except FileNotFoundError:
36
39
  logger.exception(
37
- "Failed to run {cmd!r}. Is `bump2version` installed?", cmd=" ".join(cmd)
40
+ "Failed to run {cmd!r}. Is `bump2version` installed?",
41
+ cmd=" ".join(cmd),
38
42
  )
39
43
  else:
40
44
  _trim_trailing_whitespaces(path)
@@ -42,7 +46,6 @@ def _process(*, setup_cfg: bool) -> bool:
42
46
  return False
43
47
 
44
48
 
45
- @beartype
46
49
  def _trim_trailing_whitespaces(path: Path, /) -> None:
47
50
  with path.open() as fh:
48
51
  lines = fh.readlines()
@@ -3,8 +3,8 @@ from pathlib import Path
3
3
  from subprocess import check_output
4
4
 
5
5
  import click
6
- from beartype import beartype
7
- from click import argument, command
6
+ from click import argument
7
+ from click import command
8
8
 
9
9
 
10
10
  @command()
@@ -12,31 +12,32 @@ from click import argument, command
12
12
  "paths",
13
13
  nargs=-1,
14
14
  type=click.Path(
15
- exists=True, file_okay=True, dir_okay=False, readable=True, path_type=Path
15
+ exists=True,
16
+ file_okay=True,
17
+ dir_okay=False,
18
+ readable=True,
19
+ path_type=Path,
16
20
  ),
17
21
  )
18
- @beartype
19
22
  def main(paths: tuple[Path, ...]) -> bool:
20
23
  """CLI for the `run-dockfmt` hook."""
21
24
  results = list(_yield_outcomes(*paths)) # run all
22
25
  return all(results)
23
26
 
24
27
 
25
- @beartype
26
28
  def _yield_outcomes(*paths: Path) -> Iterator[bool]:
27
29
  for path in paths:
28
30
  if path.name == "Dockerfile":
29
31
  yield _process(path)
30
32
 
31
33
 
32
- @beartype
33
34
  def _process(path: Path, /) -> bool:
34
35
  with path.open() as fh:
35
36
  current = fh.read()
36
37
  strip = "\t\n"
37
- proposed = check_output(["dockfmt", "fmt", path.as_posix()], text=True).lstrip(
38
- strip
39
- )
38
+ proposed = check_output(
39
+ ["dockfmt", "fmt", path.as_posix()], text=True # noqa: S603, S607
40
+ ).lstrip(strip)
40
41
  if current == proposed:
41
42
  return True
42
43
  with path.open(mode="w") as fh:
@@ -1,25 +1,25 @@
1
1
  from pathlib import Path
2
- from subprocess import PIPE, STDOUT, CalledProcessError, check_call
2
+ from subprocess import PIPE
3
+ from subprocess import STDOUT
4
+ from subprocess import CalledProcessError
5
+ from subprocess import check_call
3
6
  from typing import cast
4
7
 
5
- from beartype import beartype
6
8
  from click import command
7
- from git import Repo
8
9
  from loguru import logger
9
10
  from tomlkit import loads
10
11
  from tomlkit.container import Container
11
12
 
13
+ from pre_commit_hooks.common import PYPROJECT_TOML
12
14
  from pre_commit_hooks.common import check_versions
13
15
 
14
16
 
15
17
  @command()
16
- @beartype
17
18
  def main() -> bool:
18
19
  """CLI for the `run-hatch-version` hook."""
19
20
  return _process()
20
21
 
21
22
 
22
- @beartype
23
23
  def _process() -> bool:
24
24
  path = _get_path_version_file()
25
25
  pattern = r'^__version__ = "(\d+\.\d+\.\d+)"$'
@@ -28,7 +28,7 @@ def _process() -> bool:
28
28
  return True
29
29
  cmd = ["hatch", "version", str(version)]
30
30
  try:
31
- _ = check_call(cmd, stdout=PIPE, stderr=STDOUT)
31
+ _ = check_call(cmd, stdout=PIPE, stderr=STDOUT) # noqa: S603
32
32
  except CalledProcessError as error:
33
33
  if error.returncode != 1:
34
34
  logger.exception("Failed to run {cmd!r}", cmd=" ".join(cmd))
@@ -41,12 +41,8 @@ def _process() -> bool:
41
41
  return False
42
42
 
43
43
 
44
- @beartype
45
44
  def _get_path_version_file() -> Path:
46
- repo = Repo(".", search_parent_directories=True)
47
- if (wtd := repo.working_tree_dir) is None:
48
- raise ValueError(str(repo))
49
- with Path(wtd, "pyproject.toml").open() as fh:
45
+ with PYPROJECT_TOML.open() as fh:
50
46
  doc = loads(fh.read())
51
47
  try:
52
48
  tool = cast(Container, doc["tool"])
@@ -1,19 +1,25 @@
1
1
  import datetime as dt
2
- from collections.abc import Iterable, Iterator
2
+ from collections.abc import Iterable
3
+ from collections.abc import Iterator
3
4
  from pathlib import Path
4
- from re import MULTILINE, sub
5
- from subprocess import CalledProcessError, check_call
5
+ from re import MULTILINE
6
+ from re import sub
7
+ from subprocess import CalledProcessError
8
+ from subprocess import check_call
6
9
  from tempfile import TemporaryDirectory
7
10
  from textwrap import indent
8
- from typing import Union, cast
11
+ from typing import cast
9
12
 
10
13
  import click
11
- from beartype import beartype
12
- from click import argument, command
13
- from git import Repo
14
+ from click import argument
15
+ from click import command
14
16
  from loguru import logger
15
- from tomlkit import dumps, parse
17
+ from tomlkit import dumps
18
+ from tomlkit import parse
16
19
  from tomlkit.container import Container
20
+ from utilities.git import get_repo_root
21
+
22
+ from pre_commit_hooks.common import PYPROJECT_TOML
17
23
 
18
24
 
19
25
  @command()
@@ -21,17 +27,19 @@ from tomlkit.container import Container
21
27
  "paths",
22
28
  nargs=-1,
23
29
  type=click.Path(
24
- exists=True, file_okay=True, dir_okay=False, readable=True, path_type=Path
30
+ exists=True,
31
+ file_okay=True,
32
+ dir_okay=False,
33
+ readable=True,
34
+ path_type=Path,
25
35
  ),
26
36
  )
27
- @beartype
28
37
  def main(paths: tuple[Path, ...]) -> bool:
29
38
  """CLI for the `run-pip-compile` hook."""
30
39
  results = list(_yield_outcomes(*paths)) # run all
31
40
  return all(results)
32
41
 
33
42
 
34
- @beartype
35
43
  def _yield_outcomes(*paths: Path) -> Iterator[bool]:
36
44
  for path in paths:
37
45
  if (filename := path.name) == "requirements.in":
@@ -43,26 +51,15 @@ def _yield_outcomes(*paths: Path) -> Iterator[bool]:
43
51
  # ---- dependencies -----------------------------------------------------------
44
52
 
45
53
 
46
- @beartype
47
- def _process_dependencies(req_in: Union[Path, str], /) -> bool:
48
- path = _get_pyproject_toml()
49
- curr = _get_curr_pyproject_deps(path)
54
+ def _process_dependencies(req_in: Path | str, /) -> bool:
55
+ curr = _get_curr_pyproject_deps(PYPROJECT_TOML)
50
56
  latest = _run_pip_compile(req_in)
51
57
  if curr == latest:
52
58
  return True
53
- _write_pyproject_deps(path, latest)
59
+ _write_pyproject_deps(PYPROJECT_TOML, latest)
54
60
  return False
55
61
 
56
62
 
57
- @beartype
58
- def _get_pyproject_toml() -> Path:
59
- repo = Repo(".", search_parent_directories=True)
60
- if (wtd := repo.working_tree_dir) is None:
61
- raise ValueError(str(repo))
62
- return Path(wtd, "pyproject.toml")
63
-
64
-
65
- @beartype
66
63
  def _get_curr_pyproject_deps(path: Path, /) -> set[str]:
67
64
  try:
68
65
  with path.open(mode="r") as fh:
@@ -84,8 +81,7 @@ def _get_curr_pyproject_deps(path: Path, /) -> set[str]:
84
81
  return set(cast(Iterable[str], dependencies))
85
82
 
86
83
 
87
- @beartype
88
- def _run_pip_compile(filename: Union[Path, str], /) -> set[str]:
84
+ def _run_pip_compile(filename: Path | str, /) -> set[str]:
89
85
  with TemporaryDirectory() as temp:
90
86
  temp_file = Path(temp, "temp.txt")
91
87
  cmd = [
@@ -101,7 +97,7 @@ def _run_pip_compile(filename: Union[Path, str], /) -> set[str]:
101
97
  Path(filename).as_posix(),
102
98
  ]
103
99
  try:
104
- _ = check_call(cmd)
100
+ _ = check_call(cmd) # noqa: S603
105
101
  except CalledProcessError:
106
102
  logger.exception("Failed to run {cmd!r}", cmd=" ".join(cmd))
107
103
  raise
@@ -111,18 +107,16 @@ def _run_pip_compile(filename: Union[Path, str], /) -> set[str]:
111
107
  return set(filter(_is_requirements_dep, lines))
112
108
 
113
109
 
114
- @beartype
115
110
  def _is_requirements_dep(line: str, /) -> bool:
116
111
  return len(line) >= 1 and not line.startswith("#")
117
112
 
118
113
 
119
- @beartype
120
114
  def _write_pyproject_deps(path: Path, deps: Iterable[str], /) -> None:
121
115
  with path.open(mode="r") as fh:
122
116
  contents = fh.read()
123
117
  doc = parse(contents)
124
118
  project = cast(Container, doc["project"])
125
- now = dt.datetime.now(tz=dt.timezone.utc)
119
+ now = dt.datetime.now(tz=dt.UTC)
126
120
  dummy = f"PIP_COMPILE_{now:%4Y%m%dT%H%M%S}"
127
121
  project["dependencies"] = dummy
128
122
  contents_with_dummy = dumps(doc)
@@ -133,7 +127,6 @@ def _write_pyproject_deps(path: Path, deps: Iterable[str], /) -> None:
133
127
  _ = fh.write(new_contents)
134
128
 
135
129
 
136
- @beartype
137
130
  def _get_replacement_text(deps: Iterable[str], /) -> str:
138
131
  quoted = (f'"{dep}",' for dep in sorted(deps))
139
132
  indented = indent("\n".join(quoted), " ")
@@ -143,9 +136,8 @@ def _get_replacement_text(deps: Iterable[str], /) -> str:
143
136
  # ---- dev dependencies -------------------------------------------------------
144
137
 
145
138
 
146
- @beartype
147
- def _process_dev_dependencies(req_in: Union[Path, str], /) -> bool:
148
- req_txt = _get_requirements_txt()
139
+ def _process_dev_dependencies(req_in: Path | str, /) -> bool:
140
+ req_txt = get_repo_root().joinpath("requirements.txt")
149
141
  try:
150
142
  curr = _get_curr_requirements_deps(req_txt)
151
143
  except FileNotFoundError:
@@ -159,22 +151,12 @@ def _process_dev_dependencies(req_in: Union[Path, str], /) -> bool:
159
151
  return False
160
152
 
161
153
 
162
- @beartype
163
- def _get_requirements_txt() -> Path:
164
- repo = Repo(".", search_parent_directories=True)
165
- if (wtd := repo.working_tree_dir) is None:
166
- raise ValueError(str(repo))
167
- return Path(wtd, "requirements.txt")
168
-
169
-
170
- @beartype
171
154
  def _get_curr_requirements_deps(path: Path, /) -> set[str]:
172
155
  with path.open(mode="r") as fh:
173
156
  lines = fh.readlines()
174
157
  return set(filter(_is_requirements_dep, lines))
175
158
 
176
159
 
177
- @beartype
178
160
  def _write_latest_dev_deps(req_txt: Path, deps: Iterable[str], /) -> None:
179
161
  contents = "\n".join(sorted(deps)) + "\n"
180
162
  with req_txt.open(mode="w") as fh:
@@ -1,15 +0,0 @@
1
- pre_commit_hooks/__init__.py,sha256=hBrVQxNq1ZCcpgYtBzbmp1SLEnPviBqn5xLYM6l0KGw,23
2
- pre_commit_hooks/common.py,sha256=s1KCfnohUjkHVKHGlkQWavJ4YqsIfAXr8FPH3dgLmOc,1910
3
- pre_commit_hooks/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- pre_commit_hooks/run_bump2version/__init__.py,sha256=M8R2MB8E8MuCrA7c6znFLOOtuNm_c0fQvQy7Au3AXPE,1545
5
- pre_commit_hooks/run_bump2version/__main__.py,sha256=Iw8jbq91sc_vSHO-oQfLJMBhM5K0u282b37XRSch0E8,117
6
- pre_commit_hooks/run_dockfmt/__init__.py,sha256=WVUwlJznqAcYpMc3nES7559a34STt6zBX-9Xixq_p1o,1035
7
- pre_commit_hooks/run_dockfmt/__main__.py,sha256=4THoW2NxXW-VQYrtd3ea9hZybF7vDDwGlaLETl7j9SI,112
8
- pre_commit_hooks/run_hatch_version/__init__.py,sha256=P-iSHB7kQf2WHrkVQ97jC7WVVqXf4zVWk3pjghc7jK0,1939
9
- pre_commit_hooks/run_hatch_version/__main__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- pre_commit_hooks/run_pip_compile/__init__.py,sha256=7jJ6S1EIp-6gUKVzXAbfBckjihola8BQGKXfuTUCdOU,5323
11
- pre_commit_hooks/run_pip_compile/__main__.py,sha256=DNITyLZnWcqb_BUHDuTmYU4yY9oENv9Y_WtOyuD0r4Y,89
12
- dycw_pre_commit_hooks-0.8.26.dist-info/METADATA,sha256=utmqht83TrYO02N7ceGHdvs8pVSyqzga7q8WZVqc_R8,978
13
- dycw_pre_commit_hooks-0.8.26.dist-info/WHEEL,sha256=EI2JsGydwUL5GP9t6kzZv7G3HDPi7FuZDDf9In6amRM,87
14
- dycw_pre_commit_hooks-0.8.26.dist-info/entry_points.txt,sha256=uOkhrPXXksWQu3uJoCNvlqdTJ4exmQtfx_IkpOJIbeY,240
15
- dycw_pre_commit_hooks-0.8.26.dist-info/RECORD,,