Skip to content

Commit

Permalink
Merge pull request #27 from thorgate/django-50-support
Browse files Browse the repository at this point in the history
Add Django 5.0 support
  • Loading branch information
iharthi authored Mar 4, 2024
2 parents 0914cc3 + 73f7d86 commit ddbcf20
Show file tree
Hide file tree
Showing 9 changed files with 1,133 additions and 1,169 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v2
Expand All @@ -28,23 +30,23 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Add poetry
uses: abatilo/[email protected]
with:
poetry-version: "1.2.2"
uses: abatilo/[email protected]
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
poetry install
- name: Lint
- if: ${{ matrix.python-version == '3.11' }}
name: Lint
run: |
poetry run make lint
- name: Test with tox
run: |
poetry run make coverage
poetry run make test-all
- name: Code Coverage Summary Report
- if: ${{ matrix.python-version == '3.11' }}
name: Code Coverage Summary Report
uses: irongut/[email protected]
with:
filename: coverage.xml
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"

steps:
- uses: actions/checkout@v2
Expand All @@ -24,9 +24,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Add poetry
uses: abatilo/[email protected]
with:
poetry-version: "1.2.2"
uses: abatilo/[email protected]
- name: Install dependencies
run: poetry install
- name: Build and publish
Expand Down
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
History
=======

1.0.2 (2024-01-08)

* Add support for django 5

1.0.1 (2023-01-13)
------------------

Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ test:
test-all:
tox

test-full: lint coverage

coverage:
pytest --cov=tg_utils --cov-report xml --cov-report html --cov-report term-missing

Expand Down
2,236 changes: 1,086 additions & 1,150 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tg-utils"
version = "1.0.1"
version = "1.0.2"
description = "Common utils for Django-based projects."
authors = ["Thorgate <[email protected]>"]
license = "ISCL"
Expand Down Expand Up @@ -55,7 +55,6 @@ prospector = "^1.7.0"
pylint = "==2.14.*"
sphinx = "==3.*"
tox = "*"
tox-poetry = "*"
tox-gh-actions = "*"

django-compressor = "*"
Expand Down
20 changes: 18 additions & 2 deletions tg_utils/health_check/checks/celery_beat/backends.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.core.cache import cache
from django.utils.datetime_safe import datetime
from django.utils import timezone

from health_check.backends import BaseHealthCheckBackend
from health_check.exceptions import ServiceUnavailable
Expand All @@ -19,7 +19,23 @@ def check_status(self):
last_beat_time = cache.get(CACHE_KEY, None)
if last_beat_time is None:
self.add_error(ServiceUnavailable("Celery beat is not scheduling tasks"))
elif (datetime.now() - last_beat_time).seconds > DELAY_THRESHOLD:
return

if (
not isinstance(last_beat_time, timezone.datetime)
or not last_beat_time.tzinfo
):
self.add_error(
# If you encounter this error in tests, most likely you are using a fixture
# instead of running the task, and the fixture is providing unaware timestamp. Switch
# your ficture to locale-aware timestamp to fix this
ServiceUnavailable(
f"Celery beat task timestamp is invalid: {last_beat_time!r}"
)
)
return

if (timezone.now() - last_beat_time).seconds > DELAY_THRESHOLD:
self.add_error(
ServiceUnavailable(
f"Celery beat tasks are delayed, last ran at {last_beat_time}."
Expand Down
4 changes: 2 additions & 2 deletions tg_utils/health_check/checks/celery_beat/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.core.cache import cache
from django.utils.datetime_safe import datetime
from django.utils import timezone

from celery import shared_task # pylint: disable=import-error
from tg_utils.health_check.checks.celery_beat.backends import CACHE_KEY
Expand All @@ -8,4 +8,4 @@
@shared_task(ignore_result=False)
def timestamp_task():
# timeout=None causes value to be stored forever
cache.set(CACHE_KEY, datetime.now(), timeout=None)
cache.set(CACHE_KEY, timezone.now(), timeout=None)
13 changes: 10 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,33 @@ isolated_build = True
envlist =
py37-django{22,30,31,32}
py{38,39}-django{22,30,31,32,40}
py310-django{32,40}
py{310,311}-django{32,40,41,42,50}
py{312}-django{42,50}

[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310
3.11: py311
3.12: py312

[testenv]
setenv =
PYTHONPATH = {toxinidir}
whitelist_externals=make
allowlist_externals=make
commands=make test

deps=
django22: Django>=2.2,<2.3
django30: Django>=3.0,<3.1
django31: Django>=3.1,<3.2
django32: Django>=3.2,<3.3
django40: Django>=4.0,<4.1
django41: Django>=4.1,<4.2
django42: Django>=4.2,<4.3
django50: Django>=5.0,<5.1

[testenv:py310-django40]
[testenv:py311-django50]
commands = make test-full

0 comments on commit ddbcf20

Please sign in to comment.