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

Add isort #474

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ jobs:
- uses: chartboost/ruff-action@v1
with:
version: 0.4.8
args: 'format --check'
args: 'format --check'

ruff-lint:
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
with:
version: 0.4.8

build:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion post_office/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ast import literal_eval
from os.path import dirname, join
from os.path import dirname
from os.path import join

with open(join(dirname(__file__), 'version.txt')) as fh:
VERSION = literal_eval(fh.read())
Expand Down
19 changes: 14 additions & 5 deletions post_office/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@

from django import forms
from django.conf import settings
from django.contrib import admin, messages
from django.contrib import admin
from django.contrib import messages
from django.core.exceptions import ValidationError
from django.core.mail.message import SafeMIMEText
from django.db import models
from django.forms import BaseInlineFormSet
from django.forms.widgets import TextInput
from django.http.response import HttpResponse, HttpResponseNotFound, HttpResponseRedirect
from django.template import Context, Template
from django.urls import re_path, reverse
from django.http.response import HttpResponse
from django.http.response import HttpResponseNotFound
from django.http.response import HttpResponseRedirect
from django.template import Context
from django.template import Template
from django.urls import re_path
from django.urls import reverse
from django.utils.html import format_html
from django.utils.text import Truncator
from django.utils.translation import gettext_lazy as _

from .fields import CommaSeparatedEmailField
from .models import STATUS, Attachment, Email, EmailTemplate, Log
from .models import STATUS
from .models import Attachment
from .models import Email
from .models import EmailTemplate
from .models import Log
from .sanitizer import clean_html


Expand Down
7 changes: 5 additions & 2 deletions post_office/backends.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from collections import OrderedDict
from email.mime.base import MIMEBase

from django.core.files.base import ContentFile
from django.core.mail.backends.base import BaseEmailBackend

from .settings import get_default_priority


Expand All @@ -18,9 +20,10 @@ def send_messages(self, email_messages):
email messages sent.
"""
from .mail import create
from .models import STATUS, Email
from .utils import create_attachments
from .models import STATUS
from .models import Email
from .signals import email_queued
from .utils import create_attachments

if not email_messages:
return
Expand Down
54 changes: 29 additions & 25 deletions post_office/mail.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
from email.utils import make_msgid
from multiprocessing import Pool
from multiprocessing.dummy import Pool as ThreadPool

from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import connection as db_connection
from django.db.models import Q
from django.template import Context, Template
from django.template import Context
from django.template import Template
from django.utils import timezone
from email.utils import make_msgid
from multiprocessing import Pool
from multiprocessing.dummy import Pool as ThreadPool

from .connections import connections
from .lockfile import default_lockfile, FileLock, FileLocked
from .lockfile import FileLock
from .lockfile import FileLocked
from .lockfile import default_lockfile
from .logutils import setup_loghandlers
from .models import Email, EmailTemplate, Log, PRIORITY, STATUS
from .settings import (
get_available_backends,
get_batch_delivery_timeout,
get_batch_size,
get_log_level,
get_max_retries,
get_message_id_enabled,
get_message_id_fqdn,
get_retry_timedelta,
get_sending_order,
get_threads_per_process,
)
from .models import PRIORITY
from .models import STATUS
from .models import Email
from .models import EmailTemplate
from .models import Log
from .settings import get_available_backends
from .settings import get_batch_delivery_timeout
from .settings import get_batch_size
from .settings import get_log_level
from .settings import get_max_retries
from .settings import get_message_id_enabled
from .settings import get_message_id_fqdn
from .settings import get_retry_timedelta
from .settings import get_sending_order
from .settings import get_threads_per_process
from .signals import email_queued
from .utils import (
create_attachments,
get_email_template,
parse_emails,
parse_priority,
split_emails,
)
from .utils import create_attachments
from .utils import get_email_template
from .utils import parse_emails
from .utils import parse_priority
from .utils import split_emails

logger = setup_loghandlers('INFO')

Expand Down
5 changes: 3 additions & 2 deletions post_office/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.db import models, migrations
from django.db import migrations
from django.db import models

import post_office.fields
import post_office.validators
import post_office.models
import post_office.validators


class Migration(migrations.Migration):
Expand Down
6 changes: 4 additions & 2 deletions post_office/migrations/0002_add_i18n_and_backend_alias.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.db import models, migrations
import post_office.validators
from django.db import migrations
from django.db import models

import post_office.fields
import post_office.validators


class Migration(migrations.Migration):
Expand Down
3 changes: 2 additions & 1 deletion post_office/migrations/0003_longer_subject.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 1.9 on 2016-02-04 08:08
from django.db import migrations, models
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):
Expand Down
3 changes: 2 additions & 1 deletion post_office/migrations/0004_auto_20160607_0901.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 1.9.6 on 2016-06-07 07:01
from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations
from django.db import models

import post_office.models

Expand Down
3 changes: 2 additions & 1 deletion post_office/migrations/0006_attachment_mimetype.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models, migrations
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):
Expand Down
3 changes: 2 additions & 1 deletion post_office/migrations/0008_attachment_headers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 1.11.16 on 2018-11-30 08:54
from django.db import migrations, models
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):
Expand Down
3 changes: 2 additions & 1 deletion post_office/migrations/0009_requeued_mode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 2.2.11 on 2020-05-10 08:59

from django.db import migrations, models
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):
Expand Down
7 changes: 5 additions & 2 deletions post_office/migrations/0010_message_id.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import random
from django.db import migrations, models

from django.db import migrations
from django.db import models

from post_office.models import STATUS
from post_office.settings import get_message_id_enabled, get_message_id_fqdn
from post_office.settings import get_message_id_enabled
from post_office.settings import get_message_id_fqdn


def forwards(apps, schema_editor):
Expand Down
3 changes: 2 additions & 1 deletion post_office/migrations/0011_models_help_text.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 3.0.10 on 2020-11-02 22:48

from django.db import migrations, models
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):
Expand Down
20 changes: 12 additions & 8 deletions post_office/models.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import os

from collections import namedtuple
from uuid import uuid4
from email.mime.nonmultipart import MIMENonMultipart
from uuid import uuid4

from django.core.exceptions import ValidationError
from django.core.mail import EmailMessage, EmailMultiAlternatives
from django.core.mail import EmailMessage
from django.core.mail import EmailMultiAlternatives
from django.db import models
from django.utils.encoding import smart_str
from django.utils.translation import pgettext_lazy, gettext_lazy as _
from django.utils import timezone
from django.utils.encoding import smart_str
from django.utils.translation import gettext_lazy as _
from django.utils.translation import pgettext_lazy

from post_office import cache
from post_office.fields import CommaSeparatedEmailField

from .connections import connections
from .logutils import setup_loghandlers
from .settings import context_field_class, get_log_level, get_template_engine, get_override_recipients
from .validators import validate_email_with_name, validate_template_syntax

from .settings import context_field_class
from .settings import get_log_level
from .settings import get_override_recipients
from .settings import get_template_engine
from .validators import validate_email_with_name
from .validators import validate_template_syntax

logger = setup_loghandlers('INFO')

Expand Down
3 changes: 2 additions & 1 deletion post_office/sanitizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.utils.html import mark_safe, format_html
from django.utils.html import format_html
from django.utils.html import mark_safe
from django.utils.translation import gettext_lazy

try:
Expand Down
4 changes: 1 addition & 3 deletions post_office/settings.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import datetime
import warnings

from django.conf import settings
from django.core.cache import caches
from django.core.cache.backends.base import InvalidCacheBackendError
from django.core.mail.utils import DNS_NAME
from django.template import engines as template_engines

from django.utils.module_loading import import_string

import datetime


def get_backend(alias='default'):
return get_available_backends()[alias]
Expand Down
3 changes: 2 additions & 1 deletion post_office/template/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.template.loader import get_template, select_template
from django.template.loader import get_template
from django.template.loader import select_template


def render_to_string(template_name, context=None, request=None, using=None):
Expand Down
4 changes: 3 additions & 1 deletion post_office/template/backends/post_office.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from django.core.mail import EmailMultiAlternatives
from django.template import TemplateDoesNotExist
from django.template.backends.base import BaseEngine
from django.template.backends.django import Template as DjangoTemplate, reraise, get_installed_libraries
from django.template.backends.django import Template as DjangoTemplate
from django.template.backends.django import get_installed_libraries
from django.template.backends.django import reraise
from django.template.engine import Engine


Expand Down
2 changes: 1 addition & 1 deletion post_office/templatetags/post_office.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from email.mime.image import MIMEImage
import hashlib
import os
from email.mime.image import MIMEImage

from django import template
from django.conf import settings
Expand Down
2 changes: 1 addition & 1 deletion post_office/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .test_backends import BackendTest
from .test_cache import CacheTest
from .test_commands import CommandTest
from .test_lockfile import LockTest
from .test_mail import MailTest
from .test_models import ModelTest
from .test_utils import UtilsTest
from .test_cache import CacheTest
from .test_views import AdminViewTest
8 changes: 6 additions & 2 deletions post_office/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

from django.conf import settings
from django.core.files.images import File
from django.core.mail import EmailMultiAlternatives, send_mail, EmailMessage
from django.core.mail import EmailMessage
from django.core.mail import EmailMultiAlternatives
from django.core.mail import send_mail
from django.core.mail.backends.base import BaseEmailBackend
from django.test import TestCase
from django.test.utils import override_settings

from ..models import Email, STATUS, PRIORITY
from ..models import PRIORITY
from ..models import STATUS
from ..models import Email
from ..settings import get_backend


Expand All @@ -20,7 +24,7 @@
"""

def send_messages(self, email_messages):
raise Exception('Fake Error')

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.9/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.9/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.9/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.9/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.9/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.9/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.9/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.10/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.11/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django4.2

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django5.0

Fake Error

Check failure on line 27 in post_office/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / Python3.12/Django5.0

Fake Error


class BackendTest(TestCase):
Expand Down
1 change: 1 addition & 0 deletions post_office/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.test import TestCase

from post_office import cache

from ..settings import get_cache_backend


Expand Down
4 changes: 3 additions & 1 deletion post_office/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from django.test.utils import override_settings
from django.utils.timezone import now

from ..models import Attachment, Email, STATUS
from ..models import STATUS
from ..models import Attachment
from ..models import Email


class CommandTest(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion post_office/tests/test_connections.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.core.mail import backends
from django.test import TestCase

from .test_backends import ErrorRaisingBackend
from ..connections import connections
from .test_backends import ErrorRaisingBackend


class ConnectionTest(TestCase):
Expand Down
6 changes: 3 additions & 3 deletions post_office/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.forms import formset_factory
from django.test import TestCase, Client
from django.contrib.auth import get_user_model
from django.forms import formset_factory
from django.test import Client
from django.test import TestCase
from django.urls import reverse

from post_office.admin import EmailTemplateAdminForm


User = get_user_model()


Expand Down
Loading