Skip to content

Commit a7c4668

Browse files
committed
Configure pyupgrade to upgrade to versions newer than 3.6
1 parent f523f72 commit a7c4668

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

repo_helper/files/pre_commit.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from apeye.url import URL
3838
from domdf_python_tools.paths import PathPlus
3939
from domdf_python_tools.stringlist import StringList
40+
from packaging.version import Version
4041
from ruamel.yaml import YAML
4142
from typing_extensions import Literal, TypedDict
4243

@@ -193,12 +194,6 @@ def replace_hooks(self: "Repo", hooks: Iterable[Union[str, Hook]]) -> "Repo":
193194
],
194195
)
195196

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-
202197
lucas_c_hooks = Repo(
203198
repo=make_github_url("Lucas-C", "pre-commit-hooks"),
204199
rev="v1.5.1",
@@ -300,6 +295,27 @@ def make_pre_commit(repo_path: pathlib.Path, templates: Environment) -> List[str
300295
hooks=[{"id": "dep_checker", "args": dep_checker_args}]
301296
)
302297

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+
303319
pre_commit_file = PathPlus(repo_path / ".pre-commit-config.yaml")
304320

305321
if not pre_commit_file.is_file():

tests/test_files/test_testing_/test_make_pre_commit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ repos:
6262
- id: rst-inline-touching-normal
6363

6464
- repo: https://github.com/asottile/pyupgrade
65-
rev: v2.12.0
65+
rev: v3.3.0
6666
hooks:
6767
- id: pyupgrade
6868
args:

0 commit comments

Comments
 (0)