|
37 | 37 | from apeye.url import URL
|
38 | 38 | from domdf_python_tools.paths import PathPlus
|
39 | 39 | from domdf_python_tools.stringlist import StringList
|
| 40 | +from packaging.version import Version |
40 | 41 | from ruamel.yaml import YAML
|
41 | 42 | from typing_extensions import Literal, TypedDict
|
42 | 43 |
|
@@ -193,12 +194,6 @@ def replace_hooks(self: "Repo", hooks: Iterable[Union[str, Hook]]) -> "Repo":
|
193 | 194 | ],
|
194 | 195 | )
|
195 | 196 |
|
196 |
| -pyupgrade = Repo( |
197 |
| - repo=make_github_url("asottile", "pyupgrade"), |
198 |
| - rev="v2.12.0", |
199 |
| - hooks=[{"id": "pyupgrade", "args": ["--py36-plus", "--keep-runtime-typing"]}] |
200 |
| - ) |
201 |
| - |
202 | 197 | lucas_c_hooks = Repo(
|
203 | 198 | repo=make_github_url("Lucas-C", "pre-commit-hooks"),
|
204 | 199 | rev="v1.5.1",
|
@@ -300,6 +295,27 @@ def make_pre_commit(repo_path: pathlib.Path, templates: Environment) -> List[str
|
300 | 295 | hooks=[{"id": "dep_checker", "args": dep_checker_args}]
|
301 | 296 | )
|
302 | 297 |
|
| 298 | + min_py_version = Version(templates.globals["min_py_version"]) |
| 299 | + |
| 300 | + if min_py_version >= Version("3.11"): |
| 301 | + pyupgrade_plus_arg = "--py311-plus" |
| 302 | + elif min_py_version >= Version("3.10"): |
| 303 | + pyupgrade_plus_arg = "--py310-plus" |
| 304 | + elif min_py_version >= Version("3.9"): |
| 305 | + pyupgrade_plus_arg = "--py39-plus" |
| 306 | + elif min_py_version >= Version("3.8"): |
| 307 | + pyupgrade_plus_arg = "--py38-plus" |
| 308 | + elif min_py_version >= Version("3.7"): |
| 309 | + pyupgrade_plus_arg = "--py37-plus" |
| 310 | + else: |
| 311 | + pyupgrade_plus_arg = "--py36-plus" |
| 312 | + |
| 313 | + pyupgrade = Repo( |
| 314 | + repo=make_github_url("asottile", "pyupgrade"), |
| 315 | + rev="v3.3.0", |
| 316 | + hooks=[{"id": "pyupgrade", "args": [pyupgrade_plus_arg, "--keep-runtime-typing"]}] |
| 317 | + ) |
| 318 | + |
303 | 319 | pre_commit_file = PathPlus(repo_path / ".pre-commit-config.yaml")
|
304 | 320 |
|
305 | 321 | if not pre_commit_file.is_file():
|
|
0 commit comments