Skip to content

Commit f590166

Browse files
authored
Merge pull request #362 from plotly/hot-reload
Hot reload
2 parents 800b73f + d410c9c commit f590166

File tree

8 files changed

+306
-29
lines changed

8 files changed

+306
-29
lines changed

.pylintrc37

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ disable=invalid-name,
146146
no-else-return,
147147
useless-object-inheritance,
148148
possibly-unused-variable,
149-
too-many-lines
149+
too-many-lines,
150+
too-many-statements
150151

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

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.30.0 - 2018-11-14
2+
## Added
3+
- Hot reload from the browser [#362](https://github.com/plotly/dash/pull/362)
4+
- Silence routes logging with `dev_tools_silence_routes_logging`.
5+
16
## 0.29.0 - 2018-11-06
27
## Added
38
- Added component namespaces registry, collect the resources needed by component library when they are imported instead of crawling the layout. [#444](https://github.com/plotly/dash/pull/444)

dash/_configs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ def env_configs():
2222
'DASH_COMPONENTS_CACHE_MAX_AGE',
2323
'DASH_INCLUDE_ASSETS_FILES',
2424
'DASH_SERVE_DEV_BUNDLES',
25-
'DASH_DEBUG'
25+
'DASH_DEBUG',
26+
'DASH_HOT_RELOAD',
27+
'DASH_HOT_RELOAD_INTERVAL',
28+
'DASH_HOT_RELOAD_WATCH_INTERVAL',
29+
'DASH_HOT_RELOAD_MAX_RETRY',
30+
'DASH_SILENCE_ROUTES_LOGGING'
2631
)})
2732

2833

dash/_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import uuid
2+
3+
14
def interpolate_str(template, **data):
25
s = template
36
for k, v in data.items():
@@ -20,12 +23,15 @@ def format_tag(tag_name, attributes, inner='', closed=False, opened=False):
2023
'{}="{}"'.format(k, v) for k, v in attributes.items()]))
2124

2225

26+
def generate_hash():
27+
return str(uuid.uuid4().hex).strip('-')
28+
29+
2330
def get_asset_path(
2431
requests_pathname,
2532
routes_pathname,
2633
asset_path,
2734
asset_url_path):
28-
2935
i = requests_pathname.rfind(routes_pathname)
3036
req = requests_pathname[:i]
3137

dash/_watch.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import collections
2+
import os
3+
import re
4+
import time
5+
6+
7+
def watch(folders, on_change, pattern=None, sleep_time=0.1):
8+
pattern = re.compile(pattern) if pattern else None
9+
watched = collections.defaultdict(lambda: -1)
10+
11+
def walk():
12+
walked = []
13+
for folder in folders:
14+
for current, _, files, in os.walk(folder):
15+
for f in files:
16+
if pattern and not pattern.search(f):
17+
continue
18+
path = os.path.join(current, f)
19+
20+
info = os.stat(path)
21+
new_time = info.st_mtime
22+
23+
if new_time > watched[path] > 0:
24+
on_change(path, new_time, False)
25+
26+
watched[path] = new_time
27+
walked.append(path)
28+
29+
# Look for deleted files
30+
for w in [x for x in watched.keys() if x not in walked]:
31+
del watched[w]
32+
on_change(w, -1, True)
33+
34+
while True:
35+
walk()
36+
time.sleep(sleep_time)

0 commit comments

Comments
 (0)