Skip to content

Commit 7e3277a

Browse files
authored
[chore] Tooling updates/tweaks (#252)
* Bump pre-commit/ruff versions * Tidy up tox config * Bump action versions and harden checkout action * Lint
1 parent 3d9014c commit 7e3277a

27 files changed

+71
-38
lines changed

.github/workflows/nightly-tests.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ jobs:
2424

2525
steps:
2626
- uses: actions/checkout@v4
27-
- name: Set up Python 3.11
27+
with:
28+
persist-credentials: false
29+
- name: Set up Python
2830
uses: actions/setup-python@v5
2931
with:
30-
python-version: "3.11"
32+
python-version: "3.13"
3133
- name: Install dependencies
3234
run: |
3335
python -m pip install --upgrade pip
34-
pip install "psycopg2>=2.6"
36+
pip install "psycopg2>=2.9"
3537
pip install "git+https://github.com/wagtail/wagtail.git@main#egg=wagtail"
3638
pip install -e .[testing]
3739
- name: Test

.github/workflows/publish.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@ jobs:
1111
build:
1212
runs-on: ubuntu-latest
1313
steps:
14+
- name: 🔒 Harden Runner
15+
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
16+
with:
17+
disable-sudo: true
18+
egress-policy: block
19+
allowed-endpoints: >
20+
files.pythonhosted.org:443
21+
github.com:443
22+
pypi.org:443
23+
api.github.com:443
24+
1425
- uses: actions/checkout@v4
1526
with:
27+
persist-credentials: false
1628
fetch-depth: 0
1729

1830
- uses: actions/setup-python@v5
1931
with:
20-
python-version: '3.11'
32+
python-version: '3.13'
2133
cache: "pip"
2234
cache-dependency-path: "**/pyproject.toml"
2335

@@ -28,7 +40,7 @@ jobs:
2840
- name: 🏗️ Build
2941
run: python -Im flit build
3042

31-
- uses: actions/upload-artifact@v3
43+
- uses: actions/upload-artifact@v4
3244
with:
3345
path: ./dist
3446

@@ -43,7 +55,7 @@ jobs:
4355
# Mandatory for trusted publishing
4456
id-token: write
4557
steps:
46-
- uses: actions/download-artifact@v3
58+
- uses: actions/download-artifact@v4
4759

4860
- name: 🚀 Publish package distributions to PyPI
4961
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/ruff.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v4
17+
with:
18+
persist-credentials: false
1719

18-
- run: python -Im pip install --user ruff==0.5.4
20+
- run: python -Im pip install --user ruff==0.8.2
1921

2022
- name: Run ruff
2123
working-directory: ./src

.github/workflows/test.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ env:
1919
PIP_DISABLE_PIP_VERSION_CHECK: "1"
2020
PIP_NO_PYTHON_VERSION_WARNING: "1"
2121
# Keep in sync with .pre-commit-config.yaml/default_language_version/python.
22-
PYTHON_LATEST: "3.11"
22+
PYTHON_LATEST: "3.12" # because harden runner fails on the 3.13 download
2323

2424
jobs:
2525
tests:
@@ -32,7 +32,7 @@ jobs:
3232

3333
steps:
3434
- name: 🔒 Harden Runner
35-
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
35+
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
3636
with:
3737
disable-sudo: true
3838
egress-policy: block
@@ -43,6 +43,8 @@ jobs:
4343
pypi.org:443
4444
api.github.com:443
4545
- uses: actions/checkout@v4
46+
with:
47+
persist-credentials: false
4648
- name: 🐍 Set up Python ${{ matrix.python-version }}
4749
uses: actions/setup-python@v5
4850
with:
@@ -60,9 +62,9 @@ jobs:
6062
run: tox --installpkg ./dist/*.whl
6163

6264
- name: ⬆️ Upload coverage data
63-
uses: actions/upload-artifact@v3
65+
uses: actions/upload-artifact@v4
6466
with:
65-
name: coverage-data
67+
name: coverage-data-${{ matrix.python-version }}
6668
path: .coverage.*
6769
if-no-files-found: ignore
6870
include-hidden-files: true
@@ -74,7 +76,7 @@ jobs:
7476

7577
steps:
7678
- name: 🔒 Harden Runner
77-
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
79+
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
7880
with:
7981
disable-sudo: true
8082
egress-policy: block
@@ -85,6 +87,7 @@ jobs:
8587
api.github.com:443
8688
- uses: actions/checkout@v4
8789
with:
90+
persist-credentials: false
8891
fetch-depth: 0
8992
- uses: actions/setup-python@v5
9093
with:
@@ -94,9 +97,10 @@ jobs:
9497
- run: python -Im pip install --upgrade coverage
9598

9699
- name: Download coverage data
97-
uses: actions/download-artifact@v3
100+
uses: actions/download-artifact@v4
98101
with:
99-
name: coverage-data
102+
pattern: coverage-data-*
103+
merge-multiple: true
100104

101105
- name: + Combine coverage
102106
run: |
@@ -106,7 +110,7 @@ jobs:
106110
echo "## Coverage summary" >> $GITHUB_STEP_SUMMARY
107111
python -Im coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
108112
- name: 📈 Upload HTML report if check failed.
109-
uses: actions/upload-artifact@v3
113+
uses: actions/upload-artifact@v4
110114
with:
111115
name: html-report
112116
path: htmlcov

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ ci:
33
autoupdate_schedule: 'quarterly'
44

55
default_language_version:
6-
python: python3.11
6+
python: python3.13
77

88
repos:
99
- repo: https://github.com/pre-commit/pre-commit-hooks
10-
rev: v4.5.0
10+
rev: v5.0.0
1111
hooks:
1212
- id: check-added-large-files
1313
- id: check-case-conflict
@@ -19,7 +19,7 @@ repos:
1919
- id: end-of-file-fixer
2020
- id: trailing-whitespace
2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: 'v0.5.4'
22+
rev: 'v0.8.2' # keep in sync with .github/workflows/ruff.yml
2323
hooks:
2424
- id: ruff
2525
args: [--fix, --exit-non-zero-on-fix]

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ dependencies = [
3333

3434
[project.optional-dependencies]
3535
testing = [
36-
"coverage>=7.4.0",
36+
"coverage>=7.6.0",
3737
]
3838
linting = [
39-
"pre-commit>=3.6.0",
39+
"pre-commit>=5.0.0",
4040
]
4141

4242
[project.urls]

src/wagtailmedia/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING, Type
1+
from typing import TYPE_CHECKING
22

33
from django.forms import ModelChoiceField
44
from django.template.loader import render_to_string
@@ -52,7 +52,7 @@ def render_basic(self, value, context=None):
5252
f"You need to implement {self.__class__.__name__}.render_basic"
5353
)
5454

55-
def get_comparison_class(self) -> Type["MediaChooserBlockComparison"]:
55+
def get_comparison_class(self) -> type["MediaChooserBlockComparison"]:
5656
return MediaChooserBlockComparison
5757

5858

src/wagtailmedia/wagtail_hooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def register_media_permissions_panel():
9595
def describe_collection_media(collection):
9696
media_count = get_media_model().objects.filter(collection=collection).count()
9797
if media_count:
98-
url = reverse("wagtailmedia:index") + ("?collection_id=%d" % collection.id)
98+
url = reverse("wagtailmedia:index") + f"?collection_id={collection.id}"
9999
return {
100100
"count": media_count,
101101
"count_text": ngettext(

tests/test_admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.urls import reverse
33
from wagtail.models import Page
44
from wagtail.test.utils import WagtailTestUtils
5+
56
from wagtailmedia.blocks import AbstractMediaChooserBlock
67

78

tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from django.test import TestCase, override_settings
44
from django.urls import reverse
5+
56
from wagtailmedia.models import get_media_model
67

78
from .utils import create_audio, create_video
@@ -66,8 +67,7 @@ def test_basic(self):
6667

6768
# Check detail_url
6869
self.assertEqual(
69-
item["meta"]["detail_url"],
70-
"http://localhost/api/media/%d/" % item["id"],
70+
item["meta"]["detail_url"], f"http://localhost/api/media/{item['id']}/"
7171
)
7272

7373
media = Media.objects.get(pk=item["id"])

tests/test_blocks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.core.files.base import ContentFile
22
from django.test import TestCase
33
from django.urls import reverse
4+
45
from wagtailmedia.blocks import (
56
AbstractMediaChooserBlock,
67
AudioChooserBlock,

tests/test_compare.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from django.test import TestCase
22
from django.utils.safestring import SafeString
3+
4+
from tests.testapp.models import BlogStreamPage
35
from wagtailmedia.blocks import (
46
AudioChooserBlock,
57
MediaChooserBlockComparison,
@@ -9,8 +11,6 @@
911
from wagtailmedia.models import get_media_model
1012
from wagtailmedia.utils import format_audio_html, format_video_html
1113

12-
from tests.testapp.models import BlogStreamPage
13-
1414
from .utils import create_audio, create_video
1515

1616

tests/test_edit_handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from wagtail import VERSION as WAGTAIL_VERSION
55
from wagtail.admin.panels import FieldPanel, ObjectList
66
from wagtail.models import Page
7-
from wagtailmedia.edit_handlers import MediaChooserPanel, MediaFieldComparison
8-
from wagtailmedia.widgets import AdminAudioChooser, AdminMediaChooser, AdminVideoChooser
97

108
from tests.testapp.models import BlogStreamPage
9+
from wagtailmedia.edit_handlers import MediaChooserPanel, MediaFieldComparison
10+
from wagtailmedia.widgets import AdminAudioChooser, AdminMediaChooser, AdminVideoChooser
1111

1212
from .utils import create_audio, create_video
1313

tests/test_form_override.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from django import forms
22
from django.test import TestCase, override_settings
33
from wagtail.admin import widgets
4-
from wagtailmedia import models
5-
from wagtailmedia.forms import BaseMediaForm, get_media_base_form, get_media_form
64

75
from tests.testapp.forms import AlternateMediaForm, OverridenWidget
6+
from wagtailmedia import models
7+
from wagtailmedia.forms import BaseMediaForm, get_media_base_form, get_media_form
88

99

1010
class TestFormOverride(TestCase):

tests/test_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.db import transaction
55
from django.template import Context, Template
66
from django.test import TestCase, override_settings
7+
78
from wagtailmedia.forms import get_media_form
89
from wagtailmedia.models import get_media_model
910

tests/test_permissions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.urls import reverse
66
from wagtail.models import Collection, GroupCollectionPermission
77
from wagtail.test.utils import WagtailTestUtils
8+
89
from wagtailmedia import models
910

1011

tests/test_settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from unittest import mock
22

33
from django.test import TestCase, override_settings
4+
45
from wagtailmedia.settings import WagtailMediaSettings, wagtailmedia_settings
56

67

tests/test_tags.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from unittest.mock import patch
22

33
from django.test import TestCase
4+
45
from wagtailmedia.templatetags.media_tags import wagtail_version_gte
56

67

tests/test_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.core.files.base import ContentFile
22
from django.test import TestCase
3+
34
from wagtailmedia.models import get_media_model
45
from wagtailmedia.utils import format_audio_html, format_video_html
56

tests/test_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from django.urls import NoReverseMatch, reverse
1111
from wagtail.models import Collection, GroupCollectionPermission
1212
from wagtail.test.utils import WagtailTestUtils
13-
from wagtailmedia import models
1413

1514
from tests.testapp.models import EventPage, EventPageRelatedMedia
15+
from wagtailmedia import models
1616

1717

1818
class TestMediaIndexView(TestCase, WagtailTestUtils):

tests/test_widgets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.test import TestCase
22
from django.urls import reverse
3+
34
from wagtailmedia import widgets
45
from wagtailmedia.widgets import AdminAudioChooser, AdminMediaChooser, AdminVideoChooser
56

tests/testapp/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.forms.widgets import Widget
2+
23
from wagtailmedia.forms import BaseMediaForm
34

45

tests/testapp/migrations/0001_initial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import wagtail.blocks
88
import wagtail.fields
99
import wagtail.search.index
10-
import wagtailmedia.blocks
1110

1211
from django.conf import settings
1312
from django.db import migrations, models
1413

14+
import wagtailmedia.blocks
15+
1516

1617
try:
1718
import wagtail.models.media as collections

tests/testapp/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from wagtail.admin.panels import FieldPanel, InlinePanel
77
from wagtail.fields import RichTextField, StreamField
88
from wagtail.models import Orderable, Page
9+
910
from wagtailmedia.blocks import (
1011
AbstractMediaChooserBlock,
1112
AudioChooserBlock,

tests/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from wagtail.admin import urls as wagtailadmin_urls
66
from wagtail.api.v2.router import WagtailAPIRouter
77
from wagtail.documents import urls as wagtaildocs_urls
8+
89
from wagtailmedia.api.views import MediaAPIViewSet
910

1011

tests/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Optional
44

55
from django.core.files.base import ContentFile
6+
67
from wagtailmedia.models import MediaType, get_media_model
78

89

0 commit comments

Comments
 (0)