From 8cb04450fd88269580a50ebf857c0e229811b618 Mon Sep 17 00:00:00 2001 From: zerolab Date: Fri, 6 Dec 2024 11:08:03 +0000 Subject: [PATCH 1/4] Bump pre-commit/ruff versions --- .github/workflows/ruff.yml | 4 +++- .pre-commit-config.yaml | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index a6901ab..7e47f25 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -14,8 +14,10 @@ jobs: steps: - uses: actions/checkout@v4 + with: + persist-credentials: false - - run: python -Im pip install --user ruff==0.5.4 + - run: python -Im pip install --user ruff==0.8.2 - name: Run ruff working-directory: ./src diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 65070f0..42a44fa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,11 +3,11 @@ ci: autoupdate_schedule: 'quarterly' default_language_version: - python: python3.11 + python: python3.13 repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: check-added-large-files - id: check-case-conflict @@ -19,7 +19,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.5.4' + rev: 'v0.8.2' # keep in sync with .github/workflows/ruff.yml hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 5c55a85e63dda0365fe8e2641f85bb1040e4e7d1 Mon Sep 17 00:00:00 2001 From: zerolab Date: Fri, 6 Dec 2024 11:09:12 +0000 Subject: [PATCH 2/4] Tidy up tox config --- .github/workflows/publish.yml | 2 +- .github/workflows/test.yml | 4 +++- pyproject.toml | 4 ++-- tox.ini | 10 +++++----- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4e08246..1d62f3c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: '3.13' cache: "pip" cache-dependency-path: "**/pyproject.toml" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4631604..2a62d9c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ env: PIP_DISABLE_PIP_VERSION_CHECK: "1" PIP_NO_PYTHON_VERSION_WARNING: "1" # Keep in sync with .pre-commit-config.yaml/default_language_version/python. - PYTHON_LATEST: "3.11" + PYTHON_LATEST: "3.13" jobs: tests: @@ -43,6 +43,8 @@ jobs: pypi.org:443 api.github.com:443 - uses: actions/checkout@v4 + with: + persist-credentials: false - name: 🐍 Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: diff --git a/pyproject.toml b/pyproject.toml index 28234e8..1fd8544 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,10 +33,10 @@ dependencies = [ [project.optional-dependencies] testing = [ - "coverage>=7.4.0", + "coverage>=7.6.0", ] linting = [ - "pre-commit>=3.6.0", + "pre-commit>=5.0.0", ] [project.urls] diff --git a/tox.ini b/tox.ini index 1963fb6..bf2e6f5 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -min_version = 4.11 +min_version = 4.22 env_list = py{39,310,311}-dj42-wagtail{52} @@ -51,7 +51,7 @@ commands = python -Im coverage run runtests.py {posargs: -v 2} [testenv:coverage-report] -base_python = python3.11 +base_python = python3.12 package = skip deps = coverage>=7.0,<8.0 @@ -61,17 +61,17 @@ commands = [testenv:wagtailmain] description = Test with latest Wagtail main branch -base_python = python3.12 +base_python = python3.13 deps = wagtailmain: git+https://github.com/wagtail/wagtail.git@main#egg=Wagtail [testenv:interactive] package = editable description = An interactive environment for local testing purposes -base_python = python3.11 +base_python = python3.13 deps = - wagtail>=5.2 + wagtail>=6.3 commands_pre = python {toxinidir}/manage.py makemigrations From fe0af27940ffaf6e11de63bc43e2ab63c78a715c Mon Sep 17 00:00:00 2001 From: zerolab Date: Fri, 6 Dec 2024 11:10:04 +0000 Subject: [PATCH 3/4] Bump action versions and harden checkout action --- .github/workflows/nightly-tests.yml | 8 +++++--- .github/workflows/publish.yml | 16 ++++++++++++++-- .github/workflows/test.yml | 18 ++++++++++-------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/.github/workflows/nightly-tests.yml b/.github/workflows/nightly-tests.yml index 07f1660..c986daf 100644 --- a/.github/workflows/nightly-tests.yml +++ b/.github/workflows/nightly-tests.yml @@ -24,14 +24,16 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python 3.11 + with: + persist-credentials: false + - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.11" + python-version: "3.13" - name: Install dependencies run: | python -m pip install --upgrade pip - pip install "psycopg2>=2.6" + pip install "psycopg2>=2.9" pip install "git+https://github.com/wagtail/wagtail.git@main#egg=wagtail" pip install -e .[testing] - name: Test diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1d62f3c..0c3ab1d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,8 +11,20 @@ jobs: build: runs-on: ubuntu-latest steps: + - name: 🔒 Harden Runner + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 + with: + disable-sudo: true + egress-policy: block + allowed-endpoints: > + files.pythonhosted.org:443 + github.com:443 + pypi.org:443 + api.github.com:443 + - uses: actions/checkout@v4 with: + persist-credentials: false fetch-depth: 0 - uses: actions/setup-python@v5 @@ -28,7 +40,7 @@ jobs: - name: 🏗️ Build run: python -Im flit build - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: path: ./dist @@ -43,7 +55,7 @@ jobs: # Mandatory for trusted publishing id-token: write steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 - name: 🚀 Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a62d9c..17da297 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ env: PIP_DISABLE_PIP_VERSION_CHECK: "1" PIP_NO_PYTHON_VERSION_WARNING: "1" # Keep in sync with .pre-commit-config.yaml/default_language_version/python. - PYTHON_LATEST: "3.13" + PYTHON_LATEST: "3.12" # because harden runner fails on the 3.13 download jobs: tests: @@ -32,7 +32,7 @@ jobs: steps: - name: 🔒 Harden Runner - uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: disable-sudo: true egress-policy: block @@ -62,9 +62,9 @@ jobs: run: tox --installpkg ./dist/*.whl - name: ⬆️ Upload coverage data - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: coverage-data + name: coverage-data-${{ matrix.python-version }} path: .coverage.* if-no-files-found: ignore include-hidden-files: true @@ -76,7 +76,7 @@ jobs: steps: - name: 🔒 Harden Runner - uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: disable-sudo: true egress-policy: block @@ -87,6 +87,7 @@ jobs: api.github.com:443 - uses: actions/checkout@v4 with: + persist-credentials: false fetch-depth: 0 - uses: actions/setup-python@v5 with: @@ -96,9 +97,10 @@ jobs: - run: python -Im pip install --upgrade coverage - name: Download coverage data - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: - name: coverage-data + pattern: coverage-data-* + merge-multiple: true - name: + Combine coverage run: | @@ -108,7 +110,7 @@ jobs: echo "## Coverage summary" >> $GITHUB_STEP_SUMMARY python -Im coverage report --format=markdown >> $GITHUB_STEP_SUMMARY - name: 📈 Upload HTML report if check failed. - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: html-report path: htmlcov From d5bd74055d38bf463899f118781becfefe84161a Mon Sep 17 00:00:00 2001 From: zerolab Date: Fri, 6 Dec 2024 11:16:46 +0000 Subject: [PATCH 4/4] Lint --- src/wagtailmedia/blocks.py | 4 ++-- src/wagtailmedia/wagtail_hooks.py | 2 +- tests/test_admin.py | 1 + tests/test_api.py | 4 ++-- tests/test_blocks.py | 1 + tests/test_compare.py | 4 ++-- tests/test_edit_handlers.py | 4 ++-- tests/test_form_override.py | 4 ++-- tests/test_models.py | 1 + tests/test_permissions.py | 1 + tests/test_settings.py | 1 + tests/test_tags.py | 1 + tests/test_utils.py | 1 + tests/test_views.py | 2 +- tests/test_widgets.py | 1 + tests/testapp/forms.py | 1 + tests/testapp/migrations/0001_initial.py | 3 ++- tests/testapp/models.py | 1 + tests/urls.py | 1 + tests/utils.py | 1 + 20 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/wagtailmedia/blocks.py b/src/wagtailmedia/blocks.py index 8777649..1e85a27 100644 --- a/src/wagtailmedia/blocks.py +++ b/src/wagtailmedia/blocks.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Type +from typing import TYPE_CHECKING from django.forms import ModelChoiceField from django.template.loader import render_to_string @@ -52,7 +52,7 @@ def render_basic(self, value, context=None): f"You need to implement {self.__class__.__name__}.render_basic" ) - def get_comparison_class(self) -> Type["MediaChooserBlockComparison"]: + def get_comparison_class(self) -> type["MediaChooserBlockComparison"]: return MediaChooserBlockComparison diff --git a/src/wagtailmedia/wagtail_hooks.py b/src/wagtailmedia/wagtail_hooks.py index 47c6e41..e54a003 100644 --- a/src/wagtailmedia/wagtail_hooks.py +++ b/src/wagtailmedia/wagtail_hooks.py @@ -95,7 +95,7 @@ def register_media_permissions_panel(): def describe_collection_media(collection): media_count = get_media_model().objects.filter(collection=collection).count() if media_count: - url = reverse("wagtailmedia:index") + ("?collection_id=%d" % collection.id) + url = reverse("wagtailmedia:index") + f"?collection_id={collection.id}" return { "count": media_count, "count_text": ngettext( diff --git a/tests/test_admin.py b/tests/test_admin.py index 69e0501..7297b9f 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -2,6 +2,7 @@ from django.urls import reverse from wagtail.models import Page from wagtail.test.utils import WagtailTestUtils + from wagtailmedia.blocks import AbstractMediaChooserBlock diff --git a/tests/test_api.py b/tests/test_api.py index 3f19e32..0b3bb78 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -2,6 +2,7 @@ from django.test import TestCase, override_settings from django.urls import reverse + from wagtailmedia.models import get_media_model from .utils import create_audio, create_video @@ -66,8 +67,7 @@ def test_basic(self): # Check detail_url self.assertEqual( - item["meta"]["detail_url"], - "http://localhost/api/media/%d/" % item["id"], + item["meta"]["detail_url"], f"http://localhost/api/media/{item['id']}/" ) media = Media.objects.get(pk=item["id"]) diff --git a/tests/test_blocks.py b/tests/test_blocks.py index 02fc507..010ea34 100644 --- a/tests/test_blocks.py +++ b/tests/test_blocks.py @@ -1,6 +1,7 @@ from django.core.files.base import ContentFile from django.test import TestCase from django.urls import reverse + from wagtailmedia.blocks import ( AbstractMediaChooserBlock, AudioChooserBlock, diff --git a/tests/test_compare.py b/tests/test_compare.py index c10473d..0435f58 100644 --- a/tests/test_compare.py +++ b/tests/test_compare.py @@ -1,5 +1,7 @@ from django.test import TestCase from django.utils.safestring import SafeString + +from tests.testapp.models import BlogStreamPage from wagtailmedia.blocks import ( AudioChooserBlock, MediaChooserBlockComparison, @@ -9,8 +11,6 @@ from wagtailmedia.models import get_media_model from wagtailmedia.utils import format_audio_html, format_video_html -from tests.testapp.models import BlogStreamPage - from .utils import create_audio, create_video diff --git a/tests/test_edit_handlers.py b/tests/test_edit_handlers.py index ffc9e79..7e8752a 100644 --- a/tests/test_edit_handlers.py +++ b/tests/test_edit_handlers.py @@ -4,10 +4,10 @@ from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin.panels import FieldPanel, ObjectList from wagtail.models import Page -from wagtailmedia.edit_handlers import MediaChooserPanel, MediaFieldComparison -from wagtailmedia.widgets import AdminAudioChooser, AdminMediaChooser, AdminVideoChooser from tests.testapp.models import BlogStreamPage +from wagtailmedia.edit_handlers import MediaChooserPanel, MediaFieldComparison +from wagtailmedia.widgets import AdminAudioChooser, AdminMediaChooser, AdminVideoChooser from .utils import create_audio, create_video diff --git a/tests/test_form_override.py b/tests/test_form_override.py index 10f91c6..0477baf 100644 --- a/tests/test_form_override.py +++ b/tests/test_form_override.py @@ -1,10 +1,10 @@ from django import forms from django.test import TestCase, override_settings from wagtail.admin import widgets -from wagtailmedia import models -from wagtailmedia.forms import BaseMediaForm, get_media_base_form, get_media_form from tests.testapp.forms import AlternateMediaForm, OverridenWidget +from wagtailmedia import models +from wagtailmedia.forms import BaseMediaForm, get_media_base_form, get_media_form class TestFormOverride(TestCase): diff --git a/tests/test_models.py b/tests/test_models.py index 15790b1..d5f31a0 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -4,6 +4,7 @@ from django.db import transaction from django.template import Context, Template from django.test import TestCase, override_settings + from wagtailmedia.forms import get_media_form from wagtailmedia.models import get_media_model diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 3dbf2f3..78af0d4 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -5,6 +5,7 @@ from django.urls import reverse from wagtail.models import Collection, GroupCollectionPermission from wagtail.test.utils import WagtailTestUtils + from wagtailmedia import models diff --git a/tests/test_settings.py b/tests/test_settings.py index 00a758d..4b424a8 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,6 +1,7 @@ from unittest import mock from django.test import TestCase, override_settings + from wagtailmedia.settings import WagtailMediaSettings, wagtailmedia_settings diff --git a/tests/test_tags.py b/tests/test_tags.py index 736c7b6..b8470fe 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -1,6 +1,7 @@ from unittest.mock import patch from django.test import TestCase + from wagtailmedia.templatetags.media_tags import wagtail_version_gte diff --git a/tests/test_utils.py b/tests/test_utils.py index ba9d800..eecdd0c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,5 +1,6 @@ from django.core.files.base import ContentFile from django.test import TestCase + from wagtailmedia.models import get_media_model from wagtailmedia.utils import format_audio_html, format_video_html diff --git a/tests/test_views.py b/tests/test_views.py index d45da60..70b0b83 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -10,9 +10,9 @@ from django.urls import NoReverseMatch, reverse from wagtail.models import Collection, GroupCollectionPermission from wagtail.test.utils import WagtailTestUtils -from wagtailmedia import models from tests.testapp.models import EventPage, EventPageRelatedMedia +from wagtailmedia import models class TestMediaIndexView(TestCase, WagtailTestUtils): diff --git a/tests/test_widgets.py b/tests/test_widgets.py index 0ec6b2f..9de1aa0 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -1,5 +1,6 @@ from django.test import TestCase from django.urls import reverse + from wagtailmedia import widgets from wagtailmedia.widgets import AdminAudioChooser, AdminMediaChooser, AdminVideoChooser diff --git a/tests/testapp/forms.py b/tests/testapp/forms.py index 574a416..f27166a 100644 --- a/tests/testapp/forms.py +++ b/tests/testapp/forms.py @@ -1,4 +1,5 @@ from django.forms.widgets import Widget + from wagtailmedia.forms import BaseMediaForm diff --git a/tests/testapp/migrations/0001_initial.py b/tests/testapp/migrations/0001_initial.py index e95c7b4..4eb2ad0 100644 --- a/tests/testapp/migrations/0001_initial.py +++ b/tests/testapp/migrations/0001_initial.py @@ -7,11 +7,12 @@ import wagtail.blocks import wagtail.fields import wagtail.search.index -import wagtailmedia.blocks from django.conf import settings from django.db import migrations, models +import wagtailmedia.blocks + try: import wagtail.models.media as collections diff --git a/tests/testapp/models.py b/tests/testapp/models.py index dfd038b..2f5e5a8 100644 --- a/tests/testapp/models.py +++ b/tests/testapp/models.py @@ -6,6 +6,7 @@ from wagtail.admin.panels import FieldPanel, InlinePanel from wagtail.fields import RichTextField, StreamField from wagtail.models import Orderable, Page + from wagtailmedia.blocks import ( AbstractMediaChooserBlock, AudioChooserBlock, diff --git a/tests/urls.py b/tests/urls.py index bc77bd9..89641eb 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -5,6 +5,7 @@ from wagtail.admin import urls as wagtailadmin_urls from wagtail.api.v2.router import WagtailAPIRouter from wagtail.documents import urls as wagtaildocs_urls + from wagtailmedia.api.views import MediaAPIViewSet diff --git a/tests/utils.py b/tests/utils.py index e5885c5..a479917 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -3,6 +3,7 @@ from typing import Optional from django.core.files.base import ContentFile + from wagtailmedia.models import MediaType, get_media_model