dycw-pre-commit-hooks 0.9.24__tar.gz → 0.9.26__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.

Potentially problematic release.


This version of dycw-pre-commit-hooks might be problematic. Click here for more details.

Files changed (31) hide show
  1. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/.github/workflows/push.yml +4 -4
  2. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/.pre-commit-hooks.yaml +16 -0
  3. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/PKG-INFO +3 -3
  4. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pre_commit_hooks/__init__.py +1 -1
  5. dycw_pre_commit_hooks-0.9.26/pre_commit_hooks/run_uv_pip_compile/__init__.py +121 -0
  6. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pyproject.toml +2 -2
  7. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/requirements.txt +11 -11
  8. dycw_pre_commit_hooks-0.9.26/run-test-hook.sh +28 -0
  9. dycw_pre_commit_hooks-0.9.24/pre_commit_hooks/run_uv_pip_compile/__init__.py +0 -80
  10. dycw_pre_commit_hooks-0.9.24/try-repo/run-bump2version.sh +0 -9
  11. dycw_pre_commit_hooks-0.9.24/try-repo/run-dockfmt.sh +0 -9
  12. dycw_pre_commit_hooks-0.9.24/try-repo/run-hatch-version.sh +0 -9
  13. dycw_pre_commit_hooks-0.9.24/try-repo/run-ruff-format.sh +0 -9
  14. dycw_pre_commit_hooks-0.9.24/try-repo/run-uv-pip-compile.sh +0 -9
  15. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/.envrc +0 -0
  16. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/.gitignore +0 -0
  17. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/.pre-commit-config.yaml +0 -0
  18. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/README.md +0 -0
  19. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pre_commit_hooks/common.py +0 -0
  20. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pre_commit_hooks/py.typed +0 -0
  21. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pre_commit_hooks/run_bump2version/__init__.py +0 -0
  22. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pre_commit_hooks/run_bump2version/__main__.py +0 -0
  23. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pre_commit_hooks/run_dockfmt/__init__.py +0 -0
  24. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pre_commit_hooks/run_dockfmt/__main__.py +0 -0
  25. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pre_commit_hooks/run_hatch_version/__init__.py +0 -0
  26. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pre_commit_hooks/run_hatch_version/__main__.py +0 -0
  27. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pre_commit_hooks/run_ruff_format/__init__.py +0 -0
  28. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pre_commit_hooks/run_ruff_format/__main__.py +0 -0
  29. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/pre_commit_hooks/run_uv_pip_compile/__main__.py +0 -0
  30. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/tests/__init__.py +0 -0
  31. {dycw_pre_commit_hooks-0.9.24 → dycw_pre_commit_hooks-0.9.26}/tests/test_main.py +0 -0
@@ -9,7 +9,7 @@ jobs:
9
9
  tag:
10
10
  runs-on: ubuntu-latest
11
11
  steps:
12
- - uses: actions/checkout@v3
12
+ - uses: actions/checkout@v4
13
13
  - uses: butlerlogic/action-autotag@1.1.2 # https://github.com/ButlerLogic/action-autotag/issues/45#issuecomment-1825726927
14
14
  env:
15
15
  GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
@@ -22,13 +22,13 @@ jobs:
22
22
  runs-on: ubuntu-latest
23
23
  needs: tag
24
24
  steps:
25
- - uses: actions/checkout@v3
25
+ - uses: actions/checkout@v4
26
26
  - run: |
27
27
  python -m venv venv
28
28
  source venv/bin/activate
29
29
  python -m pip install --upgrade pip hatch
30
30
  hatch build
31
- - uses: actions/upload-artifact@v3
31
+ - uses: actions/upload-artifact@v4
32
32
  with:
33
33
  name: artifacts
34
34
  path: dist/*
@@ -39,7 +39,7 @@ jobs:
39
39
  needs:
40
40
  - build
41
41
  steps:
42
- - uses: actions/download-artifact@v3
42
+ - uses: actions/download-artifact@v4
43
43
  with:
44
44
  name: artifacts
45
45
  path: dist
@@ -32,3 +32,19 @@
32
32
  files: ^pyproject\.toml$
33
33
  pass_filenames: false
34
34
  description: Run `uv pip compile`
35
+ - id: test-hook
36
+ name: test-hook
37
+ entry: run-uv-pip-compile
38
+ language: python
39
+ files: ^pyproject\.toml$
40
+ pass_filenames: false
41
+ description: Run `uv pip compile`
42
+ args: [
43
+ # --output-file=requirements-macos.txt,
44
+ # --extra=interactive,
45
+ # --python-platform=macos,
46
+ # --python-version=3.12,
47
+ --output-file=requirements-linux.txt,
48
+ --python-platform=linux,
49
+ --python-version=3.12,
50
+ ]
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-pre-commit-hooks
3
- Version: 0.9.24
3
+ Version: 0.9.26
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.95,>=0.94.13
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
@@ -12,7 +12,7 @@ Requires-Dist: xdg-base-dirs<6.1,>=6.0.2
12
12
  Provides-Extra: dev
13
13
  Requires-Dist: dycw-utilities[test]; extra == 'dev'
14
14
  Requires-Dist: hatch<1.15,>=1.14.0; extra == 'dev'
15
- Requires-Dist: setuptools<75.9,>=75.8.0; extra == 'dev'
15
+ Requires-Dist: setuptools<75.9,>=75.8.1; extra == 'dev'
16
16
  Description-Content-Type: text/markdown
17
17
 
18
18
  # pre-commit-hooks
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.9.24"
3
+ __version__ = "0.9.26"
@@ -0,0 +1,121 @@
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
+ from typing import TYPE_CHECKING, Literal
8
+
9
+ from click import Choice, command, option
10
+ from loguru import logger
11
+
12
+ from pre_commit_hooks.common import REQUIREMENTS_TXT
13
+
14
+ if TYPE_CHECKING:
15
+ from collections.abc import Iterable
16
+
17
+
18
+ @command()
19
+ @option(
20
+ "--output-file",
21
+ default=REQUIREMENTS_TXT,
22
+ help="Write the compiled requirements to the given `requirements.txt` file",
23
+ )
24
+ @option("--extra", multiple=True, help="Optional dependencies")
25
+ @option(
26
+ "--python-platform",
27
+ type=Choice(["windows", "linux", "macos"], case_sensitive=False),
28
+ help="The platform for which requirements should be resolved",
29
+ )
30
+ @option(
31
+ "--python-version", default=None, help="The Python version to use for resolution"
32
+ )
33
+ def main(
34
+ *,
35
+ output_file: Path | str = REQUIREMENTS_TXT,
36
+ extra: tuple[str, ...] = (),
37
+ python_platform: Literal["windows", "linux", "macos"] | None = None,
38
+ python_version: str | None = None,
39
+ ) -> bool:
40
+ """CLI for the `run-uv-pip-compile` hook."""
41
+ return _process(
42
+ output_file=Path(output_file),
43
+ extra=None if len(extra) == 0 else list(extra),
44
+ python_platform=python_platform,
45
+ python_version=python_version,
46
+ )
47
+
48
+
49
+ def _process(
50
+ *,
51
+ extra: Iterable[str] | None = None,
52
+ output_file: Path = REQUIREMENTS_TXT,
53
+ python_platform: Literal["windows", "linux", "macos"] | None = None,
54
+ python_version: str | None = None,
55
+ ) -> bool:
56
+ curr = _read_requirements_txt(output_file)
57
+ latest = _run_uv_pip_compile(
58
+ extra=extra, python_platform=python_platform, python_version=python_version
59
+ )
60
+ if curr == latest:
61
+ return True
62
+ _write_requirements_txt(latest, path=output_file)
63
+ return False
64
+
65
+
66
+ def _read_requirements_txt(path: Path, /) -> str | None:
67
+ try:
68
+ with path.open() as fh:
69
+ return fh.read()
70
+ except FileNotFoundError:
71
+ return None
72
+
73
+
74
+ def _run_uv_pip_compile(
75
+ *,
76
+ extra: Iterable[str] | None = None,
77
+ python_platform: Literal["windows", "linux", "macos"] | None = None,
78
+ python_version: str | None = None,
79
+ ) -> str:
80
+ cmd: list[str] = [
81
+ "uv",
82
+ "pip",
83
+ "compile",
84
+ "--extra=dev",
85
+ "--prerelease=explicit",
86
+ "--quiet",
87
+ "--upgrade",
88
+ ]
89
+ if extra is not None:
90
+ cmd.extend(f"--extra={e}" for e in extra)
91
+ if python_platform is not None:
92
+ cmd.append(f"--python-platform={python_platform}")
93
+ if python_version is not None:
94
+ cmd.append(f"--python-version={python_version}")
95
+ with TemporaryDirectory() as temp:
96
+ temp_file = Path(temp, "temp.txt")
97
+ cmd.extend([
98
+ f"--output-file={temp_file.as_posix()}",
99
+ "pyproject.toml", # don't use absolute path
100
+ ])
101
+ try:
102
+ _ = check_call(cmd)
103
+ except CalledProcessError:
104
+ logger.exception("Failed to run {cmd!r}", cmd=" ".join(cmd))
105
+ raise
106
+ with temp_file.open(mode="r") as fh:
107
+ contents = fh.read()
108
+ return _fix_header(contents, temp_file) + "\n"
109
+
110
+
111
+ def _fix_header(text: str, temp_file: Path, /) -> str:
112
+ return "\n".join(_fix_header_line(line, temp_file) for line in text.splitlines())
113
+
114
+
115
+ def _fix_header_line(line: str, temp_file: Path, /) -> str:
116
+ return sub(str(temp_file), temp_file.name, line)
117
+
118
+
119
+ def _write_requirements_txt(contents: str, /, *, path: Path = REQUIREMENTS_TXT) -> None:
120
+ with path.open(mode="w") as fh:
121
+ _ = fh.write(contents)
@@ -9,7 +9,7 @@ requires = ["hatchling"]
9
9
  authors = [{name = "Derek Wan", email = "d.wan@icloud.com"}]
10
10
  dependencies = [
11
11
  "click >= 8.1.8, < 8.2",
12
- "dycw-utilities >= 0.92.10, < 0.93",
12
+ "dycw-utilities >= 0.94.13, < 0.95",
13
13
  "loguru >= 0.7.3, < 0.8",
14
14
  "semver >= 3.0.4, < 3.1",
15
15
  "tomlkit >= 0.13.2, < 0.14",
@@ -24,7 +24,7 @@ requires-python = ">= 3.11"
24
24
  dev = [
25
25
  "dycw-utilities[test]",
26
26
  "hatch >= 1.14.0, < 1.15",
27
- "setuptools >= 75.8.0, < 75.9", # https://github.com/theY4Kman/pytest-only/issues/14
27
+ "setuptools >= 75.8.1, < 75.9", # https://github.com/theY4Kman/pytest-only/issues/14
28
28
  ]
29
29
 
30
30
  [project.scripts]
@@ -6,7 +6,7 @@ attrs==25.1.0
6
6
  # via hypothesis
7
7
  backports-tarfile==1.2.0
8
8
  # via jaraco-context
9
- certifi==2024.12.14
9
+ certifi==2025.1.31
10
10
  # via
11
11
  # httpcore
12
12
  # httpx
@@ -15,7 +15,7 @@ click==8.1.8
15
15
  # dycw-pre-commit-hooks (pyproject.toml)
16
16
  # hatch
17
17
  # userpath
18
- coverage==7.6.10
18
+ coverage==7.6.12
19
19
  # via
20
20
  # coverage-conditional-plugin
21
21
  # pytest-cov
@@ -23,7 +23,7 @@ coverage-conditional-plugin==0.9.0
23
23
  # via dycw-utilities
24
24
  distlib==0.3.9
25
25
  # via virtualenv
26
- dycw-utilities==0.92.10
26
+ dycw-utilities==0.94.13
27
27
  # via dycw-pre-commit-hooks (pyproject.toml)
28
28
  execnet==2.1.1
29
29
  # via pytest-xdist
@@ -41,7 +41,7 @@ httpx==0.28.1
41
41
  # via hatch
42
42
  hyperlink==21.0.0
43
43
  # via hatch
44
- hypothesis==6.124.7
44
+ hypothesis==6.127.2
45
45
  # via dycw-utilities
46
46
  idna==3.10
47
47
  # via
@@ -70,7 +70,7 @@ more-itertools==10.6.0
70
70
  # via
71
71
  # jaraco-classes
72
72
  # jaraco-functools
73
- numpy==2.2.2
73
+ numpy==2.2.3
74
74
  # via pytest-rng
75
75
  packaging==24.2
76
76
  # via
@@ -108,11 +108,11 @@ pytest==8.3.4
108
108
  # pytest-rerunfailures
109
109
  # pytest-rng
110
110
  # pytest-xdist
111
- pytest-asyncio==0.25.2
111
+ pytest-asyncio==0.25.3
112
112
  # via dycw-utilities
113
113
  pytest-cov==6.0.0
114
114
  # via dycw-utilities
115
- pytest-datadir==1.5.0
115
+ pytest-datadir==1.6.1
116
116
  # via pytest-regressions
117
117
  pytest-instafail==0.5.0
118
118
  # via dycw-utilities
@@ -134,7 +134,7 @@ rich==13.9.4
134
134
  # via hatch
135
135
  semver==3.0.4
136
136
  # via dycw-pre-commit-hooks (pyproject.toml)
137
- setuptools==75.8.0
137
+ setuptools==75.8.1
138
138
  # via dycw-pre-commit-hooks (pyproject.toml)
139
139
  shellingham==1.5.4
140
140
  # via hatch
@@ -150,7 +150,7 @@ tomlkit==0.13.2
150
150
  # via
151
151
  # dycw-pre-commit-hooks (pyproject.toml)
152
152
  # hatch
153
- trove-classifiers==2025.1.15.22
153
+ trove-classifiers==2025.2.18.16
154
154
  # via hatchling
155
155
  typing-extensions==4.12.2
156
156
  # via
@@ -158,9 +158,9 @@ typing-extensions==4.12.2
158
158
  # dycw-utilities
159
159
  userpath==1.9.2
160
160
  # via hatch
161
- uv==0.5.24
161
+ uv==0.6.3
162
162
  # via hatch
163
- virtualenv==20.29.1
163
+ virtualenv==20.29.2
164
164
  # via hatch
165
165
  xdg-base-dirs==6.0.2
166
166
  # via dycw-pre-commit-hooks (pyproject.toml)
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # usage: edit the following in `.pre-commit-hooks.yaml`
4
+ #
5
+ # - id: test-hook
6
+ # name: test-hook
7
+ # entry: run-uv-pip-compile
8
+ # language: python
9
+ # files: ^pyproject\.toml$
10
+ # pass_filenames: false
11
+ # description: Run `uv pip compile`
12
+ # args: [
13
+ # --output-file=requirements-macos.txt
14
+ # --extra=interactive
15
+ # --python-platform=macos
16
+ # --python-version=3.12,
17
+ # ]
18
+ #
19
+ # then, in your project, run:
20
+ #
21
+ # ❯ ../pre-commit-hooks/run-test-hook.sh
22
+
23
+ PATH_DIR="$(
24
+ cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit
25
+ pwd -P
26
+ )"
27
+
28
+ pre-commit try-repo --verbose --all-files "$PATH_DIR" test-hook
@@ -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,9 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- PATH_SCRIPTS_DIR="$(
4
- cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit
5
- pwd -P
6
- )"
7
- PATH_REPO_ROOT="$(dirname "${PATH_SCRIPTS_DIR}")"
8
-
9
- pre-commit try-repo --verbose --all-files "$PATH_REPO_ROOT" run-bump2version "$@"
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- PATH_SCRIPTS_DIR="$(
4
- cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit
5
- pwd -P
6
- )"
7
- PATH_REPO_ROOT="$(dirname "${PATH_SCRIPTS_DIR}")"
8
-
9
- pre-commit try-repo --verbose --all-files "$PATH_REPO_ROOT" run-dockfmt "$@"
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- PATH_SCRIPTS_DIR="$(
4
- cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit
5
- pwd -P
6
- )"
7
- PATH_REPO_ROOT="$(dirname "${PATH_SCRIPTS_DIR}")"
8
-
9
- pre-commit try-repo --verbose --all-files "$PATH_REPO_ROOT" run-hatch-version "$@"
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- PATH_SCRIPTS_DIR="$(
4
- cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit
5
- pwd -P
6
- )"
7
- PATH_REPO_ROOT="$(dirname "${PATH_SCRIPTS_DIR}")"
8
-
9
- pre-commit try-repo --verbose --all-files "$PATH_REPO_ROOT" run-ruff-format "$@"
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- PATH_SCRIPTS_DIR="$(
4
- cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit
5
- pwd -P
6
- )"
7
- PATH_REPO_ROOT="$(dirname "${PATH_SCRIPTS_DIR}")"
8
-
9
- pre-commit try-repo --verbose --all-files "$PATH_REPO_ROOT" run-uv-pip-compile "$@"