Skip to content

Commit

Permalink
Merge pull request #362 from plotly/hot-reload
Browse files Browse the repository at this point in the history
Hot reload
  • Loading branch information
T4rk1n authored Nov 14, 2018
2 parents 800b73f + d410c9c commit f590166
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .pylintrc37
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ disable=invalid-name,
no-else-return,
useless-object-inheritance,
possibly-unused-variable,
too-many-lines
too-many-lines,
too-many-statements

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.30.0 - 2018-11-14
## Added
- Hot reload from the browser [#362](https://github.com/plotly/dash/pull/362)
- Silence routes logging with `dev_tools_silence_routes_logging`.

## 0.29.0 - 2018-11-06
## Added
- 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)
Expand Down
7 changes: 6 additions & 1 deletion dash/_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ def env_configs():
'DASH_COMPONENTS_CACHE_MAX_AGE',
'DASH_INCLUDE_ASSETS_FILES',
'DASH_SERVE_DEV_BUNDLES',
'DASH_DEBUG'
'DASH_DEBUG',
'DASH_HOT_RELOAD',
'DASH_HOT_RELOAD_INTERVAL',
'DASH_HOT_RELOAD_WATCH_INTERVAL',
'DASH_HOT_RELOAD_MAX_RETRY',
'DASH_SILENCE_ROUTES_LOGGING'
)})


Expand Down
8 changes: 7 additions & 1 deletion dash/_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import uuid


def interpolate_str(template, **data):
s = template
for k, v in data.items():
Expand All @@ -20,12 +23,15 @@ def format_tag(tag_name, attributes, inner='', closed=False, opened=False):
'{}="{}"'.format(k, v) for k, v in attributes.items()]))


def generate_hash():
return str(uuid.uuid4().hex).strip('-')


def get_asset_path(
requests_pathname,
routes_pathname,
asset_path,
asset_url_path):

i = requests_pathname.rfind(routes_pathname)
req = requests_pathname[:i]

Expand Down
36 changes: 36 additions & 0 deletions dash/_watch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import collections
import os
import re
import time


def watch(folders, on_change, pattern=None, sleep_time=0.1):
pattern = re.compile(pattern) if pattern else None
watched = collections.defaultdict(lambda: -1)

def walk():
walked = []
for folder in folders:
for current, _, files, in os.walk(folder):
for f in files:
if pattern and not pattern.search(f):
continue
path = os.path.join(current, f)

info = os.stat(path)
new_time = info.st_mtime

if new_time > watched[path] > 0:
on_change(path, new_time, False)

watched[path] = new_time
walked.append(path)

# Look for deleted files
for w in [x for x in watched.keys() if x not in walked]:
del watched[w]
on_change(w, -1, True)

while True:
walk()
time.sleep(sleep_time)
Loading

0 comments on commit f590166

Please sign in to comment.