Skip to content

Commit 7a3657a

Browse files
authored
Warn if INSTALLED_APPS['reactpy_django'] position looks suspicious (#181)
1 parent ceeead6 commit 7a3657a

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ Using the following categories, list your changes in this order:
3434

3535
## [Unreleased]
3636

37-
- Nothing (yet)!
37+
### Added
38+
39+
- Warning W018 (`Suspicious position of 'reactpy_django' in INSTALLED_APPS`) has been added.
3840

3941
## [3.5.0] - 2023-08-26
4042

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Follow the links below to find out more about this project.
109109
- [Documentation](https://reactive-python.github.io/reactpy-django)
110110
- [GitHub Discussions](https://github.com/reactive-python/reactpy-django/discussions)
111111
- [Discord](https://discord.gg/uNb5P4hA9X)
112-
- [Contributor Guide](https://reactive-python.github.io/reactpy-django/contribute/code/)
112+
- [Contributor Guide](https://reactive-python.github.io/reactpy-django/latest/contribute/code/)
113113
- [Code of Conduct](https://github.com/reactive-python/reactpy-django/blob/main/CODE_OF_CONDUCT.md)
114114

115115
<!--resources-end-->

src/reactpy_django/checks.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def reactpy_warnings(app_configs, **kwargs):
1717
from reactpy_django.config import REACTPY_FAILED_COMPONENTS
1818

1919
warnings = []
20+
INSTALLED_APPS: list[str] = getattr(settings, "INSTALLED_APPS", [])
2021

2122
# REACTPY_DATABASE is not an in-memory database.
2223
if (
@@ -53,10 +54,7 @@ def reactpy_warnings(app_configs, **kwargs):
5354
# Warn if REACTPY_BACKHAUL_THREAD is set to True with Daphne
5455
if (
5556
sys.argv[0].endswith("daphne")
56-
or (
57-
"runserver" in sys.argv
58-
and "daphne" in getattr(settings, "INSTALLED_APPS", [])
59-
)
57+
or ("runserver" in sys.argv and "daphne" in INSTALLED_APPS)
6058
) and getattr(settings, "REACTPY_BACKHAUL_THREAD", False):
6159
warnings.append(
6260
Warning(
@@ -72,7 +70,7 @@ def reactpy_warnings(app_configs, **kwargs):
7270
warnings.append(
7371
Warning(
7472
"ReactPy client.js could not be found within Django static files!",
75-
hint="Check your Django static file configuration.",
73+
hint="Check all static files related Django settings and INSTALLED_APPS.",
7674
id="reactpy_django.W004",
7775
)
7876
)
@@ -241,6 +239,22 @@ def reactpy_warnings(app_configs, **kwargs):
241239
)
242240
)
243241

242+
position_to_beat = 0
243+
for app in INSTALLED_APPS:
244+
if app.startswith("django.contrib."):
245+
position_to_beat = INSTALLED_APPS.index(app)
246+
if (
247+
"reactpy_django" in INSTALLED_APPS
248+
and INSTALLED_APPS.index("reactpy_django") < position_to_beat
249+
):
250+
warnings.append(
251+
Warning(
252+
"The position of 'reactpy_django' in INSTALLED_APPS is suspicious.",
253+
hint="Move 'reactpy_django' below all 'django.contrib.*' apps, or suppress this warning.",
254+
id="reactpy_django.W018",
255+
)
256+
)
257+
244258
return warnings
245259

246260

0 commit comments

Comments
 (0)