Skip to content

Commit f94991b

Browse files
authored
Merge pull request #369 from plotly/serve-unminified
Add unminified components bundle support.
2 parents e725e70 + 81d2220 commit f94991b

File tree

7 files changed

+79
-16
lines changed

7 files changed

+79
-16
lines changed

.pylintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ confidence=
5656
# --disable=W"
5757
disable=fixme,
5858
missing-docstring,
59-
invalid-name
59+
invalid-name,
60+
too-many-lines
6061
# Enable the message, report, category or checker with the given id(s). You can
6162
# either give multiple identifier separated by comma (,) or put this option
6263
# multiple time (only on the command line, not in the configuration file where

.pylintrc37

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ disable=invalid-name,
145145
comprehension-escape,
146146
no-else-return,
147147
useless-object-inheritance,
148-
possibly-unused-variable
148+
possibly-unused-variable,
149+
too-many-lines
149150

150151
# Enable the message, report, category or checker with the given id(s). You can
151152
# either give multiple identifier separated by comma (,) or put this option

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.27.0 - 2018-09-20
2+
## Added
3+
- Added support for serving dev bundles from the components suite, enable with `app.run_server(dev_tools_serve_dev_bundles=True)` [#369](https://github.com/plotly/dash/pull/369)
4+
5+
## Fixed
6+
- Use HTML5 syntax for the meta tag [#350](https://github.com/plotly/dash/pull/350)
7+
18
## 0.26.6 - 2018-09-19
29
## Fixed
310
- Added `Cache-Control` headers to files served by `Dash.serve_component_suites`. [#387](https://github.com/plotly/dash/pull/387)

dash/_configs.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@ def env_configs():
1919
'DASH_SUPPRESS_CALLBACK_EXCEPTIONS',
2020
'DASH_ASSETS_EXTERNAL_PATH',
2121
'DASH_INCLUDE_ASSETS_FILES',
22-
'DASH_COMPONENTS_CACHE_MAX_AGE'
22+
'DASH_COMPONENTS_CACHE_MAX_AGE',
23+
'DASH_INCLUDE_ASSETS_FILES',
24+
'DASH_SERVE_DEV_BUNDLES',
25+
'DASH_DEBUG'
2326
)})
2427

2528

26-
def get_config(config_name, init, env, default=None):
29+
def get_config(config_name, init, env, default=None, is_bool=False):
2730
if init is not None:
2831
return init
2932

3033
env_value = env.get('DASH_{}'.format(config_name.upper()))
3134
if env_value is None:
3235
return default
33-
return env_value
36+
return env_value if not is_bool else env_value.lower() == 'true'
3437

3538

3639
def pathname_configs(url_base_pathname=None,

dash/dash.py

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ def add_url(name, view_func, methods=('GET',)):
221221
self._layout = None
222222
self._cached_layout = None
223223
self.routes = []
224+
self._dev_tools = _AttributeDict({
225+
'serve_dev_bundles': False
226+
})
224227

225228
# add a handler for components suites errors to return 404
226229
self.server.errorhandler(exceptions.InvalidResourceError)(
@@ -373,11 +376,14 @@ def _generate_scripts_html(self):
373376
# pylint: disable=protected-access
374377
srcs = self._collect_and_register_resources(
375378
self.scripts._resources._filter_resources(
376-
dash_renderer._js_dist_dependencies
379+
dash_renderer._js_dist_dependencies,
380+
dev_bundles=self._dev_tools.serve_dev_bundles
377381
)) + self._external_scripts + self._collect_and_register_resources(
378-
self.scripts.get_all_scripts() +
382+
self.scripts.get_all_scripts(
383+
dev_bundles=self._dev_tools.serve_dev_bundles) +
379384
self.scripts._resources._filter_resources(
380-
dash_renderer._js_dist
385+
dash_renderer._js_dist,
386+
dev_bundles=self._dev_tools.serve_dev_bundles
381387
))
382388

383389
return '\n'.join([
@@ -541,7 +547,7 @@ def dependencies(self):
541547
'inputs': v['inputs'],
542548
'state': v['state'],
543549
'events': v['events']
544-
} for k, v in list(self.callback_map.items())
550+
} for k, v in self.callback_map.items()
545551
])
546552

547553
# pylint: disable=unused-argument, no-self-use
@@ -979,8 +985,49 @@ def get_asset_url(self, path):
979985

980986
return asset
981987

988+
def enable_dev_tools(self,
989+
debug=False,
990+
dev_tools_serve_dev_bundles=None):
991+
"""
992+
Activate the dev tools, called by `run_server`. If your application is
993+
served by wsgi and you want to activate the dev tools, you can call
994+
this method out of `__main__`.
995+
996+
:param debug: If True, then activate all the tools unless specified.
997+
:type debug: bool
998+
:param dev_tools_serve_dev_bundles: Serve the dev bundles.
999+
:type dev_tools_serve_dev_bundles: bool
1000+
:return:
1001+
"""
1002+
env = _configs.env_configs()
1003+
debug = debug or _configs.get_config('debug', None, env, debug,
1004+
is_bool=True)
1005+
1006+
self._dev_tools['serve_dev_bundles'] = _configs.get_config(
1007+
'serve_dev_bundles', dev_tools_serve_dev_bundles, env,
1008+
default=debug,
1009+
is_bool=True
1010+
)
1011+
return debug
1012+
9821013
def run_server(self,
9831014
port=8050,
9841015
debug=False,
1016+
dev_tools_serve_dev_bundles=None,
9851017
**flask_run_options):
986-
self.server.run(port=port, debug=debug, **flask_run_options)
1018+
"""
1019+
Start the flask server in local mode, you should not run this on a
1020+
production server and use gunicorn/waitress instead.
1021+
1022+
:param port: Port the application
1023+
:type port: int
1024+
:param debug: Set the debug mode of flask and enable the dev tools.
1025+
:type debug: bool
1026+
:param dev_tools_serve_dev_bundles: Serve the dev bundles of components
1027+
:type dev_tools_serve_dev_bundles: bool
1028+
:param flask_run_options: Given to `Flask.run`
1029+
:return:
1030+
"""
1031+
debug = self.enable_dev_tools(debug, dev_tools_serve_dev_bundles)
1032+
self.server.run(port=port, debug=debug,
1033+
**flask_run_options)

dash/resources.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ def __init__(self, resource_name, layout):
1616
def append_resource(self, resource):
1717
self._resources.append(resource)
1818

19-
def _filter_resources(self, all_resources):
19+
def _filter_resources(self, all_resources, dev_bundles=False):
2020
filtered_resources = []
2121
for s in all_resources:
2222
filtered_resource = {}
2323
if 'namespace' in s:
2424
filtered_resource['namespace'] = s['namespace']
2525
if 'external_url' in s and not self.config.serve_locally:
2626
filtered_resource['external_url'] = s['external_url']
27+
elif 'dev_package_path' in s and dev_bundles:
28+
filtered_resource['relative_package_path'] = (
29+
s['dev_package_path']
30+
)
2731
elif 'relative_package_path' in s:
2832
filtered_resource['relative_package_path'] = (
2933
s['relative_package_path']
@@ -54,7 +58,7 @@ def _filter_resources(self, all_resources):
5458

5559
return filtered_resources
5660

57-
def get_all_resources(self):
61+
def get_all_resources(self, dev_bundles=False):
5862
all_resources = []
5963
if self.config.infer_from_layout:
6064
all_resources = (
@@ -63,7 +67,7 @@ def get_all_resources(self):
6367
else:
6468
all_resources = self._resources
6569

66-
return self._filter_resources(all_resources)
70+
return self._filter_resources(all_resources, dev_bundles)
6771

6872
def get_inferred_resources(self):
6973
namespaces = []
@@ -127,8 +131,8 @@ def _update_layout(self, layout):
127131
def append_script(self, script):
128132
self._resources.append_resource(script)
129133

130-
def get_all_scripts(self):
131-
return self._resources.get_all_resources()
134+
def get_all_scripts(self, dev_bundles=False):
135+
return self._resources.get_all_resources(dev_bundles)
132136

133137
def get_inferred_scripts(self):
134138
return self._resources.get_inferred_resources()

dash/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.26.6'
1+
__version__ = '0.27.0'

0 commit comments

Comments
 (0)