From ba52240224f211878ae4b3cbcd085c0c9aac81aa Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 28 Aug 2023 22:41:33 -0700 Subject: [PATCH 1/5] Warn if `INSTALLED_APPS['reactpy_django']` position looks suspicious --- src/reactpy_django/checks.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/reactpy_django/checks.py b/src/reactpy_django/checks.py index 754b81be..3a142f05 100644 --- a/src/reactpy_django/checks.py +++ b/src/reactpy_django/checks.py @@ -17,6 +17,7 @@ def reactpy_warnings(app_configs, **kwargs): from reactpy_django.config import REACTPY_FAILED_COMPONENTS warnings = [] + INSTALLED_APPS: list[str] = getattr(settings, "INSTALLED_APPS", []) # REACTPY_DATABASE is not an in-memory database. if ( @@ -53,10 +54,7 @@ def reactpy_warnings(app_configs, **kwargs): # Warn if REACTPY_BACKHAUL_THREAD is set to True with Daphne if ( sys.argv[0].endswith("daphne") - or ( - "runserver" in sys.argv - and "daphne" in getattr(settings, "INSTALLED_APPS", []) - ) + or ("runserver" in sys.argv and "daphne" in INSTALLED_APPS) ) and getattr(settings, "REACTPY_BACKHAUL_THREAD", False): warnings.append( Warning( @@ -72,7 +70,7 @@ def reactpy_warnings(app_configs, **kwargs): warnings.append( Warning( "ReactPy client.js could not be found within Django static files!", - hint="Check your Django static file configuration.", + hint="Check all Django settings and installed apps related to static files.", id="reactpy_django.W004", ) ) @@ -241,6 +239,23 @@ def reactpy_warnings(app_configs, **kwargs): ) ) + # Raise warning if `reactpy_django` is less than half way down installed apps + position_to_beat = 0 + for app in INSTALLED_APPS: + if app.startswith("django.contrib."): + position_to_beat = INSTALLED_APPS.index(app) + if ( + "reactpy_django" in INSTALLED_APPS + and INSTALLED_APPS.index("reactpy_django") < position_to_beat + ): + warnings.append( + Warning( + "Suspicious position of INSTALLED_APPS['reactpy_django'].", + hint="Move 'reactpy_django' below all 'django.contrib.*' apps, or suppress this warning if you know what you're doing.", + id="reactpy_django.W018", + ) + ) + return warnings From 293270b2cd943be4ab554fac4414939ec22e6aa9 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 28 Aug 2023 22:45:28 -0700 Subject: [PATCH 2/5] add changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f41b7389..e2b9c13c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,9 @@ Using the following categories, list your changes in this order: ## [Unreleased] -- Nothing (yet)! +### Added + +- Warning if the position of `INSTALLED_APPS['reactpy_django']` looks suspicious ## [3.5.0] - 2023-08-26 From b277cddf84e71f7a4776ec3c795f21421390128d Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 28 Aug 2023 22:52:46 -0700 Subject: [PATCH 3/5] fix link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 281290e3..71d8d5b6 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Follow the links below to find out more about this project. - [Documentation](https://reactive-python.github.io/reactpy-django) - [GitHub Discussions](https://github.com/reactive-python/reactpy-django/discussions) - [Discord](https://discord.gg/uNb5P4hA9X) -- [Contributor Guide](https://reactive-python.github.io/reactpy-django/contribute/code/) +- [Contributor Guide](https://reactive-python.github.io/reactpy-django/develop/contribute/code/) - [Code of Conduct](https://github.com/reactive-python/reactpy-django/blob/main/CODE_OF_CONDUCT.md) From af0f27ef80231ae7dd4ed444c9d257c76cca1f91 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Tue, 29 Aug 2023 02:04:31 -0700 Subject: [PATCH 4/5] verbiage changes --- CHANGELOG.md | 2 +- src/reactpy_django/checks.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2b9c13c..80b9d021 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,7 @@ Using the following categories, list your changes in this order: ### Added -- Warning if the position of `INSTALLED_APPS['reactpy_django']` looks suspicious +- Warning W018 (`Suspicious position of 'reactpy_django' in INSTALLED_APPS`) has been added. ## [3.5.0] - 2023-08-26 diff --git a/src/reactpy_django/checks.py b/src/reactpy_django/checks.py index 3a142f05..e7d320d6 100644 --- a/src/reactpy_django/checks.py +++ b/src/reactpy_django/checks.py @@ -70,7 +70,7 @@ def reactpy_warnings(app_configs, **kwargs): warnings.append( Warning( "ReactPy client.js could not be found within Django static files!", - hint="Check all Django settings and installed apps related to static files.", + hint="Check all static files related Django settings and INSTALLED_APPS.", id="reactpy_django.W004", ) ) @@ -239,7 +239,6 @@ def reactpy_warnings(app_configs, **kwargs): ) ) - # Raise warning if `reactpy_django` is less than half way down installed apps position_to_beat = 0 for app in INSTALLED_APPS: if app.startswith("django.contrib."): @@ -250,8 +249,8 @@ def reactpy_warnings(app_configs, **kwargs): ): warnings.append( Warning( - "Suspicious position of INSTALLED_APPS['reactpy_django'].", - hint="Move 'reactpy_django' below all 'django.contrib.*' apps, or suppress this warning if you know what you're doing.", + "The position of 'reactpy_django' in INSTALLED_APPS is suspicious.", + hint="Move 'reactpy_django' below all 'django.contrib.*' apps, or suppress this warning.", id="reactpy_django.W018", ) ) From 8eff56b11ace69b04394b5c393b99b6cae19f327 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Tue, 29 Aug 2023 02:06:31 -0700 Subject: [PATCH 5/5] use latest instead of develop link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 71d8d5b6..8e05e247 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Follow the links below to find out more about this project. - [Documentation](https://reactive-python.github.io/reactpy-django) - [GitHub Discussions](https://github.com/reactive-python/reactpy-django/discussions) - [Discord](https://discord.gg/uNb5P4hA9X) -- [Contributor Guide](https://reactive-python.github.io/reactpy-django/develop/contribute/code/) +- [Contributor Guide](https://reactive-python.github.io/reactpy-django/latest/contribute/code/) - [Code of Conduct](https://github.com/reactive-python/reactpy-django/blob/main/CODE_OF_CONDUCT.md)