mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-06-29 09:53:06 +03:00
Add django-upgrade to pre-commit hooks (#4298)
This commit is contained in:
parent
9d821ee82b
commit
c88f8ef37a
|
@ -7,6 +7,7 @@ binaryornot==0.4.4
|
||||||
black==23.3.0
|
black==23.3.0
|
||||||
isort==5.12.0
|
isort==5.12.0
|
||||||
flake8==6.0.0
|
flake8==6.0.0
|
||||||
|
django-upgrade==1.13.0
|
||||||
pre-commit==3.2.2
|
pre-commit==3.2.2
|
||||||
|
|
||||||
# Testing
|
# Testing
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import glob
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
@ -24,6 +25,7 @@ elif sys.platform.startswith("darwin") and os.getenv("CI"):
|
||||||
# automatically by running pre-commit after generation however they are tedious
|
# automatically by running pre-commit after generation however they are tedious
|
||||||
# to fix in the template, so we don't insist too much in fixing them.
|
# to fix in the template, so we don't insist too much in fixing them.
|
||||||
AUTOFIXABLE_STYLES = os.getenv("AUTOFIXABLE_STYLES") == "1"
|
AUTOFIXABLE_STYLES = os.getenv("AUTOFIXABLE_STYLES") == "1"
|
||||||
|
auto_fixable = pytest.mark.skipif(not AUTOFIXABLE_STYLES, reason="auto-fixable")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -185,7 +187,7 @@ def test_flake8_passes(cookies, context_override):
|
||||||
pytest.fail(e.stdout.decode())
|
pytest.fail(e.stdout.decode())
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not AUTOFIXABLE_STYLES, reason="Black is auto-fixable")
|
@auto_fixable
|
||||||
@pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id)
|
@pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id)
|
||||||
def test_black_passes(cookies, context_override):
|
def test_black_passes(cookies, context_override):
|
||||||
"""Check whether generated project passes black style."""
|
"""Check whether generated project passes black style."""
|
||||||
|
@ -204,7 +206,7 @@ def test_black_passes(cookies, context_override):
|
||||||
pytest.fail(e.stdout.decode())
|
pytest.fail(e.stdout.decode())
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not AUTOFIXABLE_STYLES, reason="isort is auto-fixable")
|
@auto_fixable
|
||||||
@pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id)
|
@pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id)
|
||||||
def test_isort_passes(cookies, context_override):
|
def test_isort_passes(cookies, context_override):
|
||||||
"""Check whether generated project passes isort style."""
|
"""Check whether generated project passes isort style."""
|
||||||
|
@ -216,6 +218,27 @@ def test_isort_passes(cookies, context_override):
|
||||||
pytest.fail(e.stdout.decode())
|
pytest.fail(e.stdout.decode())
|
||||||
|
|
||||||
|
|
||||||
|
@auto_fixable
|
||||||
|
@pytest.mark.parametrize("context_override", SUPPORTED_COMBINATIONS, ids=_fixture_id)
|
||||||
|
def test_django_upgrade_passes(cookies, context_override):
|
||||||
|
"""Check whether generated project passes django-upgrade."""
|
||||||
|
result = cookies.bake(extra_context=context_override)
|
||||||
|
|
||||||
|
python_files = [
|
||||||
|
file_path.removeprefix(f"{result.project_path}/")
|
||||||
|
for file_path in glob.glob(str(result.project_path / "**" / "*.py"), recursive=True)
|
||||||
|
]
|
||||||
|
try:
|
||||||
|
sh.django_upgrade(
|
||||||
|
"--target-version",
|
||||||
|
"4.1",
|
||||||
|
*python_files,
|
||||||
|
_cwd=str(result.project_path),
|
||||||
|
)
|
||||||
|
except sh.ErrorReturnCode as e:
|
||||||
|
pytest.fail(e.stdout.decode())
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
["use_docker", "expected_test_script"],
|
["use_docker", "expected_test_script"],
|
||||||
[
|
[
|
||||||
|
|
|
@ -24,6 +24,12 @@ repos:
|
||||||
args: ['--tab-width', '2', '--single-quote']
|
args: ['--tab-width', '2', '--single-quote']
|
||||||
exclude: '{{cookiecutter.project_slug}}/templates/'
|
exclude: '{{cookiecutter.project_slug}}/templates/'
|
||||||
|
|
||||||
|
- repo: https://github.com/adamchainz/django-upgrade
|
||||||
|
rev: "1.13.0"
|
||||||
|
hooks:
|
||||||
|
- id: django-upgrade
|
||||||
|
args: ["--target-version", "4.1"]
|
||||||
|
|
||||||
- repo: https://github.com/asottile/pyupgrade
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
rev: v3.3.2
|
rev: v3.3.2
|
||||||
hooks:
|
hooks:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user