@@ -17,19 +17,16 @@ def reactpy_warnings(app_configs, **kwargs):
17
17
from reactpy_django .config import REACTPY_FAILED_COMPONENTS
18
18
19
19
warnings = []
20
- INSTALLED_APPS : list [str ] = getattr (settings , "INSTALLED_APPS" , [])
20
+ installed_apps : list [str ] = getattr (settings , "INSTALLED_APPS" , [])
21
21
22
22
# Check if REACTPY_DATABASE is not an in-memory database.
23
23
if (
24
- getattr (settings , "DATABASES" , {})
25
- .get (getattr (settings , "REACTPY_DATABASE" , "default" ), {})
26
- .get ("NAME" , None )
24
+ getattr (settings , "DATABASES" , {}).get (getattr (settings , "REACTPY_DATABASE" , "default" ), {}).get ("NAME" , None )
27
25
== ":memory:"
28
26
):
29
27
warnings .append (
30
28
Warning (
31
- "Using ReactPy with an in-memory database can cause unexpected "
32
- "behaviors." ,
29
+ "Using ReactPy with an in-memory database can cause unexpected behaviors." ,
33
30
hint = "Configure settings.py:DATABASES[REACTPY_DATABASE], to use a "
34
31
"multiprocessing and thread safe database." ,
35
32
id = "reactpy_django.W001" ,
@@ -52,14 +49,12 @@ def reactpy_warnings(app_configs, **kwargs):
52
49
)
53
50
54
51
# Warn if REACTPY_BACKHAUL_THREAD is set to True with Daphne
55
- if (
56
- sys .argv [0 ].endswith ("daphne" )
57
- or ("runserver" in sys .argv and "daphne" in INSTALLED_APPS )
58
- ) and getattr (settings , "REACTPY_BACKHAUL_THREAD" , False ):
52
+ if (sys .argv [0 ].endswith ("daphne" ) or ("runserver" in sys .argv and "daphne" in installed_apps )) and getattr (
53
+ settings , "REACTPY_BACKHAUL_THREAD" , False
54
+ ):
59
55
warnings .append (
60
56
Warning (
61
- "Unstable configuration detected. REACTPY_BACKHAUL_THREAD is enabled "
62
- "and you running with Daphne." ,
57
+ "Unstable configuration detected. REACTPY_BACKHAUL_THREAD is enabled and you running with Daphne." ,
63
58
hint = "Set settings.py:REACTPY_BACKHAUL_THREAD to False or use a different web server." ,
64
59
id = "reactpy_django.W003" ,
65
60
)
@@ -79,10 +74,8 @@ def reactpy_warnings(app_configs, **kwargs):
79
74
if REACTPY_FAILED_COMPONENTS :
80
75
warnings .append (
81
76
Warning (
82
- "ReactPy failed to register the following components:\n \t + "
83
- + "\n \t + " .join (REACTPY_FAILED_COMPONENTS ),
84
- hint = "Check if these paths are valid, or if an exception is being "
85
- "raised during import." ,
77
+ "ReactPy failed to register the following components:\n \t + " + "\n \t + " .join (REACTPY_FAILED_COMPONENTS ),
78
+ hint = "Check if these paths are valid, or if an exception is being raised during import." ,
86
79
id = "reactpy_django.W005" ,
87
80
)
88
81
)
@@ -106,10 +99,8 @@ def reactpy_warnings(app_configs, **kwargs):
106
99
107
100
# Check if REACTPY_URL_PREFIX is being used properly in our HTTP URLs
108
101
with contextlib .suppress (NoReverseMatch ):
109
- full_path = reverse ("reactpy:web_modules" , kwargs = {"file" : "example" }).strip (
110
- "/"
111
- )
112
- reactpy_http_prefix = f'{ full_path [: full_path .find ("web_module/" )].strip ("/" )} '
102
+ full_path = reverse ("reactpy:web_modules" , kwargs = {"file" : "example" }).strip ("/" )
103
+ reactpy_http_prefix = f"{ full_path [: full_path .find ('web_module/' )].strip ('/' )} "
113
104
if reactpy_http_prefix != config .REACTPY_URL_PREFIX :
114
105
warnings .append (
115
106
Warning (
@@ -138,9 +129,7 @@ def reactpy_warnings(app_configs, **kwargs):
138
129
)
139
130
140
131
# Check if `daphne` is not in installed apps when using `runserver`
141
- if "runserver" in sys .argv and "daphne" not in getattr (
142
- settings , "INSTALLED_APPS" , []
143
- ):
132
+ if "runserver" in sys .argv and "daphne" not in getattr (settings , "INSTALLED_APPS" , []):
144
133
warnings .append (
145
134
Warning (
146
135
"You have not configured the `runserver` command to use ASGI. "
@@ -153,10 +142,7 @@ def reactpy_warnings(app_configs, **kwargs):
153
142
# DELETED W013: Check if deprecated value REACTPY_RECONNECT_MAX exists
154
143
155
144
# Check if REACTPY_RECONNECT_INTERVAL is set to a large value
156
- if (
157
- isinstance (config .REACTPY_RECONNECT_INTERVAL , int )
158
- and config .REACTPY_RECONNECT_INTERVAL > 30000
159
- ):
145
+ if isinstance (config .REACTPY_RECONNECT_INTERVAL , int ) and config .REACTPY_RECONNECT_INTERVAL > 30000 :
160
146
warnings .append (
161
147
Warning (
162
148
"REACTPY_RECONNECT_INTERVAL is set to >30 seconds. Are you sure this is intentional? "
@@ -167,10 +153,7 @@ def reactpy_warnings(app_configs, **kwargs):
167
153
)
168
154
169
155
# Check if REACTPY_RECONNECT_MAX_RETRIES is set to a large value
170
- if (
171
- isinstance (config .REACTPY_RECONNECT_MAX_RETRIES , int )
172
- and config .REACTPY_RECONNECT_MAX_RETRIES > 5000
173
- ):
156
+ if isinstance (config .REACTPY_RECONNECT_MAX_RETRIES , int ) and config .REACTPY_RECONNECT_MAX_RETRIES > 5000 :
174
157
warnings .append (
175
158
Warning (
176
159
"REACTPY_RECONNECT_MAX_RETRIES is set to a very large value "
@@ -204,18 +187,12 @@ def reactpy_warnings(app_configs, **kwargs):
204
187
and config .REACTPY_RECONNECT_MAX_INTERVAL > 0
205
188
and config .REACTPY_RECONNECT_MAX_RETRIES > 0
206
189
and config .REACTPY_RECONNECT_BACKOFF_MULTIPLIER > 1
207
- and (
208
- config .REACTPY_RECONNECT_BACKOFF_MULTIPLIER
209
- ** config .REACTPY_RECONNECT_MAX_RETRIES
210
- )
190
+ and (config .REACTPY_RECONNECT_BACKOFF_MULTIPLIER ** config .REACTPY_RECONNECT_MAX_RETRIES )
211
191
* config .REACTPY_RECONNECT_INTERVAL
212
192
< config .REACTPY_RECONNECT_MAX_INTERVAL
213
193
):
214
194
max_value = math .floor (
215
- (
216
- config .REACTPY_RECONNECT_BACKOFF_MULTIPLIER
217
- ** config .REACTPY_RECONNECT_MAX_RETRIES
218
- )
195
+ (config .REACTPY_RECONNECT_BACKOFF_MULTIPLIER ** config .REACTPY_RECONNECT_MAX_RETRIES )
219
196
* config .REACTPY_RECONNECT_INTERVAL
220
197
)
221
198
warnings .append (
@@ -229,13 +206,10 @@ def reactpy_warnings(app_configs, **kwargs):
229
206
230
207
# Check if 'reactpy_django' is in the correct position in INSTALLED_APPS
231
208
position_to_beat = 0
232
- for app in INSTALLED_APPS :
209
+ for app in installed_apps :
233
210
if app .startswith ("django.contrib." ):
234
- position_to_beat = INSTALLED_APPS .index (app )
235
- if (
236
- "reactpy_django" in INSTALLED_APPS
237
- and INSTALLED_APPS .index ("reactpy_django" ) < position_to_beat
238
- ):
211
+ position_to_beat = installed_apps .index (app )
212
+ if "reactpy_django" in installed_apps and installed_apps .index ("reactpy_django" ) < position_to_beat :
239
213
warnings .append (
240
214
Warning (
241
215
"The position of 'reactpy_django' in INSTALLED_APPS is suspicious." ,
@@ -276,17 +250,13 @@ def reactpy_errors(app_configs, **kwargs):
276
250
)
277
251
278
252
# DATABASE_ROUTERS is properly configured when REACTPY_DATABASE is defined
279
- if getattr (
280
- settings , "REACTPY_DATABASE" , None
281
- ) and "reactpy_django.database.Router" not in getattr (
253
+ if getattr (settings , "REACTPY_DATABASE" , None ) and "reactpy_django.database.Router" not in getattr (
282
254
settings , "DATABASE_ROUTERS" , []
283
255
):
284
256
errors .append (
285
257
Error (
286
- "ReactPy database has been changed but the database router is "
287
- "not configured." ,
288
- hint = "Set settings.py:DATABASE_ROUTERS to "
289
- "['reactpy_django.database.Router', ...]" ,
258
+ "ReactPy database has been changed but the database router is not configured." ,
259
+ hint = "Set settings.py:DATABASE_ROUTERS to ['reactpy_django.database.Router', ...]" ,
290
260
id = "reactpy_django.E002" ,
291
261
)
292
262
)
@@ -336,9 +306,7 @@ def reactpy_errors(app_configs, **kwargs):
336
306
)
337
307
338
308
# Check if REACTPY_DEFAULT_QUERY_POSTPROCESSOR is a valid data type
339
- if not isinstance (
340
- getattr (settings , "REACTPY_DEFAULT_QUERY_POSTPROCESSOR" , "" ), (str , type (None ))
341
- ):
309
+ if not isinstance (getattr (settings , "REACTPY_DEFAULT_QUERY_POSTPROCESSOR" , "" ), (str , type (None ))):
342
310
errors .append (
343
311
Error (
344
312
"Invalid type for REACTPY_DEFAULT_QUERY_POSTPROCESSOR." ,
@@ -397,10 +365,7 @@ def reactpy_errors(app_configs, **kwargs):
397
365
)
398
366
399
367
# Check if REACTPY_RECONNECT_INTERVAL is a positive integer
400
- if (
401
- isinstance (config .REACTPY_RECONNECT_INTERVAL , int )
402
- and config .REACTPY_RECONNECT_INTERVAL < 0
403
- ):
368
+ if isinstance (config .REACTPY_RECONNECT_INTERVAL , int ) and config .REACTPY_RECONNECT_INTERVAL < 0 :
404
369
errors .append (
405
370
Error (
406
371
"Invalid value for REACTPY_RECONNECT_INTERVAL." ,
@@ -420,10 +385,7 @@ def reactpy_errors(app_configs, **kwargs):
420
385
)
421
386
422
387
# Check if REACTPY_RECONNECT_MAX_INTERVAL is a positive integer
423
- if (
424
- isinstance (config .REACTPY_RECONNECT_MAX_INTERVAL , int )
425
- and config .REACTPY_RECONNECT_MAX_INTERVAL < 0
426
- ):
388
+ if isinstance (config .REACTPY_RECONNECT_MAX_INTERVAL , int ) and config .REACTPY_RECONNECT_MAX_INTERVAL < 0 :
427
389
errors .append (
428
390
Error (
429
391
"Invalid value for REACTPY_RECONNECT_MAX_INTERVAL." ,
@@ -457,10 +419,7 @@ def reactpy_errors(app_configs, **kwargs):
457
419
)
458
420
459
421
# Check if REACTPY_RECONNECT_MAX_RETRIES is a positive integer
460
- if (
461
- isinstance (config .REACTPY_RECONNECT_MAX_RETRIES , int )
462
- and config .REACTPY_RECONNECT_MAX_RETRIES < 0
463
- ):
422
+ if isinstance (config .REACTPY_RECONNECT_MAX_RETRIES , int ) and config .REACTPY_RECONNECT_MAX_RETRIES < 0 :
464
423
errors .append (
465
424
Error (
466
425
"Invalid value for REACTPY_RECONNECT_MAX_RETRIES." ,
@@ -523,10 +482,7 @@ def reactpy_errors(app_configs, **kwargs):
523
482
)
524
483
525
484
# Check if REACTPY_CLEAN_INTERVAL is a positive integer
526
- if (
527
- isinstance (config .REACTPY_CLEAN_INTERVAL , int )
528
- and config .REACTPY_CLEAN_INTERVAL < 0
529
- ):
485
+ if isinstance (config .REACTPY_CLEAN_INTERVAL , int ) and config .REACTPY_CLEAN_INTERVAL < 0 :
530
486
errors .append (
531
487
Error (
532
488
"Invalid value for REACTPY_CLEAN_INTERVAL." ,
0 commit comments