fastled 1.0.15__py2.py3-none-any.whl → 1.1.0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastled/__init__.py +0 -3
- fastled/app.py +82 -160
- fastled/check_cpp_syntax.py +34 -0
- fastled/compile_server.py +207 -221
- fastled/docker_manager.py +7 -11
- fastled/filewatcher.py +146 -196
- fastled/open_browser.py +1 -5
- fastled/web_compile.py +173 -291
- fastled-1.1.0.dist-info/METADATA +113 -0
- fastled-1.1.0.dist-info/RECORD +18 -0
- fastled/keyboard.py +0 -91
- fastled/sketch.py +0 -55
- fastled/util.py +0 -10
- fastled-1.0.15.dist-info/METADATA +0 -196
- fastled-1.0.15.dist-info/RECORD +0 -20
- {fastled-1.0.15.dist-info → fastled-1.1.0.dist-info}/LICENSE +0 -0
- {fastled-1.0.15.dist-info → fastled-1.1.0.dist-info}/WHEEL +0 -0
- {fastled-1.0.15.dist-info → fastled-1.1.0.dist-info}/entry_points.txt +0 -0
- {fastled-1.0.15.dist-info → fastled-1.1.0.dist-info}/top_level.txt +0 -0
fastled/filewatcher.py
CHANGED
@@ -1,196 +1,146 @@
|
|
1
|
-
"""File system watcher implementation using watchdog
|
2
|
-
"""
|
3
|
-
|
4
|
-
import hashlib
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import
|
8
|
-
import
|
9
|
-
from
|
10
|
-
|
11
|
-
from
|
12
|
-
from
|
13
|
-
from
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
path
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
self.
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
self.
|
73
|
-
|
74
|
-
|
75
|
-
self.
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
self.event_handler =
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
current_time
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
return
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
changed_files.append(changed_file)
|
148
|
-
# clear all the changes from the queue
|
149
|
-
self.change_queue.queue.clear()
|
150
|
-
return changed_files
|
151
|
-
|
152
|
-
|
153
|
-
def _process_wrapper(root: Path, excluded_patterns: list[str], queue: Queue):
|
154
|
-
with open(os.devnull, "w") as fnull: # Redirect to /dev/null
|
155
|
-
with redirect_stdout(fnull):
|
156
|
-
watcher = FileChangedNotifier(
|
157
|
-
str(root), excluded_patterns=excluded_patterns
|
158
|
-
)
|
159
|
-
watcher.start()
|
160
|
-
while True:
|
161
|
-
try:
|
162
|
-
changed_files = watcher.get_all_changes()
|
163
|
-
for file in changed_files:
|
164
|
-
queue.put(file)
|
165
|
-
except KeyboardInterrupt:
|
166
|
-
break
|
167
|
-
watcher.stop()
|
168
|
-
|
169
|
-
|
170
|
-
class FileWatcherProcess:
|
171
|
-
def __init__(self, root: Path, excluded_patterns: list[str]) -> None:
|
172
|
-
self.queue: Queue = Queue()
|
173
|
-
self.process = Process(
|
174
|
-
target=_process_wrapper,
|
175
|
-
args=(root, excluded_patterns, self.queue),
|
176
|
-
daemon=True,
|
177
|
-
)
|
178
|
-
self.process.start()
|
179
|
-
|
180
|
-
def stop(self):
|
181
|
-
self.process.terminate()
|
182
|
-
self.process.join()
|
183
|
-
self.queue.close()
|
184
|
-
self.queue.join_thread()
|
185
|
-
|
186
|
-
def get_all_changes(self, timeout: float | None = None) -> list[str]:
|
187
|
-
changed_files = []
|
188
|
-
block = timeout is not None
|
189
|
-
|
190
|
-
while True:
|
191
|
-
try:
|
192
|
-
changed_file = self.queue.get(block=block, timeout=timeout)
|
193
|
-
changed_files.append(changed_file)
|
194
|
-
except Empty:
|
195
|
-
break
|
196
|
-
return changed_files
|
1
|
+
"""File system watcher implementation using watchdog
|
2
|
+
"""
|
3
|
+
|
4
|
+
import hashlib
|
5
|
+
import queue
|
6
|
+
import threading
|
7
|
+
import time
|
8
|
+
from pathlib import Path
|
9
|
+
from typing import Dict, Set
|
10
|
+
|
11
|
+
from watchdog.events import FileSystemEvent, FileSystemEventHandler
|
12
|
+
from watchdog.observers import Observer
|
13
|
+
from watchdog.observers.api import BaseObserver
|
14
|
+
|
15
|
+
|
16
|
+
class MyEventHandler(FileSystemEventHandler):
|
17
|
+
def __init__(
|
18
|
+
self,
|
19
|
+
change_queue: queue.Queue,
|
20
|
+
excluded_patterns: Set[str],
|
21
|
+
file_hashes: Dict[str, str],
|
22
|
+
) -> None:
|
23
|
+
super().__init__()
|
24
|
+
self.change_queue = change_queue
|
25
|
+
self.excluded_patterns = excluded_patterns
|
26
|
+
self.file_hashes = file_hashes
|
27
|
+
|
28
|
+
def _get_file_hash(self, filepath: str) -> str:
|
29
|
+
try:
|
30
|
+
with open(filepath, "rb") as f:
|
31
|
+
return hashlib.md5(f.read()).hexdigest()
|
32
|
+
except Exception: # pylint: disable=broad-except
|
33
|
+
return ""
|
34
|
+
|
35
|
+
def on_modified(self, event: FileSystemEvent) -> None:
|
36
|
+
if not event.is_directory:
|
37
|
+
path = Path(event.src_path)
|
38
|
+
# Check if any part of the path matches excluded patterns
|
39
|
+
if not any(part in self.excluded_patterns for part in path.parts):
|
40
|
+
new_hash = self._get_file_hash(event.src_path)
|
41
|
+
if new_hash and new_hash != self.file_hashes.get(event.src_path):
|
42
|
+
self.file_hashes[event.src_path] = new_hash
|
43
|
+
self.change_queue.put(event.src_path)
|
44
|
+
|
45
|
+
|
46
|
+
class FileChangedNotifier(threading.Thread):
|
47
|
+
"""Watches a directory for file changes and queues notifications"""
|
48
|
+
|
49
|
+
def __init__(
|
50
|
+
self,
|
51
|
+
path: str,
|
52
|
+
debounce_seconds: float = 1.0,
|
53
|
+
excluded_patterns: list[str] | None = None,
|
54
|
+
) -> None:
|
55
|
+
"""Initialize the notifier with a path to watch
|
56
|
+
|
57
|
+
Args:
|
58
|
+
path: Directory path to watch for changes
|
59
|
+
debounce_seconds: Minimum time between notifications for the same file
|
60
|
+
excluded_patterns: List of directory/file patterns to exclude from watching
|
61
|
+
"""
|
62
|
+
super().__init__(daemon=True)
|
63
|
+
self.path = path
|
64
|
+
self.observer: BaseObserver | None = None
|
65
|
+
self.event_handler: MyEventHandler | None = None
|
66
|
+
|
67
|
+
# Combine default and user-provided patterns
|
68
|
+
self.excluded_patterns = (
|
69
|
+
set(excluded_patterns) if excluded_patterns is not None else set()
|
70
|
+
)
|
71
|
+
self.stopped = False
|
72
|
+
self.change_queue: queue.Queue = queue.Queue()
|
73
|
+
self.last_notification: Dict[str, float] = {}
|
74
|
+
self.file_hashes: Dict[str, str] = {}
|
75
|
+
self.debounce_seconds = debounce_seconds
|
76
|
+
|
77
|
+
def stop(self) -> None:
|
78
|
+
"""Stop watching for changes"""
|
79
|
+
print("watcher stop")
|
80
|
+
self.stopped = True
|
81
|
+
if self.observer:
|
82
|
+
self.observer.stop()
|
83
|
+
self.observer.join()
|
84
|
+
self.observer = None
|
85
|
+
self.event_handler = None
|
86
|
+
|
87
|
+
def run(self) -> None:
|
88
|
+
"""Thread main loop - starts watching for changes"""
|
89
|
+
self.event_handler = MyEventHandler(
|
90
|
+
self.change_queue, self.excluded_patterns, self.file_hashes
|
91
|
+
)
|
92
|
+
self.observer = Observer()
|
93
|
+
self.observer.schedule(self.event_handler, self.path, recursive=True)
|
94
|
+
self.observer.start()
|
95
|
+
|
96
|
+
try:
|
97
|
+
while not self.stopped:
|
98
|
+
time.sleep(0.1)
|
99
|
+
except KeyboardInterrupt:
|
100
|
+
print("File watcher stopped by user.")
|
101
|
+
finally:
|
102
|
+
self.stop()
|
103
|
+
|
104
|
+
def get_next_change(self, timeout: float = 0.001) -> str | None:
|
105
|
+
"""Get the next file change event from the queue
|
106
|
+
|
107
|
+
Args:
|
108
|
+
timeout: How long to wait for next change in seconds
|
109
|
+
|
110
|
+
Returns:
|
111
|
+
Changed filepath or None if no change within timeout
|
112
|
+
"""
|
113
|
+
try:
|
114
|
+
filepath = self.change_queue.get(timeout=timeout)
|
115
|
+
current_time = time.time()
|
116
|
+
|
117
|
+
# Check if we've seen this file recently
|
118
|
+
last_time = self.last_notification.get(filepath, 0)
|
119
|
+
if current_time - last_time < self.debounce_seconds:
|
120
|
+
return None
|
121
|
+
|
122
|
+
self.last_notification[filepath] = current_time
|
123
|
+
return filepath
|
124
|
+
except KeyboardInterrupt:
|
125
|
+
raise
|
126
|
+
except queue.Empty:
|
127
|
+
return None
|
128
|
+
|
129
|
+
def get_all_changes(self, timeout: float = 0.001) -> list[str]:
|
130
|
+
"""Get all file change events from the queue
|
131
|
+
|
132
|
+
Args:
|
133
|
+
timeout: How long to wait for next change in seconds
|
134
|
+
|
135
|
+
Returns:
|
136
|
+
List of changed filepaths
|
137
|
+
"""
|
138
|
+
changed_files = []
|
139
|
+
while True:
|
140
|
+
changed_file = self.get_next_change(timeout=timeout)
|
141
|
+
if changed_file is None:
|
142
|
+
break
|
143
|
+
changed_files.append(changed_file)
|
144
|
+
# clear all the changes from the queue
|
145
|
+
self.change_queue.queue.clear()
|
146
|
+
return changed_files
|
fastled/open_browser.py
CHANGED
@@ -24,11 +24,7 @@ def _open_browser_python(fastled_js: Path, port: int) -> subprocess.Popen:
|
|
24
24
|
]
|
25
25
|
|
26
26
|
# Start the process
|
27
|
-
process = subprocess.Popen(
|
28
|
-
cmd,
|
29
|
-
# stdout=subprocess.DEVNULL,
|
30
|
-
stderr=subprocess.DEVNULL,
|
31
|
-
)
|
27
|
+
process = subprocess.Popen(cmd)
|
32
28
|
return process
|
33
29
|
|
34
30
|
|