Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 480 - Add .map file extension support to dash #478

Merged
merged 8 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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.
Expand Down
21 changes: 17 additions & 4 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the preferred indentation pattern is for Python -- went with something that seemed natural with the syntax

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No () and single line, we prefer explicit: if 'dynamic' in resources and resource.get('dynamic'). Also .get over [key] to avoid unnecessary KeyErrors. Only use is for comparing pointer references, ie is None to assert null and not just falsy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this because the line is too long for flake8's taste.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I one line this and make flake8 happy? Apart from an actual function, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break them using \ at the end of the line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting the same error from pylint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And now this.. dash/dash.py:355:4: R0912: Too many branches (13/12) (too-many-branches

I guess the additional if triggered this rule.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer if cond to is True, is True is when you need to assert that it the actual True and not another type that evaluate to True in a condition like a string.

Copy link
Contributor Author

@Marc-Andre-Rivet Marc-Andre-Rivet Dec 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Misread! No need for the explicit comparison... all good haha

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add # pylint: disable=too-many-branches to the start of the function.


if 'relative_package_path' in resource:
if isinstance(resource['relative_package_path'], str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternate way might solve the too-many-branches 🐫

paths = resource['relative_package_path']
paths = [paths] if isinstance(paths, str) else paths
for rel_path in paths:
   ... the logic that is repeated twice ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.. I'm in, if only because it makes me learn the language haha!

srcs.append(_relative_url_path(**resource))
path = _relative_url_path(
resource['relative_package_path'],
resource['namespace']
)
if not is_dynamic_resource:
Marc-Andre-Rivet marked this conversation as resolved.
Show resolved Hide resolved
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here..

elif 'external_url' in resource:
if isinstance(resource['external_url'], str):
srcs.append(resource['external_url'])
Expand Down Expand Up @@ -492,7 +504,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'
Marc-Andre-Rivet marked this conversation as resolved.
Show resolved Hide resolved
})[path_in_package_dist.split('.')[-1]]
Marc-Andre-Rivet marked this conversation as resolved.
Show resolved Hide resolved

headers = {
Expand Down
2 changes: 2 additions & 0 deletions dash/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dynamic property needs to survive the sanitation process -- adding it to the list

if 'namespace' in s:
filtered_resource['namespace'] = s['namespace']
if 'external_url' in s and not self.config.serve_locally:
Expand Down
2 changes: 1 addition & 1 deletion dash/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.31.1'
__version__ = '0.31.2'