-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #362 from plotly/hot-reload
Hot reload
- Loading branch information
Showing
8 changed files
with
306 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.