From 9b75ab4736804cc065eca11e30bca2e14083f14f Mon Sep 17 00:00:00 2001 From: Bernhard Hagmann Date: Fri, 11 Oct 2024 17:23:08 +0200 Subject: [PATCH] SIANXKE-395: Update pre-commit configuration and re-format all files --- .pre-commit-config.yaml | 31 ++++++++++++++----- LICENSE | 2 +- README.md | 8 ++--- django_generic_contact/admin.py | 2 +- .../migrations/0001_initial.py | 3 +- django_generic_contact/utils.py | 2 +- django_generic_contact/validators.py | 4 ++- requirements.txt | 16 +++++----- tests/core/settings.py | 2 +- tests/manage.py | 16 +--------- tests/testapp/tests/test_model.py | 6 ++-- 11 files changed, 48 insertions(+), 44 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 53b6220..4ce655d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,27 @@ repos: - - repo: https://github.com/pycqa/isort - rev: 5.12.0 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 hooks: - - id: isort - args: [ "--profile", "black", "--filter-files" ] + - id: check-merge-conflict + - id: end-of-file-fixer + - id: requirements-txt-fixer + - id: trailing-whitespace + args: ["--markdown-linebreak-ext=md"] - - repo: https://github.com/psf/black - rev: 23.10.0 # Replace by any tag/version: https://github.com/psf/black/tags + - repo: https://github.com/asottile/pyupgrade + rev: v3.17.0 hooks: - - id: black - language_version: python3 # Should be a command that runs python3.6.2+ \ No newline at end of file + - id: pyupgrade + args: ["--py39-plus"] + + - repo: https://github.com/asottile/add-trailing-comma + rev: v3.1.0 + hooks: + - id: add-trailing-comma + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.9 + hooks: + - id: ruff + args: [ --fix ] + - id: ruff-format diff --git a/LICENSE b/LICENSE index cd0bfbf..fb4b56a 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/README.md b/README.md index 0e3d620..4c8b491 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ INSTALLED_APPS = [ ### Usage -The package provides you with a `Contact` model which expects `data` (dict) and the `name` of the requester, +The package provides you with a `Contact` model which expects `data` (dict) and the `name` of the requester, an optional `message` can be added: ``` @@ -44,7 +44,7 @@ contact = Contact.objects.create( #### JSON Schema validation -The contents of `data` will be validated against a [json schema](https://json-schema.org/) defined in your project's +The contents of `data` will be validated against a [json schema](https://json-schema.org/) defined in your project's `settings.py` (if provided). If needed you can define `GENERIC_CONTACT_DATA_SCHEMA` to check all relevant input according to the expected structure, e.g.: @@ -77,14 +77,14 @@ class CustomContact(GenericContact): See folder [tests/](tests/). The provided tests cover these criteria: * success: - * Contact model instance creation + * Contact model instance creation * project's jsonschema validation * failure: * project's jsonschema validation * exemplary custom jsonschema validation Follow below instructions to run the tests. -You may exchange the installed Django and DRF versions according to your requirements. +You may exchange the installed Django and DRF versions according to your requirements. :warning: Depending on your local environment settings you might need to explicitly call `python3` instead of `python`. ```bash # install dependencies diff --git a/django_generic_contact/admin.py b/django_generic_contact/admin.py index 62dfdd4..976ce28 100644 --- a/django_generic_contact/admin.py +++ b/django_generic_contact/admin.py @@ -7,7 +7,7 @@ class ContactAdminForm(forms.ModelForm): def __init__(self, *args, **kwargs): - super(ContactAdminForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.fields["data"].help_text = get_help_text() self.fields["data"].validators = get_validators() diff --git a/django_generic_contact/migrations/0001_initial.py b/django_generic_contact/migrations/0001_initial.py index f733f4e..e4aa0f6 100644 --- a/django_generic_contact/migrations/0001_initial.py +++ b/django_generic_contact/migrations/0001_initial.py @@ -24,7 +24,8 @@ class Migration(migrations.Migration): ( "creation_date", models.DateTimeField( - auto_now_add=True, verbose_name="Creation date" + auto_now_add=True, + verbose_name="Creation date", ), ), ("data", models.JSONField(default=dict, verbose_name="meta data")), diff --git a/django_generic_contact/utils.py b/django_generic_contact/utils.py index e9a5019..851a790 100644 --- a/django_generic_contact/utils.py +++ b/django_generic_contact/utils.py @@ -6,7 +6,7 @@ def get_help_text(): return _("Meta data according to Schema: {schema}").format( - schema=GENERIC_CONTACT_DATA_SCHEMA + schema=GENERIC_CONTACT_DATA_SCHEMA, ) diff --git a/django_generic_contact/validators.py b/django_generic_contact/validators.py index c672124..c1079ba 100644 --- a/django_generic_contact/validators.py +++ b/django_generic_contact/validators.py @@ -8,7 +8,9 @@ class JSONSchemaValidator(BaseValidator): def compare(self, value, schema): try: jsonschema.validate( - value, schema, format_checker=Draft202012Validator.FORMAT_CHECKER + value, + schema, + format_checker=Draft202012Validator.FORMAT_CHECKER, ) except jsonschema.exceptions.ValidationError as e: raise ValidationError(str(e)) diff --git a/requirements.txt b/requirements.txt index 202551f..f56ae21 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,15 @@ # Package and package dependencies -e . - -# Development dependencies -setuptools>=75.1.0,<76.2 -wheel>=0.44.0,<0.45 -twine>=5.1.1,<5.2 coverage>=7.6.2,<7.7 -# Linters and formatters -pre-commit>=4.0.1,<4.2 - # TestApp dependencies django>=4.2,<5.2 jsonschema>=4.23.0,<4.24 + +# Linters and formatters +pre-commit>=4.0.1,<4.2 + +# Development dependencies +setuptools>=75.1.0,<76.2 +twine>=5.1.1,<5.2 +wheel>=0.44.0,<0.45 diff --git a/tests/core/settings.py b/tests/core/settings.py index bb76301..c66b34a 100644 --- a/tests/core/settings.py +++ b/tests/core/settings.py @@ -67,7 +67,7 @@ "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": os.path.join(BASE_DIR, "../../testapp/db.sqlite3"), - } + }, } # Password validation diff --git a/tests/manage.py b/tests/manage.py index c0b8614..d129215 100644 --- a/tests/manage.py +++ b/tests/manage.py @@ -1,22 +1,8 @@ #!/usr/bin/env python import os import sys +from django.core.management import execute_from_command_line if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings") - try: - from django.core.management import execute_from_command_line - except ImportError: - # The above import may fail for some other reason. Ensure that the - # issue is really that Django is missing to avoid masking other - # exceptions on Python 2. - try: - import django - except ImportError: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) - raise execute_from_command_line(sys.argv) diff --git a/tests/testapp/tests/test_model.py b/tests/testapp/tests/test_model.py index ea9d7d6..4c7d828 100644 --- a/tests/testapp/tests/test_model.py +++ b/tests/testapp/tests/test_model.py @@ -26,7 +26,7 @@ def test_successful_jsonschema_validation(self): { "email": "mr@tester.com", "not_validated_phone": "+431234567", - } + }, ) def test_failed_jsonschema_validation_invalid_email(self): @@ -43,7 +43,7 @@ def test_failed_jsonschema_validation_invalid_email(self): { "email": "invalid_email", "not_validated_phone": "+431234567", - } + }, ) def test_failed_jsonschema_validation_additional_fields(self): @@ -68,5 +68,5 @@ def test_failed_jsonschema_validation_additional_fields(self): { "email": "mr@tester.com", "phone": "+431234567", - } + }, )