Skip to content

Commit

Permalink
Tooling updates (#790)
Browse files Browse the repository at this point in the history
* Update ruff version and use for formatting as well
* Lint
* Remove unused runtime.txt
* Move nightly tests to GHA
* Tidy up tox config
* Ensure we're using coverage >= 7.0
* Add a publish action
   includes asset build
* Tidy up ignore files
* Drop the lint step in favour of pre-commit.ci
* Tidy up README
* Regenerate test migrations as an initial one (speeds up things)
  • Loading branch information
zerolab authored Mar 11, 2024
1 parent cf12512 commit f005601
Show file tree
Hide file tree
Showing 36 changed files with 723 additions and 2,138 deletions.
60 changes: 0 additions & 60 deletions .circleci/config.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .circleci/trigger-nightly-build.sh

This file was deleted.

17 changes: 13 additions & 4 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
[run]
branch = True
include = wagtail_localize/*
omit = */migrations/*,*/tests/*
omit = **/migrations/*,**/tests/*

[report]
show_missing = true
ignore_errors = true
skip_empty = true
skip_covered = true

# Regexes for lines to exclude from consideration
exclude_lines =
exclude_also =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__
if self\.debug
if self.debug
if settings.DEBUG

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
Expand All @@ -21,4 +27,7 @@ exclude_lines =
if 0:
if __name__ == .__main__.:

ignore_errors = True
# Nor complain about type checking
"if TYPE_CHECKING:",
class .*\bProtocol\):
@(abc\.)?abstractmethod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This reports an error to the #nightly-build-failures Slack channel.
"""

import os

import requests
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/nigthly-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Nightly Wagtail test

on:
schedule:
# Nightly at 4am.
- cron: '0 4 * * *'

workflow_dispatch:

jobs:
nightly-test:
# Cannot check the existence of secrets, so limiting to repository name to prevent all forks to run nightly.
# See: https://github.com/actions/runner/issues/520
if: ${{ github.repository == 'wagtail/wagtail-localize' }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip tox
- name: Test
id: test
continue-on-error: true
run: tox -e wagtailmain

- name: Send Slack notification on failure
if: steps.test.outcome == 'failure'
run: |
python .github/scripts/report_nightly_build_failure.py
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
62 changes: 62 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Publish to PyPI

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read # to fetch code (actions/checkout)
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Install Node dependencies
run: npm ci

- name: Build static files
run: ./node_modules/.bin/webpack --mode production

- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'

- name: ⬇️ Install build dependencies
run: |
python -m pip install -U flit
- name: 🏗️ Build
run: python -m flit build

- uses: actions/upload-artifact@v4
with:
path: ./dist

# https://docs.pypi.org/trusted-publishers/using-a-publisher/
pypi-publish:
needs: build
environment: 'publish'

name: ⬆️ Upload release to PyPI
runs-on: ubuntu-latest
permissions:
# Mandatory for trusted publishing
id-token: write
steps:
- uses: actions/download-artifact@v4

- name: 🚀 Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: artifact/
print-hash: true
22 changes: 22 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Ruff

on:
push:
branches:
- main
- 'stable/**'
pull_request:
branches: [main]

jobs:
ruff:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- run: python -Im pip install --user ruff

- name: Run ruff
working-directory: .
run: ruff --output-format=github wagtail_localize
29 changes: 8 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,11 @@ permissions:
contents: read # to fetch code (actions/checkout)

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: ${{env.PYTHON_LATEST}}
- uses: pre-commit/action@v3.0.0

test-sqlite:
runs-on: ubuntu-latest
needs: lint
strategy:
matrix:
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
python: ['3.10', '3.11', '3.12']
database: ['sqlite']

steps:
Expand All @@ -59,7 +47,6 @@ jobs:

test-postgres:
runs-on: ubuntu-latest
needs: lint
strategy:
matrix:
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
Expand Down Expand Up @@ -92,21 +79,21 @@ jobs:
- name: Install dependencies
id: install-dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
python -m pip install --upgrade pip tox tox-gh-actions
- name: Test with tox
id: test-with-tox
run: tox -- -v1
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
DATABASE: postgres

coverage:
runs-on: ubuntu-latest
needs: lint
needs:
- test-sqlite
- test-postgres
strategy:
matrix:
python: ['3.8']
python: ['3.11']

steps:
- uses: actions/checkout@v4
Expand All @@ -116,9 +103,9 @@ jobs:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
pip install flit
python -Im pip install -U flit
python -Im pip install "coverage>=7.0,<8.0"
flit install --deps production --extras testing
pip install coverage==5.4
- name: Test
run: |
coverage run testmanage.py test
Expand Down
14 changes: 3 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -12,20 +12,12 @@ repos:
args: ['--unsafe']
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.11.0]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.5'
rev: 'v0.3.2'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-prettier
rev: 'v2.7.1'
hooks:
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
[![Version](https://img.shields.io/pypi/v/wagtail-localize.svg?style=flat)](https://pypi.python.org/pypi/wagtail-localize/)
[![License](https://img.shields.io/badge/license-BSD-blue.svg?style=flat)](https://opensource.org/licenses/BSD-3-Clause)
[![codecov](https://img.shields.io/codecov/c/github/wagtail/wagtail-localize?style=flat)](https://codecov.io/gh/wagtail/wagtail-localize)
[![black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat)](https://github.com/psf/black)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat)](https://github.com/pre-commit/pre-commit)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/wagtail/wagtail-localize/main.svg)](https://results.pre-commit.ci/latest/github/wagtail/wagtail-localize/main)

Wagtail Localize is a translation plugin for the [Wagtail CMS](https://wagtail.org). It allows pages or snippets to be translated within Wagtail's admin interface. It also provides integrations with external translations services such as [Pontoon](https://pontoon.mozilla.org/) or [DeepL](https://www.deepl.com/), and importing/exporting translations with PO files.

Expand All @@ -25,9 +25,9 @@ We'll be at Wagtail Space US this year! The Call for Participation and Registrat
Wagtail Localize requires the following:

- Python (3.8, 3.9, 3.10, 3.11)
- Django (3.2, 4.1, 4.2)
- Wagtail (4.1, 5.1, 5.2) with [internationalisation enabled](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#configuration)
- [wagtail-modeladmin](https://pypi.org/project/wagtail-modeladmin/) if `using wagtail_localize.modeladmin` and Wagtail >= 5.0
- Django (3.2, 4.2, 5.0)
- Wagtail (5.2, 6.0) with [internationalisation enabled](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#configuration)
- [wagtail-modeladmin](https://pypi.org/project/wagtail-modeladmin/) if `using wagtail_localize.modeladmin` and Wagtail >= 5.2

## Installation

Expand Down Expand Up @@ -105,8 +105,8 @@ Now you can run tests as shown below:
tox
```

or, you can run them for a specific environment `tox -e python3.8-django3.2-wagtail4.1` or specific test
`tox -e python3.9-django3.2-wagtail4.1-sqlite -- wagtail_localize.tests.test_edit_translation.TestGetEditTranslationView`
or, you can run them for a specific environment `tox -e python3.11-django4.2-wagtail5.2` or specific test
`tox -e python3.11-django4.2-wagtail5.2-sqlite -- wagtail_localize.tests.test_edit_translation.TestGetEditTranslationView`

To run the test app interactively, use `tox -e interactive`, visit `http://127.0.0.1:8020/admin/` and log in with `admin`/`changeme`.

Expand Down
Loading

0 comments on commit f005601

Please sign in to comment.