dycw-pre-commit-hooks 0.10.12__py3-none-any.whl → 0.14.26__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.
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.3
2
+ Name: dycw-pre-commit-hooks
3
+ Version: 0.14.26
4
+ Summary: Pre-commit hooks
5
+ Author: Derek Wan
6
+ Author-email: Derek Wan <d.wan@icloud.com>
7
+ Requires-Dist: click>=8.3.1
8
+ Requires-Dist: dycw-utilities>=0.184.4
9
+ Requires-Dist: libcst>=1.8.6
10
+ Requires-Dist: orjson>=3.11.5
11
+ Requires-Dist: packaging>=25.0
12
+ Requires-Dist: pyyaml>=6.0.3
13
+ Requires-Dist: tomlkit>=0.14.0
14
+ Requires-Dist: xdg-base-dirs>=6.0.2
15
+ Requires-Dist: click==8.3.1 ; extra == 'cli'
16
+ Requires-Dist: dycw-utilities==0.184.4 ; extra == 'cli'
17
+ Requires-Dist: libcst==1.8.6 ; extra == 'cli'
18
+ Requires-Dist: orjson==3.11.5 ; extra == 'cli'
19
+ Requires-Dist: packaging==25.0 ; extra == 'cli'
20
+ Requires-Dist: pyyaml==6.0.3 ; extra == 'cli'
21
+ Requires-Dist: tomlkit==0.14.0 ; extra == 'cli'
22
+ Requires-Dist: xdg-base-dirs==6.0.2 ; extra == 'cli'
23
+ Requires-Python: >=3.12
24
+ Provides-Extra: cli
25
+ Description-Content-Type: text/markdown
26
+
27
+ # pre-commit-hooks
28
+
29
+ ## Overview
30
+
31
+ My [`pre-commit`](https://pre-commit.com/) hooks.
32
+
33
+ ## Installation
34
+
35
+ 1. Install `pre-commit`.
36
+
37
+ 1. Add the following to your `.pre-commit-config.yaml`:
38
+
39
+ ```yaml
40
+ repos:
41
+ - repo: https://github.com/dycw/pre-commit-hooks
42
+ rev: master
43
+ hooks:
44
+ - id: check-submodules-updated
45
+ - id: check-version-bumped
46
+ - id: format-requirements
47
+ - id: mirror-files
48
+ - id: replace-sequence-str
49
+ - id: run-version-bump
50
+ - id: tag-commits
51
+ ```
52
+
53
+ 1. Update your `.pre-commit-config.yaml`:
54
+
55
+ ```bash
56
+ pre-commit autoupdate
57
+ ```
@@ -0,0 +1,23 @@
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,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
2
+ Generator: uv 0.9.26
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -0,0 +1,14 @@
1
+ [console_scripts]
2
+ add-future-import-annotations = pre_commit_hooks.hooks.add_future_import_annotations:_main
3
+ add-hooks = pre_commit_hooks.hooks.add_hooks:_main
4
+ check-versions-consistent = pre_commit_hooks.hooks.check_versions_consistent:_main
5
+ format-pre-commit-config = pre_commit_hooks.hooks.format_pre_commit_config:_main
6
+ format-requirements = pre_commit_hooks.hooks.format_requirements:_main
7
+ replace-sequence-str = pre_commit_hooks.hooks.replace_sequence_str:_main
8
+ run-prek-autoupdate = pre_commit_hooks.hooks.run_prek_autoupdate:_main
9
+ run-version-bump = pre_commit_hooks.hooks.run_version_bump:_main
10
+ setup-git = pre_commit_hooks.hooks.setup_git:_main
11
+ setup-pyright = pre_commit_hooks.hooks.setup_pyright:_main
12
+ setup-ruff = pre_commit_hooks.hooks.setup_ruff:_main
13
+ update-requirements = pre_commit_hooks.hooks.update_requirements:_main
14
+
@@ -0,0 +1,3 @@
1
+ from __future__ import annotations
2
+
3
+ __version__ = "0.14.26"
@@ -0,0 +1,243 @@
1
+ #### STANDARD GITIGNORE #######################################################
2
+ # Byte-compiled / optimized / DLL files
3
+ __pycache__/
4
+ *.py[codz]
5
+ *$py.class
6
+
7
+ # C extensions
8
+ *.so
9
+
10
+ # Distribution / packaging
11
+ .Python
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ wheels/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py.cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ # Pipfile.lock
97
+
98
+ # UV
99
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # uv.lock
103
+
104
+ # poetry
105
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
106
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
107
+ # commonly ignored for libraries.
108
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
109
+ # poetry.lock
110
+ # poetry.toml
111
+
112
+ # pdm
113
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
114
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
115
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
116
+ # pdm.lock
117
+ # pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # pixi
122
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
123
+ # pixi.lock
124
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
125
+ # in the .venv directory. It is recommended not to include this directory in version control.
126
+ .pixi
127
+
128
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
129
+ __pypackages__/
130
+
131
+ # Celery stuff
132
+ celerybeat-schedule
133
+ celerybeat.pid
134
+
135
+ # Redis
136
+ *.rdb
137
+ *.aof
138
+ *.pid
139
+
140
+ # RabbitMQ
141
+ mnesia/
142
+ rabbitmq/
143
+ rabbitmq-data/
144
+
145
+ # ActiveMQ
146
+ activemq-data/
147
+
148
+ # SageMath parsed files
149
+ *.sage.py
150
+
151
+ # Environments
152
+ .venv
153
+ env/
154
+ venv/
155
+ ENV/
156
+ env.bak/
157
+ venv.bak/
158
+
159
+ # Spyder project settings
160
+ .spyderproject
161
+ .spyproject
162
+
163
+ # Rope project settings
164
+ .ropeproject
165
+
166
+ # mkdocs documentation
167
+ /site
168
+
169
+ # mypy
170
+ .mypy_cache/
171
+ .dmypy.json
172
+ dmypy.json
173
+
174
+ # Pyre type checker
175
+ .pyre/
176
+
177
+ # pytype static type analyzer
178
+ .pytype/
179
+
180
+ # Cython debug symbols
181
+ cython_debug/
182
+
183
+ # PyCharm
184
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
185
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
186
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
187
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
188
+ # .idea/
189
+
190
+ # Abstra
191
+ # Abstra is an AI-powered process automation framework.
192
+ # Ignore directories containing user credentials, local state, and settings.
193
+ # Learn more at https://abstra.io/docs
194
+ .abstra/
195
+
196
+ # Visual Studio Code
197
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
198
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
199
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
200
+ # you could uncomment the following to ignore the entire vscode folder
201
+ # .vscode/
202
+
203
+ # Ruff stuff:
204
+ .ruff_cache/
205
+
206
+ # PyPI configuration file
207
+ .pypirc
208
+
209
+ # Marimo
210
+ marimo/_static/
211
+ marimo/_lsp/
212
+ __marimo__/
213
+
214
+ # Streamlit
215
+ .streamlit/secrets.toml
216
+
217
+ #### END OF STANDARD GITIGNORE ################################################
218
+
219
+ #### CUSTOM GITIGNORE #########################################################
220
+
221
+ **/*.csv
222
+ **/*.db
223
+ **/*.gz
224
+ **/*.html
225
+ **/*.ipc
226
+ **/*.ipynb
227
+ **/*.pdf
228
+ **/*.pickle
229
+ **/*.shelf
230
+ **/*.sqlite
231
+ **/*.tar.gz
232
+ **/*.tar.lz
233
+ **/*.tmp
234
+ .direnv/
235
+ .logs/
236
+ htmls/
237
+ ipcs/
238
+ pdfs/
239
+ pickles/
240
+ shelves/
241
+ tmp/
242
+
243
+ #### END OF CUSTOM GITIGNORE ##################################################
@@ -0,0 +1,149 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+
5
+ import utilities.click
6
+ from click import argument, option
7
+ from utilities.constants import HOUR
8
+ from xdg_base_dirs import xdg_cache_home
9
+
10
+ BUILTIN = "builtin"
11
+ DOCKERFMT_URL = "https://github.com/reteps/dockerfmt"
12
+ DYCW_PRE_COMMIT_HOOKS_URL = "https://github.com/dycw/pre-commit-hooks"
13
+ RUFF_URL = "https://github.com/astral-sh/ruff-pre-commit"
14
+ SHELLCHECK_URL = "https://github.com/koalaman/shellcheck-precommit"
15
+ SHFMT_URL = "https://github.com/scop/pre-commit-shfmt"
16
+ STD_PRE_COMMIT_HOOKS_URL = "https://github.com/pre-commit/pre-commit-hooks"
17
+ TAPLO_URL = "https://github.com/compwa/taplo-pre-commit"
18
+ UV_URL = "https://github.com/astral-sh/uv-pre-commit"
19
+
20
+
21
+ BUMPVERSION_TOML = Path(".bumpversion.toml")
22
+ COVERAGERC_TOML = Path(".coveragerc.toml")
23
+ ENVRC = Path(".envrc")
24
+ GITEA = Path(".gitea")
25
+ GITHUB = Path(".github")
26
+ GITIGNORE = Path(".gitignore")
27
+ PRE_COMMIT_CONFIG_YAML = Path(".pre-commit-config.yaml")
28
+ PYPROJECT_TOML = Path("pyproject.toml")
29
+ PYRIGHTCONFIG_JSON = Path("pyrightconfig.json")
30
+ PYTEST_TOML = Path("pytest.toml")
31
+ README_MD = Path("README.md")
32
+ SSH = Path.home() / ".ssh"
33
+ RUFF_TOML = Path("ruff.toml")
34
+
35
+
36
+ DEFAULT_PYTHON_VERSION = "3.12"
37
+ MAX_PYTHON_VERSION = "3.14"
38
+
39
+
40
+ FORMATTER_PRIORITY = 10
41
+ LINTER_PRIORITY = 20
42
+
43
+
44
+ GITHUB_WORKFLOWS, GITEA_WORKFLOWS = [g / "workflows" for g in [GITHUB, GITEA]]
45
+ GITHUB_PULL_REQUEST_YAML, GITEA_PULL_REQUEST_YAML = [
46
+ w / "pull-request.yaml" for w in [GITHUB_WORKFLOWS, GITEA_WORKFLOWS]
47
+ ]
48
+ GITHUB_PUSH_YAML, GITEA_PUSH_YAML = [
49
+ w / "push.yaml" for w in [GITHUB_WORKFLOWS, GITEA_WORKFLOWS]
50
+ ]
51
+
52
+
53
+ PATH_CACHE = xdg_cache_home() / "pre-commit-hooks"
54
+
55
+
56
+ PRE_COMMIT_CONFIG_REPO_KEYS = ["repo", "rev", "hooks"]
57
+ PRE_COMMIT_CONFIG_HOOK_KEYS = [
58
+ "id",
59
+ "alias",
60
+ "name",
61
+ "language_version",
62
+ "files",
63
+ "exclude",
64
+ "types",
65
+ "types_or",
66
+ "exclude_types",
67
+ "args",
68
+ "stages",
69
+ "additional_dependencies",
70
+ "always_run",
71
+ "verbose",
72
+ "log_file",
73
+ "priority", # prek
74
+ ]
75
+ PRE_COMMIT_HOOKS_HOOK_KEYS = [
76
+ "id",
77
+ "name",
78
+ "entry",
79
+ "language",
80
+ "files",
81
+ "exclude",
82
+ "types",
83
+ "types_or",
84
+ "exclude_types",
85
+ "always_run",
86
+ "fail_fast",
87
+ "verbose",
88
+ "pass_filenames",
89
+ "require_serial",
90
+ "description",
91
+ "language_version",
92
+ "minimum_pre_commit_version",
93
+ "args",
94
+ "stages",
95
+ "priority", # prek
96
+ ]
97
+
98
+
99
+ THROTTLE_DURATION = 12 * HOUR
100
+
101
+
102
+ paths_argument = argument("paths", nargs=-1, type=utilities.click.Path())
103
+ python_version_option = option(
104
+ "--python-version", type=str, default=DEFAULT_PYTHON_VERSION
105
+ )
106
+ throttle_option = option("--throttle", is_flag=True, default=True)
107
+
108
+
109
+ __all__ = [
110
+ "BUILTIN",
111
+ "BUMPVERSION_TOML",
112
+ "COVERAGERC_TOML",
113
+ "DEFAULT_PYTHON_VERSION",
114
+ "DOCKERFMT_URL",
115
+ "DYCW_PRE_COMMIT_HOOKS_URL",
116
+ "ENVRC",
117
+ "FORMATTER_PRIORITY",
118
+ "GITEA",
119
+ "GITEA_PUSH_YAML",
120
+ "GITEA_WORKFLOWS",
121
+ "GITHUB",
122
+ "GITHUB_PULL_REQUEST_YAML",
123
+ "GITHUB_PUSH_YAML",
124
+ "GITHUB_WORKFLOWS",
125
+ "GITHUB_WORKFLOWS",
126
+ "GITIGNORE",
127
+ "LINTER_PRIORITY",
128
+ "MAX_PYTHON_VERSION",
129
+ "PATH_CACHE",
130
+ "PRE_COMMIT_CONFIG_HOOK_KEYS",
131
+ "PRE_COMMIT_CONFIG_REPO_KEYS",
132
+ "PRE_COMMIT_CONFIG_YAML",
133
+ "PYPROJECT_TOML",
134
+ "PYRIGHTCONFIG_JSON",
135
+ "PYTEST_TOML",
136
+ "README_MD",
137
+ "RUFF_TOML",
138
+ "RUFF_URL",
139
+ "SHELLCHECK_URL",
140
+ "SHFMT_URL",
141
+ "SSH",
142
+ "STD_PRE_COMMIT_HOOKS_URL",
143
+ "TAPLO_URL",
144
+ "THROTTLE_DURATION",
145
+ "UV_URL",
146
+ "paths_argument",
147
+ "python_version_option",
148
+ "throttle_option",
149
+ ]
@@ -0,0 +1 @@
1
+ from __future__ import annotations
@@ -0,0 +1,63 @@
1
+ from __future__ import annotations
2
+
3
+ from functools import partial
4
+ from pathlib import Path
5
+ from typing import TYPE_CHECKING
6
+
7
+ from click import command
8
+ from libcst import parse_statement
9
+ from utilities.click import CONTEXT_SETTINGS
10
+ from utilities.os import is_pytest
11
+ from utilities.throttle import throttle
12
+
13
+ from pre_commit_hooks.constants import (
14
+ THROTTLE_DURATION,
15
+ paths_argument,
16
+ throttle_option,
17
+ )
18
+ from pre_commit_hooks.utilities import (
19
+ path_throttle_cache,
20
+ run_all_maybe_raise,
21
+ yield_python_file,
22
+ )
23
+
24
+ if TYPE_CHECKING:
25
+ from collections.abc import MutableSet
26
+ from pathlib import Path
27
+
28
+ from utilities.types import PathLike
29
+
30
+
31
+ @command(**CONTEXT_SETTINGS)
32
+ @paths_argument
33
+ @throttle_option
34
+ def _main(*, paths: tuple[Path, ...], throttle: bool = True) -> None:
35
+ if is_pytest():
36
+ return
37
+ run_all_maybe_raise(*(partial(_run, p, throttle=throttle) for p in paths))
38
+
39
+
40
+ def _run(path: PathLike, /, *, throttle: bool = True) -> bool:
41
+ modifications: set[Path] = set()
42
+ func = _run_throttled if throttle else _run_unthrottled
43
+ func(path, modifications=modifications)
44
+ return len(modifications) == 0
45
+
46
+
47
+ def _run_unthrottled(
48
+ path: PathLike, /, *, modifications: MutableSet[Path] | None = None
49
+ ) -> None:
50
+ with yield_python_file(path, modifications=modifications) as context:
51
+ if len(context.input.body) == 0:
52
+ body = [parse_statement("from __future__ import annotations")]
53
+ context.output = context.input.with_changes(body=body)
54
+
55
+
56
+ _run_throttled = throttle(
57
+ duration=THROTTLE_DURATION,
58
+ path=path_throttle_cache("add-future-import-annotations"),
59
+ )(_run_unthrottled)
60
+
61
+
62
+ if __name__ == "__main__":
63
+ _main()