Skip to content

Commit

Permalink
Merge pull request #4 from bernhard-hagmann/precommit_ruff
Browse files Browse the repository at this point in the history
SIANXKE-395: Update pre-commit configuration and re-format all files
  • Loading branch information
nezhar authored Nov 6, 2024
2 parents aa8cf70 + 9b75ab4 commit f87eae8
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 44 deletions.
31 changes: 23 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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+
- 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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
SOFTWARE.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

```
Expand All @@ -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.:

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion django_generic_contact/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion django_generic_contact/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
2 changes: 1 addition & 1 deletion django_generic_contact/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
4 changes: 3 additions & 1 deletion django_generic_contact/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "../../testapp/db.sqlite3"),
}
},
}

# Password validation
Expand Down
16 changes: 1 addition & 15 deletions tests/manage.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 3 additions & 3 deletions tests/testapp/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_successful_jsonschema_validation(self):
{
"email": "[email protected]",
"not_validated_phone": "+431234567",
}
},
)

def test_failed_jsonschema_validation_invalid_email(self):
Expand All @@ -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):
Expand All @@ -68,5 +68,5 @@ def test_failed_jsonschema_validation_additional_fields(self):
{
"email": "[email protected]",
"phone": "+431234567",
}
},
)

0 comments on commit f87eae8

Please sign in to comment.