35
35
from . import _watch
36
36
from ._utils import get_asset_path as _get_asset_path
37
37
from ._utils import create_callback_id as _create_callback_id
38
- from . import _configs
38
+ from ._configs import ( get_combined_config , pathname_configs )
39
39
40
40
_default_index = '''<!DOCTYPE html>
41
41
<html>
@@ -126,33 +126,29 @@ def __init__(
126
126
# allow users to supply their own flask server
127
127
self .server = server or Flask (name , static_folder = static_folder )
128
128
129
- env_configs = _configs .env_configs ()
130
-
131
129
url_base_pathname , routes_pathname_prefix , requests_pathname_prefix = \
132
- _configs . pathname_configs (
130
+ pathname_configs (
133
131
url_base_pathname ,
134
132
routes_pathname_prefix ,
135
- requests_pathname_prefix ,
136
- environ_configs = env_configs )
133
+ requests_pathname_prefix
134
+ )
137
135
138
136
self .url_base_pathname = url_base_pathname
139
137
self .config = _AttributeDict ({
140
- 'suppress_callback_exceptions' : _configs . get_config (
138
+ 'suppress_callback_exceptions' : get_combined_config (
141
139
'suppress_callback_exceptions' ,
142
- suppress_callback_exceptions , env_configs , False
143
- ),
140
+ suppress_callback_exceptions ,
141
+ False ),
144
142
'routes_pathname_prefix' : routes_pathname_prefix ,
145
143
'requests_pathname_prefix' : requests_pathname_prefix ,
146
- 'include_assets_files' : _configs .get_config (
147
- 'include_assets_files' ,
148
- include_assets_files ,
149
- env_configs ,
150
- True ),
151
- 'assets_external_path' : _configs .get_config (
152
- 'assets_external_path' , assets_external_path , env_configs , '' ),
153
- 'components_cache_max_age' : int (_configs .get_config (
154
- 'components_cache_max_age' , components_cache_max_age ,
155
- env_configs , 2678400 ))
144
+ 'include_assets_files' : get_combined_config (
145
+ 'include_assets_files' , include_assets_files , True ),
146
+ 'assets_external_path' : get_combined_config (
147
+ 'assets_external_path' , assets_external_path , '' ),
148
+ 'components_cache_max_age' : int (get_combined_config (
149
+ 'components_cache_max_age' ,
150
+ components_cache_max_age ,
151
+ 2678400 ))
156
152
})
157
153
158
154
assets_blueprint_name = '{}{}' .format (
@@ -248,6 +244,7 @@ def _handle_error(_):
248
244
'hot_reload_watch_interval' : 0.5 ,
249
245
'hot_reload_max_retry' : 8 ,
250
246
'dev_tools_ui' : False ,
247
+ 'dev_tools_props_check' : False ,
251
248
})
252
249
253
250
# add a handler for components suites errors to return 404
@@ -330,8 +327,7 @@ def serve_layout(self):
330
327
331
328
# TODO - Set browser cache limit - pass hash into frontend
332
329
return flask .Response (
333
- json .dumps (layout ,
334
- cls = plotly .utils .PlotlyJSONEncoder ),
330
+ json .dumps (layout , cls = plotly .utils .PlotlyJSONEncoder ),
335
331
mimetype = 'application/json'
336
332
)
337
333
@@ -340,6 +336,7 @@ def _config(self):
340
336
'url_base_pathname' : self .url_base_pathname ,
341
337
'requests_pathname_prefix' : self .config .requests_pathname_prefix ,
342
338
'dev_tools_ui' : self ._dev_tools .dev_tools_ui ,
339
+ 'dev_tools_props_check' : self ._dev_tools .dev_tools_props_check ,
343
340
}
344
341
if self ._dev_tools .hot_reload :
345
342
config ['hot_reload' ] = {
@@ -365,8 +362,7 @@ def serve_reload_hash(self):
365
362
366
363
def serve_routes (self ):
367
364
return flask .Response (
368
- json .dumps (self .routes ,
369
- cls = plotly .utils .PlotlyJSONEncoder ),
365
+ json .dumps (self .routes , cls = plotly .utils .PlotlyJSONEncoder ),
370
366
mimetype = 'application/json'
371
367
)
372
368
@@ -1235,9 +1231,11 @@ def _serve_default_favicon(self):
1235
1231
'Cache-Control' : 'public, max-age={}' .format (
1236
1232
self .config .components_cache_max_age )
1237
1233
}
1238
- return flask .Response (pkgutil .get_data ('dash' , 'favicon.ico' ),
1239
- headers = headers ,
1240
- content_type = 'image/x-icon' )
1234
+ return flask .Response (
1235
+ pkgutil .get_data ('dash' , 'favicon.ico' ),
1236
+ headers = headers ,
1237
+ content_type = 'image/x-icon' ,
1238
+ )
1241
1239
1242
1240
def get_asset_url (self , path ):
1243
1241
asset = _get_asset_path (
@@ -1250,6 +1248,8 @@ def get_asset_url(self, path):
1250
1248
1251
1249
def enable_dev_tools (self ,
1252
1250
debug = False ,
1251
+ dev_tools_ui = None ,
1252
+ dev_tools_props_check = None ,
1253
1253
dev_tools_serve_dev_bundles = None ,
1254
1254
dev_tools_hot_reload = None ,
1255
1255
dev_tools_hot_reload_interval = None ,
@@ -1267,6 +1267,8 @@ def enable_dev_tools(self,
1267
1267
Available dev_tools environment variables:
1268
1268
1269
1269
- DASH_DEBUG
1270
+ - DASH_DEV_TOOLS_UI
1271
+ - DASH_DEV_TOOLS_PROPS_CHECK
1270
1272
- DASH_SERVE_DEV_BUNDLES
1271
1273
- DASH_HOT_RELOAD
1272
1274
- DASH_HOT_RELOAD_INTERVAL
@@ -1278,6 +1280,11 @@ def enable_dev_tools(self,
1278
1280
disabled by the arguments or by environ variables. Available as
1279
1281
`DASH_DEBUG` environment variable.
1280
1282
:type debug: bool
1283
+ :param dev_tools_ui: Switch the dev tools UI in debugger mode
1284
+ :type dev_tools_ui: bool
1285
+ :param dev_tools_props_check: Validate the properties of
1286
+ the Dash components
1287
+ :type dev_tools_props_check: bool
1281
1288
:param dev_tools_serve_dev_bundles: Serve the dev bundles. Available
1282
1289
as `DASH_SERVE_DEV_BUNDLES` environment variable.
1283
1290
:type dev_tools_serve_dev_bundles: bool
@@ -1302,46 +1309,40 @@ def enable_dev_tools(self,
1302
1309
:type dev_tools_silence_routes_logging: bool
1303
1310
:return: debug
1304
1311
"""
1305
- env = _configs .env_configs ()
1306
- debug = debug or _configs .get_config ('debug' , None , env , debug ,
1307
- is_bool = True )
1308
-
1309
- self ._dev_tools .dev_tools_ui = debug
1312
+ debug = debug or get_combined_config ('debug' , None , debug )
1310
1313
1311
- self ._dev_tools ['serve_dev_bundles' ] = _configs .get_config (
1312
- 'serve_dev_bundles' , dev_tools_serve_dev_bundles , env ,
1313
- default = debug ,
1314
- is_bool = True
1314
+ self ._dev_tools ['dev_tools_ui' ] = get_combined_config (
1315
+ 'dev_tools_ui' , dev_tools_ui , default = debug
1315
1316
)
1316
- self ._dev_tools ['hot_reload' ] = _configs .get_config (
1317
- 'hot_reload' , dev_tools_hot_reload , env ,
1318
- default = debug ,
1319
- is_bool = True
1317
+ self ._dev_tools ['dev_tools_props_check' ] = get_combined_config (
1318
+ 'dev_tools_props_check' , dev_tools_props_check , default = debug
1320
1319
)
1321
- self ._dev_tools ['hot_reload_interval' ] = int (_configs .get_config (
1322
- 'hot_reload_interval' , dev_tools_hot_reload_interval , env ,
1323
- default = 3000
1320
+ self ._dev_tools ['serve_dev_bundles' ] = get_combined_config (
1321
+ 'serve_dev_bundles' , dev_tools_serve_dev_bundles , default = debug )
1322
+
1323
+ self ._dev_tools ['hot_reload' ] = get_combined_config (
1324
+ 'hot_reload' , dev_tools_hot_reload , default = debug )
1325
+ self ._dev_tools ['hot_reload_interval' ] = int (get_combined_config (
1326
+ 'hot_reload_interval' , dev_tools_hot_reload_interval , default = 3000
1324
1327
))
1325
1328
self ._dev_tools ['hot_reload_watch_interval' ] = float (
1326
- _configs . get_config (
1329
+ get_combined_config (
1327
1330
'hot_reload_watch_interval' ,
1328
1331
dev_tools_hot_reload_watch_interval ,
1329
- env ,
1330
1332
default = 0.5
1331
1333
)
1332
1334
)
1333
1335
self ._dev_tools ['hot_reload_max_retry' ] = int (
1334
- _configs . get_config (
1336
+ get_combined_config (
1335
1337
'hot_reload_max_retry' ,
1336
1338
dev_tools_hot_reload_max_retry ,
1337
- env ,
1338
1339
default = 8
1339
1340
)
1340
1341
)
1341
- self ._dev_tools ['silence_routes_logging' ] = _configs .get_config (
1342
- 'silence_routes_logging' , dev_tools_silence_routes_logging , env ,
1342
+ self ._dev_tools ['silence_routes_logging' ] = get_combined_config (
1343
+ 'silence_routes_logging' ,
1344
+ dev_tools_silence_routes_logging ,
1343
1345
default = debug ,
1344
- is_bool = True ,
1345
1346
)
1346
1347
1347
1348
if self ._dev_tools .silence_routes_logging :
@@ -1425,6 +1426,8 @@ def delete_resource(resources):
1425
1426
def run_server (self ,
1426
1427
port = 8050 ,
1427
1428
debug = False ,
1429
+ dev_tools_ui = None ,
1430
+ dev_tools_props_check = None ,
1428
1431
dev_tools_serve_dev_bundles = None ,
1429
1432
dev_tools_hot_reload = None ,
1430
1433
dev_tools_hot_reload_interval = None ,
@@ -1440,6 +1443,11 @@ def run_server(self,
1440
1443
:type port: int
1441
1444
:param debug: Set the debug mode of flask and enable the dev tools.
1442
1445
:type debug: bool
1446
+ :param dev_tools_ui: Switch the dev tools UI in debugger mode
1447
+ :type dev_tools_ui: bool
1448
+ :param dev_tools_props_check: Validate the properties of
1449
+ the Dash components
1450
+ :type dev_tools_props_check: bool
1443
1451
:param dev_tools_serve_dev_bundles: Serve the dev bundles of components
1444
1452
:type dev_tools_serve_dev_bundles: bool
1445
1453
:param dev_tools_hot_reload: Enable the hot reload.
@@ -1458,6 +1466,8 @@ def run_server(self,
1458
1466
"""
1459
1467
debug = self .enable_dev_tools (
1460
1468
debug ,
1469
+ dev_tools_ui ,
1470
+ dev_tools_props_check ,
1461
1471
dev_tools_serve_dev_bundles ,
1462
1472
dev_tools_hot_reload ,
1463
1473
dev_tools_hot_reload_interval ,
@@ -1483,10 +1493,6 @@ def run_server(self,
1483
1493
for _ in range (3 ))
1484
1494
)
1485
1495
1486
- self .logger .info (
1487
- 'Debugger PIN: %s' ,
1488
- debugger_pin
1489
- )
1496
+ self .logger .info ('Debugger PIN: %s' , debugger_pin )
1490
1497
1491
- self .server .run (port = port , debug = debug ,
1492
- ** flask_run_options )
1498
+ self .server .run (port = port , debug = debug , ** flask_run_options )
0 commit comments