Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Python 3.8 support #678

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.9'

- name: Get pip cache dir
id: pip-cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
max-parallel: 5
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12']

services:
postgres:
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ repos:
rev: 24.4.2
hooks:
- id: black
language_version: python3.8
language_version: python3.9
args:
- "--target-version"
- "py38"
- "py39"
- repo: https://github.com/PyCQA/flake8
rev: "7.1.0"
hooks:
Expand All @@ -21,7 +21,7 @@ repos:
rev: v3.16.0
hooks:
- id: pyupgrade
args: [--py38-plus]
args: [--py39-plus]
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.20.0
hooks:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#### Improvements
- feat: Added `LogEntry.remote_port` field. ([#671](https://github.com/jazzband/django-auditlog/pull/671))
- Drop Python 3.8 support. ([#678](https://github.com/jazzband/django-auditlog/pull/678))

#### Fixes

Expand Down
4 changes: 1 addition & 3 deletions auditlog/migrations/0015_alter_logentry_changes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Generated by Django 4.0 on 2022-08-04 15:41
from typing import List

from django.conf import settings
from django.db import migrations, models


def two_step_migrations() -> List:
def two_step_migrations() -> list:
if settings.AUDITLOG_TWO_STEP_MIGRATION:
return [
migrations.RenameField(
Expand Down
16 changes: 8 additions & 8 deletions auditlog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
from copy import deepcopy
from datetime import timezone
from typing import Any, Callable, Dict, List, Union
from typing import Any, Callable, Union

from dateutil import parser
from dateutil.tz import gettz
Expand Down Expand Up @@ -275,8 +275,8 @@ def _get_copy_with_python_typed_fields(self, instance):
return instance_copy

def _get_applicable_model_fields(
self, instance, model_fields: Dict[str, List[str]]
) -> List[str]:
self, instance, model_fields: dict[str, list[str]]
) -> list[str]:
include_fields = model_fields["include_fields"]
exclude_fields = model_fields["exclude_fields"]
all_field_names = [field.name for field in instance._meta.fields]
Expand All @@ -287,8 +287,8 @@ def _get_applicable_model_fields(
return list(set(include_fields or all_field_names).difference(exclude_fields))

def _mask_serialized_fields(
self, data: Dict[str, Any], mask_fields: List[str]
) -> Dict[str, Any]:
self, data: dict[str, Any], mask_fields: list[str]
) -> dict[str, Any]:
all_field_data = data.pop("fields")

masked_field_data = {}
Expand Down Expand Up @@ -595,16 +595,16 @@ def bulk_related_objects(self, objs, using=DEFAULT_DB_ALIAS):
changes_func = None


def _changes_func() -> Callable[[LogEntry], Dict]:
def json_then_text(instance: LogEntry) -> Dict:
def _changes_func() -> Callable[[LogEntry], dict]:
def json_then_text(instance: LogEntry) -> dict:
if instance.changes:
return instance.changes
elif instance.changes_text:
with contextlib.suppress(ValueError):
return json.loads(instance.changes_text)
return {}

def default(instance: LogEntry) -> Dict:
def default(instance: LogEntry) -> dict:
return instance.changes or {}

if settings.AUDITLOG_USE_TEXT_CHANGES_IF_JSON_IS_NOT_PRESENT:
Expand Down
35 changes: 13 additions & 22 deletions auditlog/registry.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import copy
from collections import defaultdict
from typing import (
Any,
Callable,
Collection,
Dict,
Iterable,
List,
Optional,
Tuple,
Union,
)
from collections.abc import Collection, Iterable
from typing import Any, Callable, Optional, Union

from django.apps import apps
from django.db.models import ManyToManyField, Model
Expand All @@ -26,7 +17,7 @@
from auditlog.conf import settings
from auditlog.signals import accessed

DispatchUID = Tuple[int, int, int]
DispatchUID = tuple[int, int, int]


class AuditLogRegistrationError(Exception):
Expand All @@ -47,7 +38,7 @@ def __init__(
delete: bool = True,
access: bool = True,
m2m: bool = True,
custom: Optional[Dict[ModelSignal, Callable]] = None,
custom: Optional[dict[ModelSignal, Callable]] = None,
):
from auditlog.receivers import log_access, log_create, log_delete, log_update

Expand All @@ -71,13 +62,13 @@ def __init__(
def register(
self,
model: ModelBase = None,
include_fields: Optional[List[str]] = None,
exclude_fields: Optional[List[str]] = None,
mapping_fields: Optional[Dict[str, str]] = None,
mask_fields: Optional[List[str]] = None,
include_fields: Optional[list[str]] = None,
exclude_fields: Optional[list[str]] = None,
mapping_fields: Optional[dict[str, str]] = None,
mask_fields: Optional[list[str]] = None,
m2m_fields: Optional[Collection[str]] = None,
serialize_data: bool = False,
serialize_kwargs: Optional[Dict[str, Any]] = None,
serialize_kwargs: Optional[dict[str, Any]] = None,
serialize_auditlog_fields_only: bool = False,
):
"""
Expand Down Expand Up @@ -169,7 +160,7 @@ def unregister(self, model: ModelBase) -> None:
else:
self._disconnect_signals(model)

def get_models(self) -> List[ModelBase]:
def get_models(self) -> list[ModelBase]:
return list(self._registry.keys())

def get_model_fields(self, model: ModelBase):
Expand Down Expand Up @@ -235,7 +226,7 @@ def _dispatch_uid(self, signal, receiver) -> DispatchUID:
"""Generate a dispatch_uid which is unique for a combination of self, signal, and receiver."""
return id(self), id(signal), id(receiver)

def _get_model_classes(self, app_model: str) -> List[ModelBase]:
def _get_model_classes(self, app_model: str) -> list[ModelBase]:
try:
try:
app_label, model_name = app_model.split(".")
Expand All @@ -247,7 +238,7 @@ def _get_model_classes(self, app_model: str) -> List[ModelBase]:

def _get_exclude_models(
self, exclude_tracking_models: Iterable[str]
) -> List[ModelBase]:
) -> list[ModelBase]:
exclude_models = [
model
for app_model in tuple(exclude_tracking_models)
Expand All @@ -256,7 +247,7 @@ def _get_exclude_models(
]
return exclude_models

def _register_models(self, models: Iterable[Union[str, Dict[str, Any]]]) -> None:
def _register_models(self, models: Iterable[Union[str, dict[str, Any]]]) -> None:
models = copy.deepcopy(models)
for model in models:
if isinstance(model, str):
Expand Down
4 changes: 2 additions & 2 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ The repository can be found at https://github.com/jazzband/django-auditlog/.

**Requirements**

- Python 3.8 or higher
- Python 3.9 or higher
- Django 3.2, 4.2 and 5.0

Auditlog is currently tested with Python 3.8+ and Django 3.2, 4.2 and 5.0. The latest test report can be found
Auditlog is currently tested with Python 3.9+ and Django 3.2, 4.2 and 5.0. The latest test report can be found
at https://github.com/jazzband/django-auditlog/actions.

Adding Auditlog to your Django application
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.black]
target-version = ["py38"]
target-version = ["py39"]

[tool.isort]
profile = "black"
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
description="Audit log app for Django",
long_description=long_description,
long_description_content_type="text/markdown",
python_requires=">=3.8",
python_requires=">=3.9",
install_requires=["Django>=3.2", "python-dateutil>=2.7.0"],
zip_safe=False,
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
14 changes: 6 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[tox]
envlist =
{py38,py39,py310}-django32
{py38,py39,py310,py311}-django42
{py39,py310}-django32
{py39,py310,py311}-django42
{py310,py311,py312}-django{50,main}
py38-docs
py38-lint
py39-docs
py39-lint

[testenv]
setenv =
Expand Down Expand Up @@ -34,21 +34,19 @@ basepython =
py311: python3.11
py310: python3.10
py39: python3.9
py38: python3.8

[testenv:py38-docs]
[testenv:py39-docs]
changedir = docs/source
deps = -rdocs/requirements.txt
commands = sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html

[testenv:py38-lint]
[testenv:py39-lint]
deps = pre-commit
commands =
pre-commit run --all-files

[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311
Expand Down