Skip to content

Commit ac4977f

Browse files
amurekicodingjoe
andauthored
Add Django 5.2 support (#46)
[Django 5.2](https://docs.djangoproject.com/en/5.2/releases/5.2/) introduced a deprecation: > The all argument for the django.contrib.staticfiles.finders.find() function is deprecated in favor of the find_all argument. --------- Co-authored-by: Johannes Maron <johannes@maron.family>
1 parent 4e6ed2b commit ac4977f

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
python-version:
5252
- "3.9"
5353
- "3.10"
54+
- "3.11"
5455
- "3.12"
5556
django-version:
5657
- "4.2" # LTS
@@ -78,10 +79,9 @@ jobs:
7879
python-version:
7980
- "3.11"
8081
django-version:
81-
# LTS gets tested on all OS
82-
- "3.2"
83-
- "4.2"
84-
- "5.0"
82+
# oldest LTS gets tested on all Python versions
83+
- "5.1"
84+
- "5.2"
8585
runs-on: ubuntu-latest
8686
steps:
8787
- uses: actions/checkout@v4

django_esm/finders.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import json
3+
import warnings
34

45
from django.conf import settings
56
from django.contrib.staticfiles.finders import BaseFinder
@@ -29,9 +30,31 @@ def _check_package_json(self):
2930
]
3031
return []
3132

32-
def find(self, path, all=False):
33+
def _check_deprecated_find_param(self, find_all, **kwargs):
34+
# @todo: remove this after Django 5.2 support is dropped
35+
try:
36+
find_all = kwargs["all"]
37+
except KeyError:
38+
pass
39+
else:
40+
try:
41+
from django.utils.deprecation import RemovedInDjango61Warning
42+
except ImportError:
43+
pass
44+
else:
45+
warnings.warn(
46+
"The 'all' argument of the find() method is deprecated in favor of "
47+
"the 'find_all' argument.",
48+
category=RemovedInDjango61Warning,
49+
stacklevel=2,
50+
)
51+
return find_all
52+
53+
def find(self, path, find_all=False, **kwargs):
54+
find_all = self._check_deprecated_find_param(find_all, **kwargs)
55+
3356
if path in self.all:
34-
return [path] if all else path
57+
return [path] if find_all else path
3558
return [] # this method has a strange return type
3659

3760
def list(self, ignore_patterns):

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ classifiers = [
2828
"Programming Language :: Python :: 3.11",
2929
"Programming Language :: Python :: 3.12",
3030
"Framework :: Django",
31-
"Framework :: Django :: 3.2",
3231
"Framework :: Django :: 4.2",
33-
"Framework :: Django :: 5.0",
32+
"Framework :: Django :: 5.1",
33+
"Framework :: Django :: 5.2",
3434
]
3535
requires-python = ">=3.9"
36-
dependencies = ["django>=3.2.0"]
36+
dependencies = ["django>=4.2.0"]
3737

3838
[project.optional-dependencies]
3939
test = [

tests/test_finders.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import warnings
2+
3+
import django.utils.deprecation
4+
import pytest
15
from django.contrib.staticfiles.finders import get_finder
26
from django.core.checks import Error
37

@@ -17,9 +21,22 @@ def test_find(self):
1721
self.finder.find("testapp/static/js/components/index.js")
1822
== "testapp/static/js/components/index.js"
1923
)
20-
assert self.finder.find("lit-html/lit-html.js", all=True) == []
24+
assert self.finder.find("lit-html/lit-html.js", find_all=True) == []
2125
assert self.finder.find("foo/bar.js") == []
2226

27+
@pytest.mark.skipif(
28+
not hasattr(django.utils.deprecation, "RemovedInDjango61Warning"),
29+
reason="Django < 5.2",
30+
)
31+
def test_find_with_deprecated_param(self):
32+
with warnings.catch_warnings(record=True) as w:
33+
warnings.simplefilter("always")
34+
result = self.finder.find("testapp/static/js/index.js", all=True)
35+
assert len(w) == 1
36+
assert w[0].category == django.utils.deprecation.RemovedInDjango61Warning
37+
assert "deprecated in favor of" in str(w[0].message)
38+
assert result == ["testapp/static/js/index.js"]
39+
2340
def test_list(self):
2441
all_files = self.finder.list([])
2542
assert ("testapp/static/js/index.js", storages.root_storage) in all_files

0 commit comments

Comments
 (0)