diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index bdcd6df..6cbc765 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,13 +13,18 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13.0-rc.1"] - django-version: ["django==4.2.*", "django==5.0.*", "django==5.1.*", "django==5.2.*"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + django-version: ["django==4.2.*", "django==5.0.*", "django==5.1.*"] exclude: - - python-version: "3.12" - django-version: "django<4.2.8" - - python-version: "3.13.0-rc.1" - django-version: "django<5.2" + - python-version: "3.8" + django-version: "django==5.0.*" + - python-version: "3.8" + django-version: "django==5.1.*" + - python-version: "3.9" + django-version: "django==5.0.*" + - python-version: "3.9" + django-version: "django==5.1.*" + steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} @@ -29,10 +34,16 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements_test.txt + pip install ${{ matrix.django-version }} + echo ${{ matrix.django-version }} >> dj.txt + pip install -c dj.txt -r requirements_test.txt - name: Lint with ruff run: | # stop the build if there are Python syntax errors or undefined names make ruff-check - - name: Run Tox - run: tox + - name: MyPy + run: mypy django_mail_viewer + - name: Run Tests + run: | + coverage run --source django_mail_viewer runtests.py + coverage report diff --git a/Dockerfile b/Dockerfile index d8f625b..7f8be6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM python:3.8-bookworm AS dev +ARG PYTHON_VERSION=3.8 +ARG DEBIAN_DISTRO=bookworm +FROM python:${PYTHON_VERSION}-${DEBIAN_DISTRO} AS dev # Dockerfile for running a test django installation LABEL maintainer="Justin Michalicek " ENV PYTHONUNBUFFERED 1 diff --git a/django_mail_viewer/__init__.py b/django_mail_viewer/__init__.py index 04188a1..8a124bf 100644 --- a/django_mail_viewer/__init__.py +++ b/django_mail_viewer/__init__.py @@ -1 +1 @@ -__version__ = '2.2.0' +__version__ = "2.2.0" diff --git a/django_mail_viewer/backends/database/models.py b/django_mail_viewer/backends/database/models.py index 49afe3a..dfaaeb1 100644 --- a/django_mail_viewer/backends/database/models.py +++ b/django_mail_viewer/backends/database/models.py @@ -1,7 +1,7 @@ import email.message import email.utils import json -from typing import TYPE_CHECKING, Any, Dict, List, Union +from typing import Any, Dict, List, Union from django.db import models @@ -12,7 +12,7 @@ class AbstractBaseEmailMessage(models.Model): storage for the Message FileField. Once Django 3.1+ only is supported then a callable may be used rendering this not really necessary. - To customize, subclass this and add a `FileField()` named `serialized_message_file` with the storage you would + To customize, subclass this and add a `FileField()` named `file_attachment` with the storage you would like to use. """ @@ -30,17 +30,11 @@ class AbstractBaseEmailMessage(models.Model): created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) + file_attachment: models.FileField + class Meta: abstract = True - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - # methods here expect the concrete subclasses to implement the file_attachment field - # should only be necessary until django 2.2 support is dropped... I hope - if TYPE_CHECKING and not hasattr(self, "file_attachment"): - self.file_attachment = models.FileField(blank=True, default="", upload_to="mailviewer_attachments") - # I really only need/use get_filename(), get_content_type(), get_payload(), walk() # returns Any due to failobj def get(self, attr: str, failobj: Any = None) -> Any: diff --git a/pyproject.toml b/pyproject.toml index 82dcca0..6281801 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,11 @@ [tool.mypy] plugins = ["mypy_django_plugin.main"] +ignore_missing_imports = true # for some reason this is not following the ignore of the settings file... exclude = [ 'migrations', - 'test_project\/test_project\/settings\.py' + 'test_project\/test_project\/settings\.py', + 'docs', ] [tool.django-stubs] diff --git a/requirements_test.txt b/requirements_test.txt index 35d19b5..4bded55 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -4,8 +4,7 @@ flake8 pytest tox tox-gh-actions -django-stubs -mypy +django-stubs[compatible-mypy] typing-extensions black ruff diff --git a/test_project/__init__.py b/test_project/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 0af8cc6..0000000 --- a/tox.ini +++ /dev/null @@ -1,40 +0,0 @@ -[tox] -envlist = - {py38,py39,py310,311,312}-django-42 - {py310,311,312}-django-50 - {py310,311,312}-django-51 - {py310,311,312}-django-52 - stats - -[gh-actions] -python = - 3.8: py38 - 3.9: py39 - 3.10: py310 - 3.11: py311 - 3.11: py312 - -[testenv] -setenv = - PYTHONPATH = {toxinidir}:{toxinidir}/django_mail_viewer -commands = - coverage run --source django_mail_viewer runtests.py - mypy django_mail_viewer - -deps = - django-32: Django>=3.2,<3.3 - django-40: Django>=4.0,<4.1 - django-41: Django>=4.1,<4.2 - -r{toxinidir}/requirements_test.txt - -basepython = - py38: python3.8 - py39: python3.9 - py310: python3.10 - py311: python3.11 - py312: python3.12 - stats: python3.9 - -[testenv:stats] -commands= - coverage report