Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilize pre-commit to manage lint and styles. #35

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TODO: move this to pyproject.toml when supported, see https://github.com/PyCQA/flake8/issues/234

[flake8]
extend-ignore = E203, E501
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ db.sqlite3
htmlcov/
dist/
.tox/

54 changes: 54 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: mixed-line-ending
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/doc8
rev: v1.1.1
hooks:
- id: doc8
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.13.0
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: rst-backticks
- id: rst-directive-colons
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
language_version: python3
entry: black --target-version=py38
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 0.9.2
hooks:
- id: pyproject-fmt
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.12.1
hooks:
- id: validate-pyproject
31 changes: 18 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
requires = [
"poetry>=0.12",
]

[tool.isort]
combine_as_imports = true
profile = "black"

[tool.coverage.run]
branch = true
parallel = true
source = ["django_safemigrate"]

[tool.coverage.paths]
source = ["src", ".tox/*/site-packages"]

[tool.coverage.report]
show_missing = true

[tool.poetry]
name = "django-safemigrate"
Expand All @@ -16,15 +33,3 @@ django = ">=3.2,<5.0"

[tool.poetry.dev-dependencies]
tox = "*"
black = "*"

[tool.coverage.run]
branch = true
parallel = true
source = ["django_safemigrate"]

[tool.coverage.paths]
source = ["src", ".tox/*/site-packages"]

[tool.coverage.report]
show_missing = true
4 changes: 2 additions & 2 deletions src/django_safemigrate/management/commands/safemigrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
Migration safety is enforced by a pre_migrate signal receiver.
"""
from django.conf import settings
from django.db.models.signals import pre_migrate
from django.core.management.base import CommandError
from django.core.management.commands import migrate
from django.db.models.signals import pre_migrate

from django_safemigrate import Safe
from django_safemigrate.apps import SafeMigrateConfig


def safety(migration):
Expand Down
3 changes: 3 additions & 0 deletions tests/safemigrate_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Unit tests for the safemigrate command."""
import pytest
from django.core.management.base import CommandError

from django_safemigrate import Safe
from django_safemigrate.management.commands.safemigrate import Command

Expand Down Expand Up @@ -156,6 +157,8 @@ def test_blocked_by_after_run_before(self, receiver):
),
(Migration("eggs", "0001_safety", safe=Safe.before_deploy), False),
]
with pytest.raises(CommandError):
receiver(plan=plan)

def test_consecutive_after(self, receiver):
"""Consecutive after migrations are ok."""
Expand Down