Skip to content

Commit

Permalink
[chore] Tooling tweaks (wagtail#816)
Browse files Browse the repository at this point in the history
* Tweak the tox configuration
* Update GitHub Actions config
   - use uv for package installation
   - add the token configuration for Codecov
   - combine coverage data from each run
* Lint
  • Loading branch information
zerolab authored Aug 22, 2024
1 parent 9314c5d commit f465821
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 33 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[run]
branch = True
concurrency = multiprocessing, thread
include = wagtail_localize/*
omit = **/migrations/*,**/tests/*

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
- uses: actions/checkout@v4

# keep in sync with .pre-commit-config.yaml
- run: python -Im pip install --user ruff==0.4.8
- run: python -Im pip install --user ruff==0.6.1

- name: Run ruff
working-directory: .
run: ruff --output-format=github wagtail_localize
run: ruff check --output-format=github wagtail_localize
65 changes: 45 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ on:
branches:
- main
- 'stable/**'

pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read # to fetch code (actions/checkout)

env:
FORCE_COLOR: '1' # Make tools pretty.
TOX_TESTENV_PASSENV: FORCE_COLOR
PIP_DISABLE_PIP_VERSION_CHECK: '1'
PIP_NO_PYTHON_VERSION_WARNING: '1'
PYTHON_LATEST: '3.11'

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
test-sqlite:
runs-on: ubuntu-latest
Expand All @@ -33,17 +32,24 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
python -m pip install --upgrade uv
python -m uv pip install setuptools wheel tox tox-gh-actions
- name: Test with tox
run: tox -- -v1
run: tox -q -- -v1
env:
DATABASE: sqlite
- name: ⬆️ Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-data-${{ matrix.python }}-sqlite
path: .coverage.*
if-no-files-found: ignore
retention-days: 1

test-postgres:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -72,19 +78,27 @@ jobs:

- name: Set up Python
id: setup-python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install dependencies
id: install-dependencies
run: |
python -m pip install --upgrade pip tox tox-gh-actions
python -Im pip install --upgrade uv
python -Im uv pip install setuptools wheel tox tox-gh-actions
- name: Test with tox
run: tox -- -v1
run: tox -q -- -v1
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
DATABASE: postgres
- name: ⬆️ Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-data-${{ matrix.python }}-postgres
path: .coverage.*
if-no-files-found: ignore
retention-days: 1

coverage:
runs-on: ubuntu-latest
Expand All @@ -93,23 +107,34 @@ jobs:
- test-postgres
strategy:
matrix:
python: ['3.11']
python: ['3.12']

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
# Use latest Python, so it understands all syntax.
python-version: ${{env.PYTHON_LATEST}}

- name: Install dependencies
run: |
python -Im pip install -U flit
python -Im pip install "coverage>=7.0,<8.0"
flit install --deps production --extras testing
- name: Test
python -Im pip install --upgrade uv
python -Im uv pip install "coverage>=7.0,<8.0"
- name: ⬇️ Download coverage data
uses: actions/download-artifact@v4
with:
pattern: coverage-data-*
merge-multiple: true

- name: + Combine coverage
run: |
coverage run testmanage.py test
python -Im coverage combine
python -Im coverage html --skip-covered --skip-empty
python -Im coverage report
- name: 'Upload coverage to Codecov'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
# keep in sync with .github/workflows/ruff.yml
rev: 'v0.4.8'
rev: 'v0.6.1'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
11 changes: 7 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tox]
min_version = 4.0
min_version = 4.11

envlist =
python{3.9,3.10,3.11,3.12}-django4.2-wagtail{5.2,6.1,6.2}-postgres15
python{3.10,3.11,3.12}-django5.0-wagtail{5.2,6.1,6.2}-postgres15
python{3.12}-django5.1-wagtail{6.2}-postgres15
# note: we're running a subset of the test with sqlite
python3.11-django4.2-wagtail{5.2,6.1,6.2}-sqlite
python3.12-django5.0-wagtail{5.2,6.1,6.2}-sqlite
python3.10-django4.2-wagtail{5.2}-sqlite
python3.11-django5.0-wagtail{6.1}-sqlite
python3.12-django5.1-wagtail{6.2}-sqlite

[gh-actions]
Expand All @@ -34,6 +34,8 @@ constrain_package_deps = true
setenv =
postgres: DATABASE_URL={env:DATABASE_URL:postgres:///wagtail_localize}
PYTHONDEVMODE = 1
# use the Python 3.12+ sys.monitoring
python3.12: COVERAGE_CORE=sysmon

extras = testing

Expand All @@ -59,6 +61,7 @@ package = skip
deps =
coverage>=7.0,<8.0
commands =
python -Im coverage combine
python -Im coverage report -m

[testenv:wagtailmain]
Expand All @@ -73,7 +76,7 @@ commands =

[testenv:interactive]
description = An interactive environment for local testing purposes
basepython = python3.11
basepython = python3.12
deps =
wagtail>=5.2,<6.3
Django>=4.2,<5.2
Expand Down
7 changes: 2 additions & 5 deletions wagtail_localize/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,9 @@ def ignore_if_at_end(element):

# Ignore if there are no text nodes
# This will exclude both <br> tags and empty inline tags
if not any(
return not any(
isinstance(desc, NavigableString) for desc in element.descendants
):
return True

return False
)

if ignore_if_at_end(elements[0]):
wrap(elements[1:])
Expand Down

0 comments on commit f465821

Please sign in to comment.