Replace black/isort with ruff (#188)

* Replace black/isort with ruff

* fix typo
This commit is contained in:
Stan Triepels
2024-05-11 03:04:32 +02:00
committed by GitHub
parent 1d1d0a9aa5
commit ad4d24e17c
35 changed files with 150 additions and 234 deletions
+1
View File
@@ -1,4 +1,5 @@
"""Admin module for Django."""
from django.contrib import admin
from django.db.models.expressions import OuterRef, Subquery
from django.urls import reverse
+1 -1
View File
@@ -182,7 +182,7 @@ def get_broker(list_key: str = None) -> Broker:
return ironmq.IronMQBroker(list_key=list_key)
# SQS
elif type(Conf.SQS) == dict:
elif isinstance(Conf.SQS, dict):
from django_q.brokers import aws_sqs
return aws_sqs.Sqs(list_key=list_key)
-1
View File
@@ -263,7 +263,6 @@ if not logger.hasHandlers():
# Error Reporting Interface
class ErrorReporter:
# initialize with iterator of reporters (better name, targets?)
def __init__(self, reporters):
self.targets = [target for target in reporters]
+8 -3
View File
@@ -2,17 +2,22 @@ import datetime
import time
import zlib
import django
from django.core.signing import BadSignature, JSONSerializer, SignatureExpired
from django.core.signing import (
BadSignature,
JSONSerializer,
SignatureExpired,
b64_decode,
dumps,
)
from django.core.signing import Signer as Sgnr
from django.core.signing import TimestampSigner as TsS
from django.core.signing import b64_decode, dumps
try:
from django.core.signing import b62_decode
except ImportError:
# fallback for django 3.x
from django.utils.baseconv import base62
b62_decode = base62.decode
from django.utils.crypto import constant_time_compare
+1 -4
View File
@@ -4,6 +4,7 @@ humanhash: Human-readable representations of digests.
The simplest ways to use this module are the :func:`humanize` and :func:`uuid`
functions. For tighter control over the output, see :class:`HumanHasher`.
"""
import operator
import uuid as uuidlib
from argparse import ArgumentError
@@ -270,7 +271,6 @@ DEFAULT_WORDLIST = (
class HumanHasher:
"""
Transforms hex digests to human-readable strings.
@@ -290,7 +290,6 @@ class HumanHasher:
self.wordlist = wordlist
def humanize(self, hexdigest, words=4, separator="-"):
"""
Humanize a given hexadecimal digest.
@@ -314,7 +313,6 @@ class HumanHasher:
@staticmethod
def compress(bytes, target):
"""
Compress a list of byte values to a fixed target length.
@@ -353,7 +351,6 @@ class HumanHasher:
return checksums
def uuid(self, **params):
"""
Generate a UUID with a human-readable representation.
-1
View File
@@ -4,7 +4,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = []
operations = [
@@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0001_initial"),
]
@@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0002_auto_20150630_1624"),
]
@@ -2,7 +2,6 @@ from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("django_q", "0003_auto_20150708_1326"),
]
@@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0004_auto_20150710_1043"),
]
@@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0005_auto_20150718_1506"),
]
-1
View File
@@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0006_auto_20150805_1817"),
]
@@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0007_ormq"),
]
@@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0008_auto_20160224_1026"),
]
@@ -3,7 +3,6 @@ from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("django_q", "0009_auto_20171009_0915"),
]
@@ -4,7 +4,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0010_auto_20200610_0856"),
]
@@ -6,7 +6,6 @@ import django_q.models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0011_auto_20200628_1055"),
]
@@ -4,7 +4,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0012_auto_20200702_1608"),
]
@@ -4,7 +4,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0013_task_attempt_count"),
]
@@ -4,7 +4,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0014_schedule_cluster"),
]
@@ -6,7 +6,6 @@ import django_q.models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0015_alter_schedule_schedule_type"),
]
@@ -4,7 +4,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("django_q", "0016_schedule_intended_date_kwarg"),
]
+1 -2
View File
@@ -10,7 +10,6 @@ from django.urls import reverse
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.html import format_html
from django.utils.timezone import is_aware
from django.utils.translation import gettext_lazy as _
# External
@@ -18,7 +17,7 @@ from picklefield import PickledObjectField
from picklefield.fields import dbsafe_decode
# Local
from django_q.conf import Conf, croniter
from django_q.conf import croniter
from django_q.signing import SignedPackage
from django_q.utils import add_months, add_years, localtime
+2 -5
View File
@@ -2,8 +2,8 @@ from multiprocessing.process import current_process
from multiprocessing.queues import Queue
from django import core, db
from django.utils.translation import gettext_lazy as _
from django.apps.registry import apps
from django.utils.translation import gettext_lazy as _
try:
apps.check_apps_ready()
@@ -145,10 +145,7 @@ def save_task(task, broker: Broker):
attempt_count=1,
)
if (
Conf.MAX_ATTEMPTS > 0
and task_obj.attempt_count >= Conf.MAX_ATTEMPTS
):
if Conf.MAX_ATTEMPTS > 0 and task_obj.attempt_count >= Conf.MAX_ATTEMPTS:
broker.acknowledge(task["ack_id"])
except Exception:
+1 -3
View File
@@ -397,9 +397,7 @@ def memory(run_once=False, workers=False, broker=None):
2,
)
# memory available (MB)
memory_available = round(
psutil.virtual_memory().available / 1024**2, 2
)
memory_available = round(psutil.virtual_memory().available / 1024**2, 2)
if memory_available_percentage < MEMORY_AVAILABLE_LOWEST_PERCENTAGE:
MEMORY_AVAILABLE_LOWEST_PERCENTAGE = memory_available_percentage
MEMORY_AVAILABLE_LOWEST_PERCENTAGE_AT = timezone.now()
+4 -4
View File
@@ -4,8 +4,8 @@ from multiprocessing.queues import Queue
from time import sleep
from django import core
from django.utils.translation import gettext_lazy as _
from django.apps.registry import apps
from django.utils.translation import gettext_lazy as _
try:
apps.check_apps_ready()
@@ -58,9 +58,9 @@ def pusher(task_queue: Queue, event: Event, broker: Broker = None):
logger.exception("Failed to push task to queue")
broker.fail(ack_id)
continue
task[
"cluster"
] = Conf.CLUSTER_NAME # save actual cluster name to orm task table
task["cluster"] = (
Conf.CLUSTER_NAME
) # save actual cluster name to orm task table
task["ack_id"] = ack_id
task_queue.put(task)
logger.debug(
+1
View File
@@ -2,6 +2,7 @@
The code is derived from
https://github.com/althonos/pronto/commit/3384010dfb4fc7c66a219f59276adef3288a886b
"""
import multiprocessing
import multiprocessing.queues
import sys
+2 -3
View File
@@ -2,11 +2,10 @@ import ast
from multiprocessing.process import current_process
from django import core, db
from django.apps.registry import apps
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django.apps.registry import apps
try:
apps.check_apps_ready()
except core.exceptions.AppRegistryNotReady:
@@ -86,7 +85,7 @@ def scheduler(broker: Broker = None):
# Little Fix for already broken numbers
if s.repeats < -1:
s.repeats = -1
# Check if the value is not zero
if s.repeats > 0:
s.repeats -= 1
+1
View File
@@ -1,4 +1,5 @@
"""Package signing."""
import pickle
from django_q import core_signing as signing
+4 -5
View File
@@ -1,4 +1,5 @@
"""Provides task functionality."""
# Standard
from multiprocessing import Value
from time import sleep, time
@@ -569,7 +570,9 @@ class Chain:
A sequential chain of tasks
"""
def __init__(self, chain=None, group=None, cached=Conf.CACHED, sync=Conf.SYNC, broker=None):
def __init__(
self, chain=None, group=None, cached=Conf.CACHED, sync=Conf.SYNC, broker=None
):
self.chain = chain or []
self.group = group or ""
self.broker = broker or get_broker()
@@ -729,17 +732,14 @@ class AsyncTask:
return self.id
def result(self, wait=0):
if self.started:
return result(self.id, wait=wait, cached=self.cached)
def fetch(self, wait=0):
if self.started:
return fetch(self.id, wait=wait, cached=self.cached)
def result_group(self, failures=False, wait=0, count=None):
if self.started and self.group:
return result_group(
self.group,
@@ -750,7 +750,6 @@ class AsyncTask:
)
def fetch_group(self, failures=True, wait=0, count=None):
if self.started and self.group:
return fetch_group(
self.group,
+1 -1
View File
@@ -5,9 +5,9 @@ from multiprocessing.process import current_process
from multiprocessing.queues import Queue
from django import core
from django.apps.registry import apps
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django.apps.registry import apps
try:
apps.check_apps_ready()