fastled 1.1.38__py2.py3-none-any.whl → 1.1.39__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 CHANGED
@@ -6,9 +6,10 @@ from pathlib import Path
6
6
  from typing import Generator
7
7
 
8
8
  from .compile_server import CompileServer
9
+ from .live_client import LiveClient
9
10
  from .types import BuildMode, CompileResult, CompileServerError
10
11
 
11
- __version__ = "1.1.38"
12
+ __version__ = "1.1.39"
12
13
 
13
14
 
14
15
  class Api:
@@ -46,6 +47,26 @@ class Api:
46
47
  )
47
48
  return out
48
49
 
50
+ @staticmethod
51
+ def live_client(
52
+ sketch_directory: Path,
53
+ host: str | CompileServer | None = None,
54
+ auto_start=True,
55
+ open_web_browser=True,
56
+ keep_running=True,
57
+ build_mode=BuildMode.QUICK,
58
+ profile=False,
59
+ ) -> LiveClient:
60
+ return LiveClient(
61
+ sketch_directory=sketch_directory,
62
+ host=host,
63
+ auto_start=auto_start,
64
+ open_web_browser=open_web_browser,
65
+ keep_running=keep_running,
66
+ build_mode=build_mode,
67
+ profile=profile,
68
+ )
69
+
49
70
  @staticmethod
50
71
  def spawn_server(
51
72
  sketch_directory: Path | None = None,
fastled/client_server.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import argparse
2
2
  import shutil
3
3
  import tempfile
4
+ import threading
4
5
  import time
5
6
  from multiprocessing import Process
6
7
  from pathlib import Path
@@ -12,7 +13,7 @@ from fastled.keyboard import SpaceBarWatcher
12
13
  from fastled.open_browser import open_browser_process
13
14
  from fastled.settings import DEFAULT_URL
14
15
  from fastled.sketch import looks_like_sketch_directory
15
- from fastled.types import BuildMode, CompileResult
16
+ from fastled.types import BuildMode, CompileResult, CompileServerError
16
17
  from fastled.web_compile import (
17
18
  SERVER_PORT,
18
19
  ConnectionResult,
@@ -78,7 +79,7 @@ def _run_web_compiler(
78
79
 
79
80
  def _try_start_server_or_get_url(
80
81
  auto_update: bool, args_web: str | bool, localhost: bool
81
- ) -> str | CompileServer:
82
+ ) -> tuple[str, CompileServer | None]:
82
83
  is_local_host = localhost or (
83
84
  isinstance(args_web, str)
84
85
  and ("localhost" in args_web or "127.0.0.1" in args_web)
@@ -94,16 +95,16 @@ def _try_start_server_or_get_url(
94
95
  result: ConnectionResult | None = find_good_connection(urls)
95
96
  if result is not None:
96
97
  print(f"Found local server at {result.host}")
97
- return result.host
98
+ return (result.host, None)
98
99
  else:
99
100
  local_host_needs_server = True
100
101
 
101
102
  if not local_host_needs_server and args_web:
102
103
  if isinstance(args_web, str):
103
- return args_web
104
+ return (args_web, None)
104
105
  if isinstance(args_web, bool):
105
- return DEFAULT_URL
106
- return args_web
106
+ return (DEFAULT_URL, None)
107
+ return (args_web, None)
107
108
  else:
108
109
  try:
109
110
  print("No local server found, starting one...")
@@ -111,63 +112,40 @@ def _try_start_server_or_get_url(
111
112
  print("Waiting for the local compiler to start...")
112
113
  if not compile_server.ping():
113
114
  print("Failed to start local compiler.")
114
- raise RuntimeError("Failed to start local compiler.")
115
- return compile_server
115
+ raise CompileServerError("Failed to start local compiler.")
116
+ return (compile_server.url(), compile_server)
116
117
  except KeyboardInterrupt:
117
118
  raise
118
119
  except RuntimeError:
119
120
  print("Failed to start local compile server, using web compiler instead.")
120
- return DEFAULT_URL
121
+ return (DEFAULT_URL, None)
121
122
 
122
123
 
123
- def run_client_server(args: argparse.Namespace) -> int:
124
- compile_server: CompileServer | None = None
124
+ def run_client(
125
+ directory: Path,
126
+ host: str | CompileServer | None,
127
+ open_web_browser: bool = True,
128
+ keep_running: bool = True, # if false, only one compilation will be done.
129
+ build_mode: BuildMode = BuildMode.QUICK,
130
+ profile: bool = False,
131
+ shutdown: threading.Event | None = None,
132
+ ) -> int:
133
+
134
+ compile_server: CompileServer | None = (
135
+ host if isinstance(host, CompileServer) else None
136
+ )
137
+ shutdown = shutdown or threading.Event()
125
138
 
126
- profile = bool(args.profile)
127
- web: str | bool = args.web if isinstance(args.web, str) else bool(args.web)
128
- auto_update = bool(args.auto_update)
129
- localhost = bool(args.localhost)
130
- directory = Path(args.directory)
131
- just_compile = bool(args.just_compile)
132
- interactive = bool(args.interactive)
133
- force_compile = bool(args.force_compile)
134
- open_web_browser = not just_compile and not interactive
139
+ def get_url() -> str:
140
+ if compile_server is not None:
141
+ return compile_server.url()
142
+ if isinstance(host, str):
143
+ return host
144
+ return DEFAULT_URL
135
145
 
136
- if not force_compile and not looks_like_sketch_directory(directory):
137
- print(
138
- "Error: Not a valid FastLED sketch directory, if you are sure it is, use --force-compile"
139
- )
140
- return 1
146
+ url = get_url()
141
147
 
142
- # If not explicitly using web compiler, check Docker installation
143
- if not web and not DockerManager.is_docker_installed():
144
- print(
145
- "\nDocker is not installed on this system - switching to web compiler instead."
146
- )
147
- web = True
148
-
149
- url: str
150
148
  try:
151
- try:
152
- url_or_server: str | CompileServer = _try_start_server_or_get_url(
153
- auto_update, web, localhost
154
- )
155
- if isinstance(url_or_server, str):
156
- print(f"Found URL: {url_or_server}")
157
- url = url_or_server
158
- else:
159
- compile_server = url_or_server
160
- print(f"Server started at {compile_server.url()}")
161
- url = compile_server.url()
162
- except KeyboardInterrupt:
163
- print("\nExiting from first try...")
164
- if compile_server:
165
- compile_server.stop()
166
- return 1
167
- except Exception as e:
168
- print(f"Error: {e}")
169
- return 1
170
- build_mode: BuildMode = BuildMode.from_args(args)
171
149
 
172
150
  def compile_function(
173
151
  url: str = url,
@@ -199,16 +177,12 @@ def run_client_server(args: argparse.Namespace) -> int:
199
177
  compile_server.stop()
200
178
  return 0
201
179
 
202
- if just_compile:
203
- if compile_server:
204
- compile_server.stop()
180
+ if not keep_running or shutdown.is_set():
205
181
  if browser_proc:
206
182
  browser_proc.kill()
207
183
  return 0 if result.success else 1
208
184
  except KeyboardInterrupt:
209
185
  print("\nExiting from main")
210
- if compile_server:
211
- compile_server.stop()
212
186
  return 1
213
187
 
214
188
  sketch_filewatcher = FileWatcherProcess(directory, excluded_patterns=["fastled_js"])
@@ -243,6 +217,9 @@ def run_client_server(args: argparse.Namespace) -> int:
243
217
 
244
218
  try:
245
219
  while True:
220
+ if shutdown.is_set():
221
+ print("\nStopping watch mode...")
222
+ return 0
246
223
  if SpaceBarWatcher.watch_space_bar_pressed(timeout=1.0):
247
224
  print("Compiling...")
248
225
  last_compiled_result = compile_function(last_hash_value=None)
@@ -310,3 +287,59 @@ def run_client_server(args: argparse.Namespace) -> int:
310
287
  compile_server.stop()
311
288
  if browser_proc:
312
289
  browser_proc.kill()
290
+
291
+
292
+ def run_client_server(args: argparse.Namespace) -> int:
293
+ profile = bool(args.profile)
294
+ web: str | bool = args.web if isinstance(args.web, str) else bool(args.web)
295
+ auto_update = bool(args.auto_update)
296
+ localhost = bool(args.localhost)
297
+ directory = Path(args.directory)
298
+ just_compile = bool(args.just_compile)
299
+ interactive = bool(args.interactive)
300
+ force_compile = bool(args.force_compile)
301
+ open_web_browser = not just_compile and not interactive
302
+ build_mode: BuildMode = BuildMode.from_args(args)
303
+
304
+ if not force_compile and not looks_like_sketch_directory(directory):
305
+ print(
306
+ "Error: Not a valid FastLED sketch directory, if you are sure it is, use --force-compile"
307
+ )
308
+ return 1
309
+
310
+ # If not explicitly using web compiler, check Docker installation
311
+ if not web and not DockerManager.is_docker_installed():
312
+ print(
313
+ "\nDocker is not installed on this system - switching to web compiler instead."
314
+ )
315
+ web = True
316
+
317
+ url: str
318
+ compile_server: CompileServer | None = None
319
+ try:
320
+ url, compile_server = _try_start_server_or_get_url(auto_update, web, localhost)
321
+ except KeyboardInterrupt:
322
+ print("\nExiting from first try...")
323
+ if compile_server:
324
+ compile_server.stop()
325
+ return 1
326
+ except Exception as e:
327
+ print(f"Error: {e}")
328
+ if compile_server:
329
+ compile_server.stop()
330
+ return 1
331
+
332
+ try:
333
+ return run_client(
334
+ directory=directory,
335
+ host=compile_server if compile_server else url,
336
+ open_web_browser=open_web_browser,
337
+ keep_running=not just_compile,
338
+ build_mode=build_mode,
339
+ profile=profile,
340
+ )
341
+ except KeyboardInterrupt:
342
+ return 1
343
+ finally:
344
+ if compile_server:
345
+ compile_server.stop()
fastled/compile_server.py CHANGED
@@ -1,6 +1,6 @@
1
1
  from pathlib import Path
2
2
 
3
- from fastled.types import BuildMode, CompileResult
3
+ from fastled.types import BuildMode, CompileResult, Platform
4
4
 
5
5
 
6
6
  class CompileServer:
@@ -13,11 +13,14 @@ class CompileServer:
13
13
  mapped_dir: Path | None = None,
14
14
  auto_start: bool = True,
15
15
  container_name: str | None = None,
16
+ platform: Platform = Platform.WASM,
16
17
  ) -> None:
17
18
  from fastled.compile_server_impl import ( # avoid circular import
18
19
  CompileServerImpl,
19
20
  )
20
21
 
22
+ assert platform == Platform.WASM, "Only WASM platform is supported right now."
23
+
21
24
  self.impl = CompileServerImpl(
22
25
  container_name=container_name,
23
26
  interactive=interactive,
fastled/live_client.py ADDED
@@ -0,0 +1,69 @@
1
+ import threading
2
+ from pathlib import Path
3
+
4
+ from fastled.compile_server import CompileServer
5
+ from fastled.types import BuildMode
6
+
7
+
8
+ class LiveClient:
9
+ """LiveClient class watches for changes and auto-triggeres rebuild."""
10
+
11
+ def __init__(
12
+ self,
13
+ sketch_directory: Path,
14
+ host: str | CompileServer | None = None,
15
+ auto_start: bool = True,
16
+ open_web_browser: bool = True,
17
+ keep_running: bool = True,
18
+ build_mode: BuildMode = BuildMode.QUICK,
19
+ profile: bool = False,
20
+ ) -> None:
21
+ self.sketch_directory = sketch_directory
22
+ self.host = host
23
+ self.open_web_browser = open_web_browser
24
+ self.keep_running = keep_running
25
+ self.build_mode = build_mode
26
+ self.profile = profile
27
+ self.auto_start = auto_start
28
+ self.shutdown = threading.Event()
29
+ self.thread: threading.Thread | None = None
30
+ if auto_start:
31
+ self.start()
32
+
33
+ def run(self) -> int:
34
+ """Run the client."""
35
+ from fastled.client_server import run_client # avoid circular import
36
+
37
+ rtn = run_client(
38
+ directory=self.sketch_directory,
39
+ host=self.host,
40
+ open_web_browser=self.open_web_browser,
41
+ keep_running=self.keep_running,
42
+ build_mode=self.build_mode,
43
+ profile=self.profile,
44
+ shutdown=self.shutdown,
45
+ )
46
+ return rtn
47
+
48
+ @property
49
+ def running(self) -> bool:
50
+ return self.thread is not None and self.thread.is_alive()
51
+
52
+ def start(self) -> None:
53
+ """Start the client."""
54
+ assert not self.running, "LiveClient is already running"
55
+ self.shutdown.clear()
56
+ self.thread = threading.Thread(target=self.run, daemon=True)
57
+ self.thread.start()
58
+
59
+ def stop(self) -> None:
60
+ """Stop the client."""
61
+ self.shutdown.set()
62
+ if self.thread:
63
+ self.thread.join()
64
+ self.thread = None
65
+
66
+ def finalize(self) -> None:
67
+ """Finalize the client."""
68
+ self.stop()
69
+ self.thread = None
fastled/types.py CHANGED
@@ -45,3 +45,17 @@ class BuildMode(Enum):
45
45
  return BuildMode.RELEASE
46
46
  else:
47
47
  return BuildMode.QUICK
48
+
49
+
50
+ class Platform(Enum):
51
+ WASM = "WASM"
52
+
53
+ @classmethod
54
+ def from_string(cls, platform_str: str) -> "Platform":
55
+ try:
56
+ return cls[platform_str.upper()]
57
+ except KeyError:
58
+ valid_modes = [mode.name for mode in cls]
59
+ raise ValueError(
60
+ f"Platform must be one of {valid_modes}, got {platform_str}"
61
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fastled
3
- Version: 1.1.38
3
+ Version: 1.1.39
4
4
  Summary: FastLED Wasm Compiler
5
5
  Home-page: https://github.com/zackees/fastled-wasm
6
6
  Maintainer: Zachary Vorhies
@@ -148,6 +148,35 @@ with Api.server() as server:
148
148
 
149
149
  ```
150
150
 
151
+ **LiveClient will auto-trigger a build on code changes, just like the cli does**
152
+ ```python
153
+
154
+ # Live Client will compile against the web-compiler
155
+ from fastapi import Api, LiveClient
156
+ client: LiveClient = Api.live_client(
157
+ "path/to/sketch_directory",
158
+ )
159
+ # Now user can start editing their sketch and it will auto-compile
160
+ # ... after a while stop it like this.
161
+ client.stop()
162
+ ```
163
+
164
+ **LiveClient with local CompileServer**
165
+ ```python
166
+
167
+ # Live Client will compile against a local server.
168
+ from fastapi import Api, LiveClient
169
+
170
+ with Api.server() as server:
171
+ client: LiveClient = Api.live_client(
172
+ "path/to/sketch_directory",
173
+ host=server
174
+ )
175
+ # Now user can start editing their sketch and it will auto-compile
176
+ # ... after a while stop it like this.
177
+ client.stop()
178
+ ```
179
+
151
180
  # Features
152
181
 
153
182
  ## Hot reload by default
@@ -168,11 +197,15 @@ can be much longer, for example if you modify a header file.
168
197
  Huge blobs of data like video will absolutely kill the compile performance as these blobs would normally have to be shuffled
169
198
  back and forth. Therefore a special directory `data/` is implicitly used to hold this blob data. Any data in this directory
170
199
  will be replaced with a stub containing the size and hash of the file during upload. On download these stubs are swapped back
171
- with their originals.
200
+ with their originals during decompression.
172
201
 
173
202
  The wasm compiler will recognize all files in the `data/` directory and generate a `files.json` manifest and can be used
174
203
  in your wasm sketch using an emulated SD card system mounted at `/data/` on the SD Card. In order to increase load speed, these
175
- files will be asynchroniously streamed into the running sketch instance during runtime. The only caveat here is that although these files will be available during the setup() phase of the sketch, they will not be fully hydrated, so if you do a seek(end) of these files the results are undefined.
204
+ files will be asynchroniously streamed into the running sketch instance during runtime. Files named with *.json, *.csv, *.txt will be
205
+ immediately injected in the app before setup() is called and can be used immediatly in setup() in their entirety.
206
+
207
+ All other files will be streamed in. The `Video` element in FastLED is designed to gracefully handle missing data streamed in through
208
+ the file system.
176
209
 
177
210
  For an example of how to use this see `examples/SdCard` which is fully wasm compatible.
178
211
 
@@ -184,11 +217,9 @@ We use `ccache` to cache object files. This seems actually help a lot and is bet
184
217
 
185
218
  The compilation to wasm will happen under a lock. Removing this lock requires removing the platformio toolchain as the compiler backend which enforces it's own internal lock preventing parallel use.
186
219
 
187
- Simple syntax errors will be caught by the pre-processing step. This happens without a lock to reduce the single lock bottleneck.
188
-
189
220
  ## Sketch Cache
190
221
 
191
- Sketchs are aggresively finger-printed and stored in a cache. White space, comments, and other superficial data will be stripped out during pre-processing and minimization for fingerprinting. This source file decimation is only used for finger
222
+ Sketchs are aggressively finger-printed and stored in a cache. White space, comments, and other superficial data will be stripped out during pre-processing and minimization for fingerprinting. This source file decimation is only used for finger
192
223
  printing while the actual source files are sent to compiler to preserve line numbers and file names.
193
224
 
194
225
  This pre-processing done is done via gcc and special regex's and will happen without a lock. This will allow you to have extremely quick recompiles for whitespace and changes in comments even if the compiler is executing under it's lock.
@@ -225,6 +256,7 @@ A: A big chunk of space is being used by unnecessary javascript `emscripten` is
225
256
 
226
257
  # Revisions
227
258
 
259
+ * 1.1.39 - Added `LiveClient`, `fastled.Api.live_server()` will spawn it. Allows user to have a live compiling client that re-triggers a compile on file changes.
228
260
  * 1.1.38 - Cleanup the `fastled.Api` object and streamline for general use.
229
261
  * 1.1.37 - `Test.test_examples()` is now unit tested to work correctly.
230
262
  * 1.1.36 - We now have an api. `from fastled import Api` and `from fastled import Test` for testing.
@@ -1,12 +1,13 @@
1
- fastled/__init__.py,sha256=P9XIl4QcR1-RO-RBTPitME_vHzDDq4qFwkZDyEKvE0k,3001
1
+ fastled/__init__.py,sha256=SQF8-PpioJm6DAQn5vCcc-muwXHBfs0loIofSRoWK8g,3613
2
2
  fastled/app.py,sha256=3xg7oVD-UYnKPU8SAY-Cs5UnAYdwpdpuEFRR2N8P1Tg,1787
3
3
  fastled/cli.py,sha256=CNR_pQR0sNVPNuv8e_nmm-0PI8sU-eUBUgnWgWkzW9c,237
4
- fastled/client_server.py,sha256=p9mbhgwA3UERrH-Hig0dLzpOpL3Y3xzIBCw3UMpoxPo,11518
5
- fastled/compile_server.py,sha256=g95J9ZtNG-GiBLIO_qyg8f5FJfnrUJxjxZY-cb3d9lY,2517
4
+ fastled/client_server.py,sha256=KQsBKjHfkhgF5EOCHSbJcqu0dPKlOCsbXA2V035VCH0,12403
5
+ fastled/compile_server.py,sha256=Z7rHFs3M6QPbSCsbgHAQDk6GTVAJMMPCXtD4Y0mu8RM,2659
6
6
  fastled/compile_server_impl.py,sha256=ClBLtFHB0ucaT8tAJfI6o3bJ-LRnXc4Pxy7bVKnFiww,8803
7
7
  fastled/docker_manager.py,sha256=zBCFGk2P3_bS7_SUQ5j2lpsOS3RvIzXYkrJXC6xP69k,25383
8
8
  fastled/filewatcher.py,sha256=LwEQJkqADsArZyY499RLAer6JjJyDwaQBcAvT7xmp3c,6708
9
9
  fastled/keyboard.py,sha256=Zz_ggxOUTX2XQEy6K6kAoorVlUev4wEk9Awpvv9aStA,3241
10
+ fastled/live_client.py,sha256=_KvqmyUyyGpoYET1Z9CdeUVoIbFjIUWwPcTp5XCQuxY,2075
10
11
  fastled/open_browser.py,sha256=vzMBcpDNY0f-Bx9KmEILKDANZ6gvsywCVwn1FRhPXh4,1770
11
12
  fastled/parse_args.py,sha256=37WsELphNEqGQgmjppZx6uMWE2E-dZ58zCKUl-3mr3Q,6150
12
13
  fastled/paths.py,sha256=VsPmgu0lNSCFOoEC0BsTYzDygXqy15AHUfN-tTuzDZA,99
@@ -16,14 +17,14 @@ fastled/settings.py,sha256=3eMKv0tLXgIQ0CFDboIp_l5_71rzIIyWg353YjnYJnc,323
16
17
  fastled/sketch.py,sha256=483TrrIdZJfo1MIu5FkD-V5OGmOfHmsZ2f6VvNsJBJM,3299
17
18
  fastled/spinner.py,sha256=VHxmvB92P0Z_zYxRajb5HiNmkHHvZ5dG7hKtZltzpcs,867
18
19
  fastled/string_diff.py,sha256=UR1oRhg9lsPzAG4bn_MwJMCn0evP5AigkBiwLiI9fgA,1354
19
- fastled/types.py,sha256=brmCvXeGBYcw0Sket_5I1XGOvrLMfKnhm7ZVbi0oDnI,1098
20
+ fastled/types.py,sha256=PpSEtzFCkWtSIEMC0QXGl966R97vLoryVl3yFW0YhTs,1475
20
21
  fastled/util.py,sha256=t4M3NFMhnCzfYbLvIyJi0RdFssZqbTN_vVIaej1WV-U,265
21
22
  fastled/web_compile.py,sha256=05PeLJ77QQC6PUKjDhsntBmyBola6QQIfF2k-zjYNE4,10261
22
23
  fastled/assets/example.txt,sha256=lTBovRjiz0_TgtAtbA1C5hNi2ffbqnNPqkKg6UiKCT8,54
23
24
  fastled/test/examples.py,sha256=EDXb6KastKOOWzew99zrpmcNcXTcAtYi8eud6F1pnWA,980
24
- fastled-1.1.38.dist-info/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
25
- fastled-1.1.38.dist-info/METADATA,sha256=hbt9CNXAOkHvxi7MasDzU9-RXBWab-mYTvoSItJWNJw,16912
26
- fastled-1.1.38.dist-info/WHEEL,sha256=0VNUDWQJzfRahYI3neAhz2UVbRCtztpN5dPHAGvmGXc,109
27
- fastled-1.1.38.dist-info/entry_points.txt,sha256=RCwmzCSOS4-C2i9EziANq7Z2Zb4KFnEMR1FQC0bBwAw,101
28
- fastled-1.1.38.dist-info/top_level.txt,sha256=Bbv5kpJpZhWNCvDF4K0VcvtBSDMa8B7PTOrZa9CezHY,8
29
- fastled-1.1.38.dist-info/RECORD,,
25
+ fastled-1.1.39.dist-info/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
26
+ fastled-1.1.39.dist-info/METADATA,sha256=a-iU6xg5tbGNPN-2l0Bydnk3Xax9-jfWAFV7ltioC6U,17889
27
+ fastled-1.1.39.dist-info/WHEEL,sha256=0VNUDWQJzfRahYI3neAhz2UVbRCtztpN5dPHAGvmGXc,109
28
+ fastled-1.1.39.dist-info/entry_points.txt,sha256=RCwmzCSOS4-C2i9EziANq7Z2Zb4KFnEMR1FQC0bBwAw,101
29
+ fastled-1.1.39.dist-info/top_level.txt,sha256=Bbv5kpJpZhWNCvDF4K0VcvtBSDMa8B7PTOrZa9CezHY,8
30
+ fastled-1.1.39.dist-info/RECORD,,