fastled 1.0.10__py2.py3-none-any.whl → 1.0.12__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
@@ -1,3 +1,3 @@
1
1
  """FastLED Wasm Compiler package."""
2
2
 
3
- __version__ = "1.0.10"
3
+ __version__ = "1.0.12"
fastled/app.py CHANGED
@@ -17,10 +17,11 @@ from fastled import __version__
17
17
  from fastled.build_mode import BuildMode, get_build_mode
18
18
  from fastled.compile_server import CompileServer
19
19
  from fastled.docker_manager import DockerManager
20
- from fastled.filewatcher import create_file_watcher_process
20
+ from fastled.filewatcher import FileWatcherProcess
21
+ from fastled.keyboard import SpaceBarWatcher
21
22
  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
23
+ from fastled.sketch import looks_like_fastled_repo, looks_like_sketch_directory
24
+ from fastled.web_compile import ConnectionResult, find_good_connection, web_compile
24
25
 
25
26
  machine = platform.machine().lower()
26
27
  IS_ARM: bool = "arm" in machine or "aarch64" in machine
@@ -107,13 +108,21 @@ def parse_args() -> argparse.Namespace:
107
108
  help="Skips the test to see if the current directory is a valid FastLED sketch directory",
108
109
  )
109
110
 
111
+ cwd_is_fastled = looks_like_fastled_repo(Path(os.getcwd()))
112
+
110
113
  args = parser.parse_args()
114
+ if not cwd_is_fastled and not args.localhost and not args.web and not args.server:
115
+ print(f"Using web compiler at {DEFAULT_URL}")
116
+ args.web = DEFAULT_URL
117
+ if cwd_is_fastled and not args.web:
118
+ args.localhost = True
111
119
  if args.localhost:
112
120
  args.web = "localhost"
113
- if args.web is not None:
114
- args.web = args.web if args.web == "" else args.web
115
121
  if args.server and args.web:
116
122
  parser.error("--server and --web are mutually exclusive")
123
+ if args.interactive and not args.server:
124
+ print("--interactive forces --server mode")
125
+ args.server = True
117
126
  if args.directory is None and not args.server:
118
127
  # does current directory look like a sketch?
119
128
  maybe_sketch_dir = Path(os.getcwd())
@@ -124,6 +133,7 @@ def parse_args() -> argparse.Namespace:
124
133
  "\nYou either need to specify a sketch directory or run in --server mode."
125
134
  )
126
135
  sys.exit(1)
136
+
127
137
  return args
128
138
 
129
139
 
@@ -187,7 +197,18 @@ def run_web_compiler(
187
197
 
188
198
 
189
199
  def _try_start_server_or_get_url(args: argparse.Namespace) -> str | CompileServer:
190
- if args.web:
200
+ is_local_host = "localhost" in args.web or "127.0.0.1" in args.web or args.localhost
201
+
202
+ # test to see if there is already a local host server
203
+ local_host_needs_server = False
204
+ if is_local_host:
205
+ addr = "localhost" if args.localhost else args.web
206
+ result: ConnectionResult | None = find_good_connection([addr])
207
+ if result is not None:
208
+ print(f"Found local server at {result.host}")
209
+ local_host_needs_server = True
210
+
211
+ if not local_host_needs_server and args.web:
191
212
  if isinstance(args.web, str):
192
213
  return args.web
193
214
  if isinstance(args.web, bool):
@@ -195,6 +216,7 @@ def _try_start_server_or_get_url(args: argparse.Namespace) -> str | CompileServe
195
216
  return args.web
196
217
  else:
197
218
  try:
219
+ print("No local server found, starting one...")
198
220
  compile_server = CompileServer()
199
221
  print("Waiting for the local compiler to start...")
200
222
  if not compile_server.wait_for_startup():
@@ -210,7 +232,7 @@ def _try_start_server_or_get_url(args: argparse.Namespace) -> str | CompileServe
210
232
 
211
233
  def run_client(args: argparse.Namespace) -> int:
212
234
  compile_server: CompileServer | None = None
213
- open_web_browser = not args.just_compile
235
+ open_web_browser = not args.just_compile and not args.interactive
214
236
  profile = args.profile
215
237
  if not args.force_compile and not looks_like_sketch_directory(Path(args.directory)):
216
238
  print(
@@ -291,41 +313,66 @@ def run_client(args: argparse.Namespace) -> int:
291
313
  compile_server.stop()
292
314
  return 1
293
315
 
294
- # Watch mode
295
316
  print("\nWatching for changes. Press Ctrl+C to stop...")
296
- # watcher = FileChangedNotifier(args.directory, excluded_patterns=["fastled_js"])
297
- # watcher.start()
298
-
299
- from multiprocessing import Process, Queue
300
-
301
- proc: Process
302
- queue: Queue
303
- proc, queue = create_file_watcher_process(
317
+ sketch_filewatcher = FileWatcherProcess(
304
318
  args.directory, excluded_patterns=["fastled_js"]
305
319
  )
306
320
 
321
+ source_code_watcher: FileWatcherProcess | None = None
322
+ if compile_server and compile_server.using_fastled_src_dir_volume():
323
+ assert compile_server.fastled_src_dir is not None
324
+ source_code_watcher = FileWatcherProcess(
325
+ compile_server.fastled_src_dir, excluded_patterns=[]
326
+ )
327
+
328
+ def trigger_rebuild_if_sketch_changed(
329
+ last_compiled_result: CompiledResult,
330
+ ) -> CompiledResult:
331
+ changed_files = sketch_filewatcher.get_all_changes()
332
+ if changed_files:
333
+ print(f"\nChanges detected in {changed_files}")
334
+ last_hash_value = last_compiled_result.hash_value
335
+ out = compile_function(last_hash_value=last_hash_value)
336
+ if not out.success:
337
+ print("\nRecompilation failed.")
338
+ else:
339
+ print("\nRecompilation successful.")
340
+ return out
341
+ return last_compiled_result
342
+
307
343
  try:
308
344
  while True:
309
- try:
310
- size = queue.qsize()
311
- changed_files = []
312
- for i in range(size):
313
- changed_files.append(queue.get())
314
- except KeyboardInterrupt:
315
- print("\nExiting from watcher...")
316
- raise
317
- except Exception as e:
318
- print(f"Error getting changes: {e}")
319
- changed_files = []
320
- if changed_files:
321
- print(f"\nChanges detected in {changed_files}")
322
- last_hash_value = last_compiled_result.hash_value
323
- result = compile_function(last_hash_value=last_hash_value)
324
- if not result.success:
325
- print("\nRecompilation failed.")
326
- else:
327
- print("\nRecompilation successful.")
328
- time.sleep(0.3)
345
+ last_compiled_result = trigger_rebuild_if_sketch_changed(
346
+ last_compiled_result
347
+ )
348
+ if compile_server and not compile_server.proceess_running():
349
+ print("Server process is not running. Exiting...")
350
+ return 1
351
+ if source_code_watcher is not None:
352
+ changed_files = source_code_watcher.get_all_changes()
353
+ if changed_files:
354
+ print(f"\nChanges detected in FastLED source code: {changed_files}")
355
+ print("Press space bar to trigger compile.")
356
+
357
+ space_key_watcher = SpaceBarWatcher()
358
+ try:
359
+ while True:
360
+ if space_key_watcher.space_bar_pressed():
361
+ print("Space bar pressed, triggering recompile...")
362
+ last_compiled_result = compile_function(
363
+ last_hash_value=None
364
+ )
365
+ print("Finished recompile.")
366
+ break
367
+ elif len(sketch_filewatcher.get_all_changes()) > 0:
368
+ last_compiled_result = compile_function(
369
+ last_hash_value=None
370
+ )
371
+ break
372
+ time.sleep(0.1)
373
+ finally:
374
+ space_key_watcher.stop()
375
+
329
376
  except KeyboardInterrupt:
330
377
  print("\nStopping watch mode...")
331
378
  return 0
@@ -333,7 +380,7 @@ def run_client(args: argparse.Namespace) -> int:
333
380
  print(f"Error: {e}")
334
381
  return 1
335
382
  finally:
336
- proc.terminate()
383
+ sketch_filewatcher.stop()
337
384
  if compile_server:
338
385
  compile_server.stop()
339
386
  if browser_proc:
@@ -372,8 +419,8 @@ def main() -> int:
372
419
 
373
420
  if __name__ == "__main__":
374
421
  try:
422
+ os.chdir("../fastled")
375
423
  sys.argv.append("examples/SdCard")
376
- sys.argv.append("--local")
377
424
  sys.exit(main())
378
425
  except KeyboardInterrupt:
379
426
  print("\nExiting from main...")