fastled 1.0.8__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 +3 -0
- fastled/app.py +376 -0
- fastled/assets/example.txt +1 -0
- fastled/build_mode.py +25 -0
- fastled/check_cpp_syntax.py +34 -0
- fastled/cli.py +16 -0
- fastled/compile_server.py +251 -0
- fastled/docker_manager.py +259 -0
- fastled/filewatcher.py +146 -0
- fastled/open_browser.py +48 -0
- fastled/paths.py +4 -0
- fastled/sketch.py +55 -0
- fastled/web_compile.py +227 -0
- fastled-1.0.8.dist-info/LICENSE +21 -0
- fastled-1.0.8.dist-info/METADATA +121 -0
- fastled-1.0.8.dist-info/RECORD +19 -0
- fastled-1.0.8.dist-info/WHEEL +6 -0
- fastled-1.0.8.dist-info/entry_points.txt +4 -0
- fastled-1.0.8.dist-info/top_level.txt +2 -0
fastled/__init__.py
ADDED
fastled/app.py
ADDED
@@ -0,0 +1,376 @@
|
|
1
|
+
"""
|
2
|
+
Uses the latest wasm compiler image to compile the FastLED sketch.
|
3
|
+
"""
|
4
|
+
|
5
|
+
import argparse
|
6
|
+
import os
|
7
|
+
import platform
|
8
|
+
import shutil
|
9
|
+
import subprocess
|
10
|
+
import sys
|
11
|
+
import tempfile
|
12
|
+
import time
|
13
|
+
from dataclasses import dataclass
|
14
|
+
from pathlib import Path
|
15
|
+
|
16
|
+
from fastled import __version__
|
17
|
+
from fastled.build_mode import BuildMode, get_build_mode
|
18
|
+
from fastled.compile_server import CompileServer, looks_like_fastled_repo
|
19
|
+
from fastled.docker_manager import DockerManager
|
20
|
+
from fastled.filewatcher import FileChangedNotifier
|
21
|
+
from fastled.open_browser import open_browser_thread
|
22
|
+
from fastled.sketch import looks_like_sketch_directory
|
23
|
+
from fastled.web_compile import web_compile
|
24
|
+
|
25
|
+
machine = platform.machine().lower()
|
26
|
+
IS_ARM: bool = "arm" in machine or "aarch64" in machine
|
27
|
+
PLATFORM_TAG: str = "-arm64" if IS_ARM else ""
|
28
|
+
CONTAINER_NAME = f"fastled-wasm-compiler{PLATFORM_TAG}"
|
29
|
+
DEFAULT_URL = "https://fastled.onrender.com"
|
30
|
+
|
31
|
+
|
32
|
+
@dataclass
|
33
|
+
class CompiledResult:
|
34
|
+
"""Dataclass to hold the result of the compilation."""
|
35
|
+
|
36
|
+
success: bool
|
37
|
+
fastled_js: str
|
38
|
+
hash_value: str | None
|
39
|
+
|
40
|
+
|
41
|
+
DOCKER = DockerManager(container_name=CONTAINER_NAME)
|
42
|
+
|
43
|
+
|
44
|
+
def parse_args() -> argparse.Namespace:
|
45
|
+
"""Parse command-line arguments."""
|
46
|
+
parser = argparse.ArgumentParser(description=f"FastLED WASM Compiler {__version__}")
|
47
|
+
parser.add_argument(
|
48
|
+
"--version", action="version", version=f"%(prog)s {__version__}"
|
49
|
+
)
|
50
|
+
parser.add_argument(
|
51
|
+
"directory",
|
52
|
+
type=str,
|
53
|
+
nargs="?",
|
54
|
+
default=None,
|
55
|
+
help="Directory containing the FastLED sketch to compile",
|
56
|
+
)
|
57
|
+
parser.add_argument(
|
58
|
+
"--just-compile",
|
59
|
+
action="store_true",
|
60
|
+
help="Just compile, skip opening the browser and watching for changes.",
|
61
|
+
)
|
62
|
+
parser.add_argument(
|
63
|
+
"--web",
|
64
|
+
"-w",
|
65
|
+
type=str,
|
66
|
+
nargs="?",
|
67
|
+
# const does not seem to be working as expected
|
68
|
+
const=DEFAULT_URL, # Default value when --web is specified without value
|
69
|
+
help="Use web compiler. Optional URL can be provided (default: https://fastled.onrender.com)",
|
70
|
+
)
|
71
|
+
parser.add_argument(
|
72
|
+
"-i",
|
73
|
+
"--interactive",
|
74
|
+
action="store_true",
|
75
|
+
help="Run in interactive mode (Not available with --web)",
|
76
|
+
)
|
77
|
+
parser.add_argument(
|
78
|
+
"--profile",
|
79
|
+
action="store_true",
|
80
|
+
help="Enable profiling for web compilation",
|
81
|
+
)
|
82
|
+
build_mode = parser.add_mutually_exclusive_group()
|
83
|
+
build_mode.add_argument("--debug", action="store_true", help="Build in debug mode")
|
84
|
+
build_mode.add_argument(
|
85
|
+
"--quick",
|
86
|
+
action="store_true",
|
87
|
+
default=True,
|
88
|
+
help="Build in quick mode (default)",
|
89
|
+
)
|
90
|
+
build_mode.add_argument(
|
91
|
+
"--release", action="store_true", help="Build in release mode"
|
92
|
+
)
|
93
|
+
build_mode.add_argument(
|
94
|
+
"--server",
|
95
|
+
action="store_true",
|
96
|
+
help="Run the server in the current directory, volume mapping fastled if we are in the repo",
|
97
|
+
)
|
98
|
+
|
99
|
+
build_mode.add_argument(
|
100
|
+
"--force-compile",
|
101
|
+
action="store_true",
|
102
|
+
help="Skips the test to see if the current directory is a valid FastLED sketch directory",
|
103
|
+
)
|
104
|
+
|
105
|
+
args = parser.parse_args()
|
106
|
+
if args.server and args.web:
|
107
|
+
parser.error("--server and --web are mutually exclusive")
|
108
|
+
if args.directory is None and not args.server:
|
109
|
+
# does current directory look like a sketch?
|
110
|
+
maybe_sketch_dir = Path(os.getcwd())
|
111
|
+
if looks_like_sketch_directory(maybe_sketch_dir):
|
112
|
+
args.directory = str(maybe_sketch_dir)
|
113
|
+
else:
|
114
|
+
print(
|
115
|
+
"\nYou either need to specify a sketch directory or run in --server mode."
|
116
|
+
)
|
117
|
+
sys.exit(1)
|
118
|
+
return args
|
119
|
+
|
120
|
+
|
121
|
+
def run_web_compiler(
|
122
|
+
directory: Path,
|
123
|
+
host: str,
|
124
|
+
build_mode: BuildMode,
|
125
|
+
profile: bool,
|
126
|
+
last_hash_value: str | None,
|
127
|
+
) -> CompiledResult:
|
128
|
+
input_dir = Path(directory)
|
129
|
+
output_dir = input_dir / "fastled_js"
|
130
|
+
start = time.time()
|
131
|
+
web_result = web_compile(
|
132
|
+
directory=input_dir, host=host, build_mode=build_mode, profile=profile
|
133
|
+
)
|
134
|
+
diff = time.time() - start
|
135
|
+
if not web_result.success:
|
136
|
+
print("\nWeb compilation failed:")
|
137
|
+
print(f"Time taken: {diff:.2f} seconds")
|
138
|
+
print(web_result.stdout)
|
139
|
+
return CompiledResult(success=False, fastled_js="", hash_value=None)
|
140
|
+
|
141
|
+
def print_results() -> None:
|
142
|
+
hash_value = (
|
143
|
+
web_result.hash_value
|
144
|
+
if web_result.hash_value is not None
|
145
|
+
else "NO HASH VALUE"
|
146
|
+
)
|
147
|
+
print(
|
148
|
+
f"\nWeb compilation successful\n Time: {diff:.2f}\n output: {output_dir}\n hash: {hash_value}\n zip size: {len(web_result.zip_bytes)} bytes"
|
149
|
+
)
|
150
|
+
|
151
|
+
# now check to see if the hash value is the same as the last hash value
|
152
|
+
if last_hash_value is not None and last_hash_value == web_result.hash_value:
|
153
|
+
print("\nSkipping redeploy: No significant changes found.")
|
154
|
+
print_results()
|
155
|
+
return CompiledResult(
|
156
|
+
success=True, fastled_js=str(output_dir), hash_value=web_result.hash_value
|
157
|
+
)
|
158
|
+
|
159
|
+
# Extract zip contents to fastled_js directory
|
160
|
+
output_dir.mkdir(exist_ok=True)
|
161
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
162
|
+
temp_path = Path(temp_dir)
|
163
|
+
temp_zip = temp_path / "result.zip"
|
164
|
+
temp_zip.write_bytes(web_result.zip_bytes)
|
165
|
+
|
166
|
+
# Clear existing contents
|
167
|
+
shutil.rmtree(output_dir, ignore_errors=True)
|
168
|
+
output_dir.mkdir(exist_ok=True)
|
169
|
+
|
170
|
+
# Extract zip contents
|
171
|
+
shutil.unpack_archive(temp_zip, output_dir, "zip")
|
172
|
+
|
173
|
+
print(web_result.stdout)
|
174
|
+
print_results()
|
175
|
+
return CompiledResult(
|
176
|
+
success=True, fastled_js=str(output_dir), hash_value=web_result.hash_value
|
177
|
+
)
|
178
|
+
|
179
|
+
|
180
|
+
def _try_start_server_or_get_url(args: argparse.Namespace) -> str | CompileServer:
|
181
|
+
if args.web:
|
182
|
+
if isinstance(args.web, str):
|
183
|
+
return args.web
|
184
|
+
if isinstance(args.web, bool):
|
185
|
+
return DEFAULT_URL
|
186
|
+
return args.web
|
187
|
+
else:
|
188
|
+
try:
|
189
|
+
compile_server = CompileServer()
|
190
|
+
print("Waiting for the local compiler to start...")
|
191
|
+
if not compile_server.wait_for_startup():
|
192
|
+
print("Failed to start local compiler.")
|
193
|
+
raise RuntimeError("Failed to start local compiler.")
|
194
|
+
return compile_server
|
195
|
+
except KeyboardInterrupt:
|
196
|
+
raise
|
197
|
+
except RuntimeError:
|
198
|
+
print("Failed to start local compile server, using web compiler instead.")
|
199
|
+
return DEFAULT_URL
|
200
|
+
|
201
|
+
|
202
|
+
def run_client(args: argparse.Namespace) -> int:
|
203
|
+
compile_server: CompileServer | None = None
|
204
|
+
open_web_browser = not args.just_compile
|
205
|
+
profile = args.profile
|
206
|
+
if not args.force_compile and not looks_like_sketch_directory(Path(args.directory)):
|
207
|
+
print(
|
208
|
+
"Error: Not a valid FastLED sketch directory, if you are sure it is, use --force-compile"
|
209
|
+
)
|
210
|
+
return 1
|
211
|
+
|
212
|
+
# If not explicitly using web compiler, check Docker installation
|
213
|
+
if not args.web and not DOCKER.is_docker_installed():
|
214
|
+
print(
|
215
|
+
"\nDocker is not installed on this system - switching to web compiler instead."
|
216
|
+
)
|
217
|
+
args.web = True
|
218
|
+
|
219
|
+
url: str
|
220
|
+
try:
|
221
|
+
try:
|
222
|
+
url_or_server: str | CompileServer = _try_start_server_or_get_url(args)
|
223
|
+
if isinstance(url_or_server, str):
|
224
|
+
print(f"Found URL: {url_or_server}")
|
225
|
+
url = url_or_server
|
226
|
+
else:
|
227
|
+
compile_server = url_or_server
|
228
|
+
print(f"Server started at {compile_server.url()}")
|
229
|
+
url = compile_server.url()
|
230
|
+
except KeyboardInterrupt:
|
231
|
+
print("\nExiting from first try...")
|
232
|
+
if compile_server:
|
233
|
+
compile_server.stop()
|
234
|
+
return 1
|
235
|
+
except Exception as e:
|
236
|
+
print(f"Error: {e}")
|
237
|
+
return 1
|
238
|
+
build_mode: BuildMode = get_build_mode(args)
|
239
|
+
|
240
|
+
def compile_function(
|
241
|
+
url: str = url,
|
242
|
+
build_mode: BuildMode = build_mode,
|
243
|
+
profile: bool = profile,
|
244
|
+
last_hash_value: str | None = None,
|
245
|
+
) -> CompiledResult:
|
246
|
+
return run_web_compiler(
|
247
|
+
args.directory,
|
248
|
+
host=url,
|
249
|
+
build_mode=build_mode,
|
250
|
+
profile=profile,
|
251
|
+
last_hash_value=last_hash_value,
|
252
|
+
)
|
253
|
+
|
254
|
+
result: CompiledResult = compile_function(last_hash_value=None)
|
255
|
+
last_compiled_result: CompiledResult = result
|
256
|
+
|
257
|
+
if not result.success:
|
258
|
+
print("\nCompilation failed.")
|
259
|
+
return 1
|
260
|
+
|
261
|
+
browser_proc: subprocess.Popen | None = None
|
262
|
+
if open_web_browser:
|
263
|
+
browser_proc = open_browser_thread(Path(args.directory) / "fastled_js")
|
264
|
+
else:
|
265
|
+
print(
|
266
|
+
"\nCompilation successful. Run without --just-compile to open in browser and watch for changes."
|
267
|
+
)
|
268
|
+
if compile_server:
|
269
|
+
print("Shutting down compile server...")
|
270
|
+
compile_server.stop()
|
271
|
+
return 0
|
272
|
+
|
273
|
+
if args.just_compile:
|
274
|
+
if compile_server:
|
275
|
+
compile_server.stop()
|
276
|
+
if browser_proc:
|
277
|
+
browser_proc.kill()
|
278
|
+
return 0 if result.success else 1
|
279
|
+
except KeyboardInterrupt:
|
280
|
+
print("\nExiting from main")
|
281
|
+
if compile_server:
|
282
|
+
compile_server.stop()
|
283
|
+
return 1
|
284
|
+
|
285
|
+
# Watch mode
|
286
|
+
print("\nWatching for changes. Press Ctrl+C to stop...")
|
287
|
+
watcher = FileChangedNotifier(args.directory, excluded_patterns=["fastled_js"])
|
288
|
+
watcher.start()
|
289
|
+
|
290
|
+
try:
|
291
|
+
while True:
|
292
|
+
try:
|
293
|
+
changed_files = watcher.get_all_changes()
|
294
|
+
except KeyboardInterrupt:
|
295
|
+
print("\nExiting from watcher...")
|
296
|
+
raise
|
297
|
+
except Exception as e:
|
298
|
+
print(f"Error getting changes: {e}")
|
299
|
+
changed_files = []
|
300
|
+
if changed_files:
|
301
|
+
print(f"\nChanges detected in {changed_files}")
|
302
|
+
last_hash_value = last_compiled_result.hash_value
|
303
|
+
result = compile_function(last_hash_value=last_hash_value)
|
304
|
+
if not result.success:
|
305
|
+
print("\nRecompilation failed.")
|
306
|
+
else:
|
307
|
+
print("\nRecompilation successful.")
|
308
|
+
time.sleep(0.3)
|
309
|
+
except KeyboardInterrupt:
|
310
|
+
watcher.stop()
|
311
|
+
print("\nStopping watch mode...")
|
312
|
+
return 0
|
313
|
+
except Exception as e:
|
314
|
+
watcher.stop()
|
315
|
+
print(f"Error: {e}")
|
316
|
+
return 1
|
317
|
+
finally:
|
318
|
+
watcher.stop()
|
319
|
+
if compile_server:
|
320
|
+
compile_server.stop()
|
321
|
+
if browser_proc:
|
322
|
+
browser_proc.kill()
|
323
|
+
|
324
|
+
|
325
|
+
def run_server(args: argparse.Namespace) -> int:
|
326
|
+
interactive = args.interactive
|
327
|
+
compile_server = CompileServer(interactive=interactive)
|
328
|
+
if not interactive:
|
329
|
+
print(f"Server started at {compile_server.url()}")
|
330
|
+
compile_server.wait_for_startup()
|
331
|
+
try:
|
332
|
+
while True:
|
333
|
+
if not compile_server.proceess_running():
|
334
|
+
print("Server process is not running. Exiting...")
|
335
|
+
return 1
|
336
|
+
time.sleep(1)
|
337
|
+
except KeyboardInterrupt:
|
338
|
+
print("\nExiting from server...")
|
339
|
+
return 1
|
340
|
+
finally:
|
341
|
+
compile_server.stop()
|
342
|
+
return 0
|
343
|
+
|
344
|
+
|
345
|
+
def main() -> int:
|
346
|
+
args = parse_args()
|
347
|
+
target_dir = Path(args.directory)
|
348
|
+
cwd_is_target_dir = target_dir == Path(os.getcwd())
|
349
|
+
force_server = cwd_is_target_dir and looks_like_fastled_repo(target_dir)
|
350
|
+
auto_server = (args.server or args.interactive or cwd_is_target_dir) and (
|
351
|
+
not args.web and not args.just_compile
|
352
|
+
)
|
353
|
+
if auto_server or force_server:
|
354
|
+
print("Running in server only mode.")
|
355
|
+
return run_server(args)
|
356
|
+
else:
|
357
|
+
print("Running in client/server mode.")
|
358
|
+
return run_client(args)
|
359
|
+
|
360
|
+
|
361
|
+
if __name__ == "__main__":
|
362
|
+
try:
|
363
|
+
project_root = Path(__file__).resolve().parent.parent.parent
|
364
|
+
print(f"Project root: {project_root}")
|
365
|
+
os.chdir(project_root)
|
366
|
+
os.chdir("../fastled")
|
367
|
+
sys.argv.append("examples/wasm")
|
368
|
+
sys.argv.append("--server")
|
369
|
+
sys.argv.append("--interactive")
|
370
|
+
sys.exit(main())
|
371
|
+
except KeyboardInterrupt:
|
372
|
+
print("\nExiting from main...")
|
373
|
+
sys.exit(1)
|
374
|
+
except Exception as e:
|
375
|
+
print(f"Error: {e}")
|
376
|
+
sys.exit(1)
|
@@ -0,0 +1 @@
|
|
1
|
+
Example assets that will be deployed with python code.
|
fastled/build_mode.py
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
import argparse
|
2
|
+
from enum import Enum
|
3
|
+
|
4
|
+
|
5
|
+
class BuildMode(Enum):
|
6
|
+
DEBUG = "DEBUG"
|
7
|
+
QUICK = "QUICK"
|
8
|
+
RELEASE = "RELEASE"
|
9
|
+
|
10
|
+
@classmethod
|
11
|
+
def from_string(cls, mode_str: str) -> "BuildMode":
|
12
|
+
try:
|
13
|
+
return cls[mode_str.upper()]
|
14
|
+
except KeyError:
|
15
|
+
valid_modes = [mode.name for mode in cls]
|
16
|
+
raise ValueError(f"BUILD_MODE must be one of {valid_modes}, got {mode_str}")
|
17
|
+
|
18
|
+
|
19
|
+
def get_build_mode(args: argparse.Namespace) -> BuildMode:
|
20
|
+
if args.debug:
|
21
|
+
return BuildMode.DEBUG
|
22
|
+
elif args.release:
|
23
|
+
return BuildMode.RELEASE
|
24
|
+
else:
|
25
|
+
return BuildMode.QUICK
|
@@ -0,0 +1,34 @@
|
|
1
|
+
from pygments import lex
|
2
|
+
from pygments.lexers import CppLexer
|
3
|
+
from pygments.token import Token
|
4
|
+
|
5
|
+
|
6
|
+
def check_cpp_syntax(code):
|
7
|
+
try:
|
8
|
+
# Tokenize the code to check for basic syntax issues
|
9
|
+
for token_type, token_value in lex(code, CppLexer()):
|
10
|
+
if token_type == Token.Error:
|
11
|
+
print(f"Syntax error detected: {token_value}")
|
12
|
+
return False
|
13
|
+
print("No syntax errors detected.")
|
14
|
+
return True
|
15
|
+
except Exception as e:
|
16
|
+
print(f"Error during syntax check: {e}")
|
17
|
+
return False
|
18
|
+
|
19
|
+
|
20
|
+
def main():
|
21
|
+
file_path = input("Enter the path to your C++ file: ")
|
22
|
+
try:
|
23
|
+
with open(file_path, "r") as file:
|
24
|
+
code = file.read()
|
25
|
+
if check_cpp_syntax(code):
|
26
|
+
print("The file can now be sent to the server.")
|
27
|
+
else:
|
28
|
+
print("Please fix the syntax errors before sending.")
|
29
|
+
except FileNotFoundError:
|
30
|
+
print("File not found. Please check the path and try again.")
|
31
|
+
|
32
|
+
|
33
|
+
if __name__ == "__main__":
|
34
|
+
main()
|
fastled/cli.py
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
"""
|
2
|
+
Main entry point.
|
3
|
+
"""
|
4
|
+
|
5
|
+
import sys
|
6
|
+
|
7
|
+
from fastled.app import main as app_main
|
8
|
+
|
9
|
+
|
10
|
+
def main() -> int:
|
11
|
+
"""Main entry point for the template_python_cmd package."""
|
12
|
+
return app_main()
|
13
|
+
|
14
|
+
|
15
|
+
if __name__ == "__main__":
|
16
|
+
sys.exit(main())
|