From f86e0622a5524ae4ce1f9097ed3aecd6b52f460e Mon Sep 17 00:00:00 2001 From: David Wobrock Date: Mon, 26 Dec 2022 16:11:48 +0100 Subject: [PATCH] Add pre-commit hook and use in CI. --- .pre-commit-config.yaml | 47 ++++++++++++++++++++++++++++++++++++ CHANGELOG.md | 3 ++- docs/internals/publishing.md | 1 - docs/internals/testing.md | 2 +- docs/usage.md | 2 +- requirements/dev.txt | 6 ----- setup.cfg | 9 ------- tox.ini | 10 ++------ 8 files changed, 53 insertions(+), 27 deletions(-) create mode 100644 .pre-commit-config.yaml delete mode 100644 requirements/dev.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..98dddc0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,47 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-added-large-files + - id: check-ast + - id: check-case-conflict + - id: check-json + - id: check-merge-conflict + - id: check-toml + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: forbid-submodules + - id: trailing-whitespace + - repo: https://github.com/psf/black + rev: 22.12.0 + hooks: + - id: black + - repo: https://github.com/PyCQA/flake8 + rev: 6.0.0 + hooks: + - id: flake8 + args: + - "--max-line-length=88" + exclude: ^tests/ + - repo: https://github.com/pycqa/isort + rev: 5.11.4 + hooks: + - id: isort + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.991 + hooks: + - id: mypy + additional_dependencies: + - types-toml==0.10.8.1 + args: + - "--ignore-missing-imports" + exclude: ^tests/ + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.194 + hooks: + - id: ruff + args: + - "--line-length=88" + exclude: ^tests/ diff --git a/CHANGELOG.md b/CHANGELOG.md index fcbbd8d..be7710f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ The crash is a sign to double-check the migration. But if you are certain the mi - Drop support for Django 2.2 - Internally rename "migration tests" to "migration checks" - Add dataclasses internally instead of custom dicts -- Add type checking using `mypy` +- Use pre-commit hooks instead for linting +- Add type checking using `mypy` and `ruff` ## 4.1.0 diff --git a/docs/internals/publishing.md b/docs/internals/publishing.md index 3e26fbd..5cac5db 100644 --- a/docs/internals/publishing.md +++ b/docs/internals/publishing.md @@ -6,4 +6,3 @@ A small note on how the linter is usually published to PyPi: - `pip install wheel twine` - `python3 setup.py sdist bdist_wheel --universal` - `twine upload dist/django_migration_linter-X.Y.Z-py3-none-any.whl dist/django-migration-linter-X.Y.Z.tar.gz` - diff --git a/docs/internals/testing.md b/docs/internals/testing.md index a1f6d31..a78f8aa 100644 --- a/docs/internals/testing.md +++ b/docs/internals/testing.md @@ -11,4 +11,4 @@ You can either tweak the ``tests/test_project/settings.py`` file to get your DB ## Database setup By default, the test Django project in the repository has multiple databases configured in order to make the CI tests work. -Do not hesitate to modify [the configured test databases](../../tests/test_project/settings.py). \ No newline at end of file +Do not hesitate to modify [the configured test databases](../../tests/test_project/settings.py). diff --git a/docs/usage.md b/docs/usage.md index b69ec40..26a15c0 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -2,7 +2,7 @@ ## Command line usage -The linter is installed as a Django app and is integrated through the Django management command system. +The linter is installed as a Django app and is integrated through the Django management command system. `python manage.py lintmigrations [app_label] [migration_name]` diff --git a/requirements/dev.txt b/requirements/dev.txt deleted file mode 100644 index a367549..0000000 --- a/requirements/dev.txt +++ /dev/null @@ -1,6 +0,0 @@ -flake8==6.0.0 -black==22.12.0 -isort==5.11.4 -mypy==0.991 -types-toml==0.10.8.1 -ruff==0.0.194 diff --git a/setup.cfg b/setup.cfg index 1cd7b95..8618a40 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,9 +1,3 @@ -[flake8] -max-line-length = 88 - -[ruff] -line-length = 88 - [isort] multi_line_output = 3 include_trailing_comma = True @@ -13,6 +7,3 @@ ensure_newline_before_comments = True line_length = 88 add_imports = from __future__ import annotations - -[mypy] -ignore_missing_imports = True \ No newline at end of file diff --git a/tox.ini b/tox.ini index 7505e74..9b4ce33 100644 --- a/tox.ini +++ b/tox.ini @@ -26,14 +26,8 @@ deps = [testenv:lint] basepython = python3.10 -deps = - -r requirements/dev.txt -commands = - flake8 django_migration_linter/ - black --check django_migration_linter/ tests/ manage.py setup.py - isort --check-only . - mypy django_migration_linter/ - ruff django_migration_linter/ +deps = pre-commit +commands = pre-commit run --all-files --show-diff-on-failure [testenv:coverage] commands =