Skip to content

Commit 6150ec5

Browse files
author
Marc-André Rivet
committed
Merge remote-tracking branch 'origin/dev'
2 parents 5fd4e71 + 8e0c80d commit 6150ec5

File tree

5 files changed

+128
-56
lines changed

5 files changed

+128
-56
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to `dash` will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [1.5.1] - 2019-10-29
6+
### Fixed
7+
- [#987](https://github.com/plotly/dash/pull/987) Fix cache string handling for component suites with nested folders in their packages.
8+
- [#986](https://github.com/plotly/dash/pull/986) Fix a bug with evaluation of `_force_eager_loading` when application is loaded with gunicorn
9+
510
## [1.5.0] - 2019-10-29
611
### Added
712
- [#964](https://github.com/plotly/dash/pull/964) Adds support for preventing updates in clientside functions.

dash/dash.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,6 @@ def __init__(
229229
plugins=None,
230230
**obsolete
231231
):
232-
# Apply _force_eager_loading overrides from modules
233-
for module_name in ComponentRegistry.registry:
234-
module = sys.modules[module_name]
235-
eager = getattr(module, '_force_eager_loading', False)
236-
eager_loading = eager_loading or eager
237-
238232
for key in obsolete:
239233
if key in ["components_cache_max_age", "static_folder"]:
240234
raise exceptions.ObsoleteKwargException(
@@ -272,6 +266,7 @@ def __init__(
272266
assets_external_path=get_combined_config(
273267
"assets_external_path", assets_external_path, ""
274268
),
269+
eager_loading=eager_loading,
275270
include_assets_files=get_combined_config(
276271
"include_assets_files", include_assets_files, True
277272
),
@@ -1434,6 +1429,16 @@ def _validate_layout(self):
14341429
component_ids.add(component_id)
14351430

14361431
def _setup_server(self):
1432+
# Apply _force_eager_loading overrides from modules
1433+
eager_loading = self.config.eager_loading
1434+
for module_name in ComponentRegistry.registry:
1435+
module = sys.modules[module_name]
1436+
eager = getattr(module, '_force_eager_loading', False)
1437+
eager_loading = eager_loading or eager
1438+
1439+
# Update eager_loading settings
1440+
self.scripts.config.eager_loading = eager_loading
1441+
14371442
if self.config.include_assets_files:
14381443
self._walk_assets_directory()
14391444

dash/fingerprint.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
import re
22

3-
build_regex = re.compile(r'^(?P<filename>[\w@~-]+)(?P<extension>.*)$')
4-
5-
check_regex = re.compile(
6-
r'^(?P<filename>.*)[.]v[\w-]+m[0-9a-fA-F]+(?P<extension>(?:(?:(?<![.])[.])?[\w])+)$'
7-
)
3+
cache_regex = re.compile(r"^v[\w-]+m[0-9a-fA-F]+$")
84

95

106
def build_fingerprint(path, version, hash_value):
11-
res = build_regex.match(path)
7+
path_parts = path.split("/")
8+
filename, extension = path_parts[-1].split(".", 1)
129

13-
return '{}.v{}m{}{}'.format(
14-
res.group('filename'),
15-
str(version).replace('.', '_'),
10+
return "{}.v{}m{}.{}".format(
11+
"/".join(path_parts[:-1] + [filename]),
12+
str(version).replace(".", "_"),
1613
hash_value,
17-
res.group('extension'),
14+
extension,
1815
)
1916

2017

2118
def check_fingerprint(path):
19+
path_parts = path.split("/")
20+
name_parts = path_parts[-1].split(".")
21+
2222
# Check if the resource has a fingerprint
23-
res = check_regex.match(path)
24-
25-
# Resolve real resource name from fingerprinted resource path
26-
return (
27-
res.group('filename') + res.group('extension')
28-
if res is not None
29-
else path,
30-
res is not None,
31-
)
23+
if len(name_parts) > 2 and cache_regex.match(name_parts[1]):
24+
original_name = ".".join([name_parts[0]] + name_parts[2:])
25+
return "/".join(path_parts[:-1] + [original_name]), True
26+
27+
return path, False

dash/version.py

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

tests/unit/test_fingerprint.py

Lines changed: 96 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,122 @@
1-
21
from dash.fingerprint import build_fingerprint, check_fingerprint
32

43
version = 1
54
hash_value = 1
65

76
valid_resources = [
8-
{'path': '[email protected]', 'fingerprint': '[email protected]'},
9-
{'path': '[email protected]', 'fingerprint': '[email protected]_1_1m1234567890abcdef.8.6.min.js', 'version': '1.1.1', 'hash': '1234567890abcdef' },
10-
{'path': '[email protected]', 'fingerprint': '[email protected]_1_1-alpha_1m1234567890abcdef.8.6.min.js', 'version': '1.1.1-alpha.1', 'hash': '1234567890abcdef' },
11-
{'path': 'dash.plotly.js', 'fingerprint': 'dash.v1m1.plotly.js'},
12-
{'path': 'dash.plotly.j_s', 'fingerprint': 'dash.v1m1.plotly.j_s'},
13-
{'path': 'dash.plotly.css', 'fingerprint': 'dash.v1m1.plotly.css'},
14-
{'path': 'dash.plotly.xxx.yyy.zzz', 'fingerprint': 'dash.v1m1.plotly.xxx.yyy.zzz'},
15-
{'path': 'dash~plotly.js', 'fingerprint': 'dash~plotly.v1m1.js'}
7+
{"path": "[email protected]", "fingerprint": "[email protected]"},
8+
{
9+
"path": "[email protected]",
10+
"fingerprint": "[email protected]_1_1m1234567890abcdef.8.6.min.js",
11+
"version": "1.1.1",
12+
"hash": "1234567890abcdef",
13+
},
14+
{
15+
"path": "[email protected]",
16+
"fingerprint": "[email protected]_1_1-alpha_1m1234567890abcdef.8.6.min.js",
17+
"version": "1.1.1-alpha.1",
18+
"hash": "1234567890abcdef",
19+
},
20+
{"path": "dash.plotly.js", "fingerprint": "dash.v1m1.plotly.js"},
21+
{"path": "dash.plotly.j_s", "fingerprint": "dash.v1m1.plotly.j_s"},
22+
{"path": "dash.plotly.css", "fingerprint": "dash.v1m1.plotly.css"},
23+
{"path": "dash.plotly.xxx.yyy.zzz", "fingerprint": "dash.v1m1.plotly.xxx.yyy.zzz"},
24+
{"path": "dash~plotly.js", "fingerprint": "dash~plotly.v1m1.js"},
25+
{"path": "nested/folder/file.js", "fingerprint": "nested/folder/file.v1m1.js"},
26+
{
27+
# kind of pathological, but we have what looks like a version string
28+
# in a different place - still works
29+
"path": "nested.v2m2/folder/file.js",
30+
"fingerprint": "nested.v2m2/folder/file.v1m1.js"
31+
},
32+
{
33+
# even works if it gets doubled up in the right place
34+
"path": "nested/folder/file.v2m2.js",
35+
"fingerprint": "nested/folder/file.v1m1.v2m2.js"
36+
},
37+
{
38+
"path": "nested.dotted/folder.structure/file.name.css",
39+
"fingerprint": "nested.dotted/folder.structure/file.v1m1.name.css",
40+
},
41+
{
42+
"path": "dash..plotly.js",
43+
"fingerprint": "dash.v1_1_1m1234567890..plotly.js",
44+
"version": "1.1.1",
45+
"hash": "1234567890",
46+
},
47+
{
48+
"path": "dash.",
49+
"fingerprint": "dash.v1_1_1m1234567890.",
50+
"version": "1.1.1",
51+
"hash": "1234567890",
52+
},
53+
{
54+
"path": "dash..",
55+
"fingerprint": "dash.v1_1_1m1234567890..",
56+
"version": "1.1.1",
57+
"hash": "1234567890",
58+
},
59+
{
60+
"path": "dash.js.",
61+
"fingerprint": "dash.v1_1_1m1234567890.js.",
62+
"version": "1.1.1",
63+
"hash": "1234567890",
64+
},
65+
{
66+
"path": "dash.j-s",
67+
"fingerprint": "dash.v1_1_1m1234567890.j-s",
68+
"version": "1.1.1",
69+
"hash": "1234567890",
70+
},
1671
]
1772

1873
valid_fingerprints = [
19-
'[email protected]_1_2m1571771240.8.6.min.js',
20-
'dash.plotly.v1_1_1m1234567890.js',
21-
'dash.plotly.v1_1_1m1234567890.j_s',
22-
'dash.plotly.v1_1_1m1234567890.css',
23-
'dash.plotly.v1_1_1m1234567890.xxx.yyy.zzz',
24-
'dash.plotly.v1_1_1-alpha1m1234567890.js',
25-
'dash.plotly.v1_1_1-alpha_3m1234567890.js',
26-
'dash.plotly.v1_1_1m1234567890123.js',
27-
'dash.plotly.v1_1_1m4bc3.js',
28-
'dash~plotly.v1m1.js'
74+
"[email protected]_1_2m1571771240.8.6.min.js",
75+
"dash.v1_1_1m1234567890.plotly.js",
76+
"dash.v1_1_1m1234567890.plotly.j_s",
77+
"dash.v1_1_1m1234567890.plotly.css",
78+
"dash.v1_1_1m1234567890.plotly.xxx.yyy.zzz",
79+
"dash.v1_1_1-alpha1m1234567890.plotly.js",
80+
"dash.v1_1_1-alpha_3m1234567890.plotly.js",
81+
"dash.v1_1_1m1234567890123.plotly.js",
82+
"dash.v1_1_1m4bc3.plotly.js",
83+
"dash~plotly.v1m1.js",
84+
"nested/folder/file.v1m1.js",
85+
"nested.dotted/folder.structure/file.v1m1.name.css",
86+
# this one has a pattern that looks like the version string in the wrong place
87+
# AND one in the right place.
88+
"nested.v2m2/folder/file.v1m1.js",
89+
"nested.v2m2.dotted/folder.structure/file.v1m1.name.css",
2990
]
3091

3192
invalid_fingerprints = [
32-
'dash.plotly.v1_1_1m1234567890..js',
33-
'dash.plotly.v1_1_1m1234567890.',
34-
'dash.plotly.v1_1_1m1234567890..',
35-
'dash.plotly.v1_1_1m1234567890.js.',
36-
'dash.plotly.v1_1_1m1234567890.j-s'
93+
"dash.plotly.v1_1_1m1234567890.js",
94+
"folder/dash.plotly.v1_1_1m1234567890.js",
95+
"nested.v1m1/folder/file.js",
96+
"nested.v1m1.dotted/folder.structure/file.name.css",
3797
]
3898

99+
39100
def test_fingerprint():
40101
for resource in valid_resources:
41102
# The fingerprint matches expectations
42-
fingerprint = build_fingerprint(resource.get('path'), resource.get('version', version), resource.get('hash', hash_value))
43-
assert fingerprint == resource.get('fingerprint')
103+
fingerprint = build_fingerprint(
104+
resource.get("path"),
105+
resource.get("version", version),
106+
resource.get("hash", hash_value),
107+
)
108+
assert fingerprint == resource.get("fingerprint")
44109

45110
(original_path, has_fingerprint) = check_fingerprint(fingerprint)
46-
# The inverse operation returns that the fingerprint was valid and the original path
111+
# The inverse operation returns that the fingerprint was valid
112+
# and the original path
47113
assert has_fingerprint
48-
assert original_path == resource.get('path')
114+
assert original_path == resource.get("path")
49115

50116
for resource in valid_fingerprints:
51117
(_, has_fingerprint) = check_fingerprint(resource)
52-
assert has_fingerprint
118+
assert has_fingerprint, resource
53119

54120
for resource in invalid_fingerprints:
55121
(_, has_fingerprint) = check_fingerprint(resource)
56-
assert not has_fingerprint
122+
assert not has_fingerprint, resource

0 commit comments

Comments
 (0)