From 6e8cbb79157af9cd68e969f69e2df34e4b633c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Wed, 5 Dec 2018 13:06:10 -0500 Subject: [PATCH 1/8] add map file support to dash --- dash/dash.py | 3 ++- dash/version.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 3beb789871..84008ca1bf 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -492,7 +492,8 @@ def serve_component_suites(self, package_name, path_in_package_dist): mimetype = ({ 'js': 'application/JavaScript', - 'css': 'text/css' + 'css': 'text/css', + 'map': 'application/json' })[path_in_package_dist.split('.')[-1]] headers = { diff --git a/dash/version.py b/dash/version.py index 74f9490deb..a56fd27512 100644 --- a/dash/version.py +++ b/dash/version.py @@ -1 +1 @@ -__version__ = '0.31.1' +__version__ = '0.31.2' From d02047c4ae81496cb1d380936fabd17dafb6b9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Thu, 6 Dec 2018 08:30:14 -0500 Subject: [PATCH 2/8] - update changelog --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7e80c7eff..d2213e6897 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.31.2 - 2018-12-06 +## Added +- Support for .map file extension [#478](https://github.com/plotly/dash/pull/478) + ## 0.31.1 - 2018-11-29 ## Fixed - Fix `_imports_.py` indentation generation. [#473](https://github.com/plotly/dash/pull/473/files) @@ -101,7 +105,7 @@ - Take configs values from init or environ variables (Prefixed with `DASH_`). [#322](https://github.com/plotly/dash/pull/322) ## Fixed -- Take `requests_pathname_prefix` config when creating scripts tags. +- Take `requests_pathname_prefix` config when creating scripts tags. - `requests/routes_pathname_prefix` must starts and end with `/`. - `requests_pathname_prefix` must ends with `routes_pathname_prefix`. If you supplied both `requests` and `routes` pathname before this update, make sure `requests_pathname_prefix` ends with the same value as `routes_pathname_prefix`. - `url_base_pathname` set both `requests/routes` pathname, cannot supply it with either `requests` or `routes` pathname prefixes. From e9adb52b1ba7ce4f763012a6673d57cbe3b1a402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Thu, 6 Dec 2018 16:42:48 -0500 Subject: [PATCH 3/8] - add dynamic file loading support --- dash/dash.py | 19 ++++++++++++++++--- dash/resources.py | 2 ++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 84008ca1bf..8f60a52561 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -378,15 +378,27 @@ def _relative_url_path(relative_package_path='', namespace=''): srcs = [] for resource in resources: + is_dynamic_resource = ( + 'dynamic' in resource and + resource['dynamic'] is True + ) + if 'relative_package_path' in resource: if isinstance(resource['relative_package_path'], str): - srcs.append(_relative_url_path(**resource)) + path = _relative_url_path( + resource['relative_package_path'], + resource['namespace'] + ) + if not is_dynamic_resource: + srcs.append(path) else: for rel_path in resource['relative_package_path']: - srcs.append(_relative_url_path( + path = _relative_url_path( relative_package_path=rel_path, namespace=resource['namespace'] - )) + ) + if not is_dynamic_resource: + srcs.append(path) elif 'external_url' in resource: if isinstance(resource['external_url'], str): srcs.append(resource['external_url']) @@ -1029,6 +1041,7 @@ def _walk_assets_directory(self): full = os.path.join(current, f) + print(f) if f.endswith('js'): self.scripts.append_script( self._add_assets_resource(path, full)) diff --git a/dash/resources.py b/dash/resources.py index 603bd37afe..476ad33839 100644 --- a/dash/resources.py +++ b/dash/resources.py @@ -19,6 +19,8 @@ def _filter_resources(self, all_resources, dev_bundles=False): filtered_resources = [] for s in all_resources: filtered_resource = {} + if 'dynamic' in s: + filtered_resource['dynamic'] = s['dynamic'] if 'namespace' in s: filtered_resource['namespace'] = s['namespace'] if 'external_url' in s and not self.config.serve_locally: From 656e24dc956801c3f92656e5c822ac4e6c463507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Thu, 6 Dec 2018 16:47:50 -0500 Subject: [PATCH 4/8] - revert print --- dash/dash.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dash/dash.py b/dash/dash.py index 8f60a52561..1a063bc0db 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -1041,7 +1041,6 @@ def _walk_assets_directory(self): full = os.path.join(current, f) - print(f) if f.endswith('js'): self.scripts.append_script( self._add_assets_resource(path, full)) From 481d15fd640034e130588d47b75762562f6483a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Thu, 6 Dec 2018 17:03:25 -0500 Subject: [PATCH 5/8] - fix linting --- dash/dash.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 1a063bc0db..969e5328f4 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -352,6 +352,7 @@ def serve_routes(self): mimetype='application/json' ) + # pylint: disable=too-many-branches def _collect_and_register_resources(self, resources): # now needs the app context. # template in the necessary component suite JS bundles @@ -378,10 +379,8 @@ def _relative_url_path(relative_package_path='', namespace=''): srcs = [] for resource in resources: - is_dynamic_resource = ( - 'dynamic' in resource and - resource['dynamic'] is True - ) + is_dynamic_resource = 'dynamic' in resource and \ + resource.get('dynamic') if 'relative_package_path' in resource: if isinstance(resource['relative_package_path'], str): From 2f39135104f8311c5c44641b287e26166b4f5013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Thu, 6 Dec 2018 21:13:31 -0500 Subject: [PATCH 6/8] - move registration logic --- dash/dash.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 969e5328f4..86dbef3806 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -360,9 +360,6 @@ def _collect_and_register_resources(self, resources): # for cache busting def _relative_url_path(relative_package_path='', namespace=''): - # track the registered packages - self.registered_paths[namespace].add(relative_package_path) - module_path = os.path.join( os.path.dirname(sys.modules[namespace].__file__), relative_package_path) @@ -384,20 +381,24 @@ def _relative_url_path(relative_package_path='', namespace=''): if 'relative_package_path' in resource: if isinstance(resource['relative_package_path'], str): - path = _relative_url_path( - resource['relative_package_path'], - resource['namespace'] - ) + self.registered_paths[resource['namespace']]\ + .add(resource['relative_package_path']) + if not is_dynamic_resource: - srcs.append(path) + srcs.append(_relative_url_path( + resource['relative_package_path'], + resource['namespace'] + )) else: for rel_path in resource['relative_package_path']: - path = _relative_url_path( - relative_package_path=rel_path, - namespace=resource['namespace'] - ) + self.registered_paths[resource['namespace']]\ + .add(rel_path) + if not is_dynamic_resource: - srcs.append(path) + srcs.append(_relative_url_path( + relative_package_path=rel_path, + namespace=resource['namespace'] + )) elif 'external_url' in resource: if isinstance(resource['external_url'], str): srcs.append(resource['external_url']) From 191b34b18607a1897bcd5facba2cf3bbaa7da57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Thu, 6 Dec 2018 22:11:28 -0500 Subject: [PATCH 7/8] - refactor relative package logic --- dash/dash.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 86dbef3806..a75d4c4c21 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -352,7 +352,6 @@ def serve_routes(self): mimetype='application/json' ) - # pylint: disable=too-many-branches def _collect_and_register_resources(self, resources): # now needs the app context. # template in the necessary component suite JS bundles @@ -376,29 +375,21 @@ def _relative_url_path(relative_package_path='', namespace=''): srcs = [] for resource in resources: - is_dynamic_resource = 'dynamic' in resource and \ - resource.get('dynamic') + is_dynamic_resource = resource.get('dynamic', False) if 'relative_package_path' in resource: - if isinstance(resource['relative_package_path'], str): + paths = resource['relative_package_path'] + paths = [paths] if isinstance(paths, str) else paths + + for rel_path in paths: self.registered_paths[resource['namespace']]\ - .add(resource['relative_package_path']) + .add(rel_path) if not is_dynamic_resource: srcs.append(_relative_url_path( - resource['relative_package_path'], - resource['namespace'] + relative_package_path=rel_path, + namespace=resource['namespace'] )) - else: - for rel_path in resource['relative_package_path']: - self.registered_paths[resource['namespace']]\ - .add(rel_path) - - if not is_dynamic_resource: - srcs.append(_relative_url_path( - relative_package_path=rel_path, - namespace=resource['namespace'] - )) elif 'external_url' in resource: if isinstance(resource['external_url'], str): srcs.append(resource['external_url']) From c4f4c49274b13446f5058ccc18f04e2b131f7257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Fri, 7 Dec 2018 11:08:30 -0500 Subject: [PATCH 8/8] - changing vesion bump from patch to minor - update changelog with dynamic --- CHANGELOG.md | 4 ++-- dash/version.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2213e6897..6566d3d0d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ -## 0.31.2 - 2018-12-06 +## 0.32.0 - 2018-12-07 ## Added -- Support for .map file extension [#478](https://github.com/plotly/dash/pull/478) +- Support for .map file extension and dynamic (on demand) loading [#478](https://github.com/plotly/dash/pull/478) ## 0.31.1 - 2018-11-29 ## Fixed diff --git a/dash/version.py b/dash/version.py index a56fd27512..2ef0c52ebf 100644 --- a/dash/version.py +++ b/dash/version.py @@ -1 +1 @@ -__version__ = '0.31.2' +__version__ = '0.32.0'