Skip to content

Commit

Permalink
Update hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Jun 20, 2024
1 parent f8399e7 commit 3bb1e7f
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 115 deletions.
32 changes: 0 additions & 32 deletions .eslintrc.js

This file was deleted.

31 changes: 12 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: ".yarn/|yarn.lock|\\.min\\.(css|js)$"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-builtin-literals
Expand All @@ -14,33 +14,26 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.15.0
rev: 1.18.0
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]
- repo: https://github.com/MarcoGorelli/absolufy-imports
rev: v0.3.1
hooks:
- id: absolufy-imports
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.291"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.4.9"
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
- id: ruff-format
- repo: https://github.com/biomejs/pre-commit
rev: "v0.4.0"
hooks:
- id: prettier
args: [--list-different, --no-semi]
exclude: "^conf/|.*\\.html$"
- id: biome-check
additional_dependencies: ["@biomejs/[email protected]"]
args: [--unsafe]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.1.0
rev: 2.1.3
hooks:
- id: pyproject-fmt
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.14
rev: v0.18
hooks:
- id: validate-pyproject
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Change log
Next version
~~~~~~~~~~~~

- Updated the pre-commit configuration, switched to biomejs.


0.18 (2023-12-07)
~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ design not check whether thumbs exist.
Installation
============

Install from PyPI: ``pip install django-imagefield``.
Install from PyPI: ``pip install django-imagefield``.

Then add ``imagefield`` to your project's ``INSTALLED_APPS``::

Expand All @@ -91,7 +91,7 @@ Then add ``imagefield`` to your project's ``INSTALLED_APPS``::
"imagefield",
...
]


Usage
=====
Expand Down
38 changes: 38 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.1/schema.json",
"organizeImports": {
"enabled": false
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2
},
"javascript": {
"formatter": {
"semicolons": "asNeeded"
}
},
"css": {
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2
},
"linter": {
"enabled": true
}
},
"linter": {
"enabled": true,
"rules": {
"complexity": {
"noForEach": "off",
"useOptionalChain": "off"
},
"suspicious": {
"noAssignInExpressions": "off"
}
}
}
}
4 changes: 1 addition & 3 deletions imagefield/management/commands/process_imagefields.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ def _process_instance(self, instance, field, housekeep, **kwargs):
fieldfile.process(key, **kwargs)
except Exception as exc:
self.stderr.write(
"Error while processing {} ({}, #{}):\n{}\n".format(
fieldfile.name, field.field_label, instance.pk, exc
)
f"Error while processing {fieldfile.name} ({field.field_label}, #{instance.pk}):\n{exc}\n"
)
if housekeep == "blank-on-failure":
field.save_form_data(instance, "")
33 changes: 19 additions & 14 deletions imagefield/static/imagefield/ppoi.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,55 @@
;(function () {
;(() => {
function centerpointWidget() {
function movePoint(point, img, x, y) {
point.style.left = img.clientWidth * x + "px"
point.style.top = img.clientHeight * y + "px"
point.style.left = `${img.clientWidth * x}px`
point.style.top = `${img.clientHeight * y}px`
}

Array.prototype.slice
.call(document.querySelectorAll(".imagefield[data-ppoi-id]"))
.forEach(function (field) {
.forEach((field) => {
if (!field.dataset.ppoiId) return
const ppoiField = document.querySelector("#" + field.dataset.ppoiId)
const ppoiField = document.querySelector(`#${field.dataset.ppoiId}`)
if (!ppoiField) return

const point = document.createElement("div"),
img = field.querySelector("img")
const point = document.createElement("div")
const img = field.querySelector("img")
point.className = "imagefield-point opaque"
img.parentNode.appendChild(point)

setTimeout(function () {
setTimeout(() => {
point.className = "imagefield-point"
}, 1000)

const matches = ppoiField.value.match(/^([.0-9]+)x([.0-9]+)$/)
if (matches) {
movePoint(point, img, parseFloat(matches[1]), parseFloat(matches[2]))
movePoint(
point,
img,
Number.parseFloat(matches[1]),
Number.parseFloat(matches[2]),
)
} else {
movePoint(point, img, 0.5, 0.5)
}
})

document.body.addEventListener("click", function (e) {
document.body.addEventListener("click", (e) => {
if (
e.target &&
e.target.matches &&
e.target.matches("img.imagefield-preview-image")
) {
const field = e.target.closest(".imagefield[data-ppoi-id]")
if (!field.dataset.ppoiId) return
const ppoiField = document.querySelector("#" + field.dataset.ppoiId)
const ppoiField = document.querySelector(`#${field.dataset.ppoiId}`)
if (!ppoiField) return

const point = field.querySelector(".imagefield-point"),
img = e.target
const point = field.querySelector(".imagefield-point")
const img = e.target
const x = e.offsetX / img.clientWidth
const y = e.offsetY / img.clientHeight
ppoiField.value = x.toFixed(3) + "x" + y.toFixed(3)
ppoiField.value = `${x.toFixed(3)}x${y.toFixed(3)}`
movePoint(point, img, x, y)
}
})
Expand Down
95 changes: 50 additions & 45 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ requires = [
name = "django-imagefield"
description = "Image field for Django"
readme = "README.rst"
license = {text = "BSD-3-Clause"}
license = { text = "BSD-3-Clause" }
authors = [
{ name = "Matthias Kestenholz", email = "[email protected]" },
{ name = "Matthias Kestenholz", email = "[email protected]" },
]
requires-python = ">=3.8"
classifiers = [
Expand All @@ -34,80 +34,85 @@ dynamic = [
"version",
]
dependencies = [
"Pillow>=9",
"pillow>=9",
]
[project.optional-dependencies]
tests = [
optional-dependencies.tests = [
"coverage",
"Pillow",
"pillow",
]
[project.urls]
Homepage = "https://github.com/matthiask/django-imagefield/"
urls.Homepage = "https://github.com/matthiask/django-imagefield/"

[tool.hatch.build]
include = ["imagefield/"]
include = [
"imagefield/",
]

[tool.hatch.version]
path = "imagefield/__init__.py"

[tool.ruff]
extend-select = [
# pyflakes, pycodestyle
"F", "E", "W",
# mmcabe
"C90",
# isort
"I",
# pep8-naming
"N",
# pyupgrade
"UP",
# flake8-2020
"YTT",
# flake8-boolean-trap
"FBT",
target-version = "py38"

fix = true
show-fixes = true
lint.extend-select = [
# flake8-bugbear
"B",
# flake8-comprehensions
"C4",
# mmcabe
"C90",
# flake8-django
"DJ",
# flake8-implicit-string-concatenation
"ISC",
# flake8-pie
"PIE",
# flake8-simplify
"SIM",
"E",
# pyflakes, pycodestyle
"F",
# flake8-boolean-trap
"FBT",
# isort
"I",
# flake8-gettext
"INT",
# flake8-implicit-string-concatenation
"ISC",
# pep8-naming
"N",
# pygrep-hooks
"PGH",
# flake8-pie
"PIE",
# pylint
"PLC", "PLE", "PLW",
"PLC",
"PLE",
"PLW",
# unused noqa
"RUF100",
# flake8-simplify
"SIM",
# pyupgrade
"UP",
"W",
# flake8-2020
"YTT",
]
extend-ignore = [
lint.extend-ignore = [
# Allow zip() without strict=
"B905",
# No line length errors
"E501",
# Percent-formatting is fine
"UP031",
]
fix = true
show-fixes = true
target-version = "py38"

[tool.ruff.isort]
combine-as-imports = true
lines-after-imports = 2

[tool.ruff.mccabe]
max-complexity = 15

[tool.ruff.per-file-ignores]
"*/migrat*/*" = [
lint.per-file-ignores."*/migrat*/*" = [
# Allow using PascalCase model names in migrations
"N806",
# Ignore the fact that migration files are invalid module names
"N999",
]
lint.per-file-ignores."tests/*" = [
# Who cares about __str__ in the test suite
"DJ008",
]
lint.isort.combine-as-imports = true
lint.isort.lines-after-imports = 2
lint.mccabe.max-complexity = 15

0 comments on commit 3bb1e7f

Please sign in to comment.