fastled 1.2.79__py3-none-any.whl → 1.2.81__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
@@ -9,12 +9,12 @@ from .compile_server import CompileServer
9
9
  from .live_client import LiveClient
10
10
  from .settings import DOCKER_FILE, IMAGE_NAME
11
11
  from .site.build import build
12
- from .types import BuildMode, CompileResult, CompileServerError
12
+ from .types import BuildMode, CompileResult, CompileServerError, FileResponse
13
13
 
14
14
  # IMPORTANT! There's a bug in github which will REJECT any version update
15
15
  # that has any other change in the repo. Please bump the version as the
16
16
  # ONLY change in a commit, or else the pypi update and the release will fail.
17
- __version__ = "1.2.79"
17
+ __version__ = "1.2.81"
18
18
 
19
19
 
20
20
  class Api:
@@ -194,14 +194,19 @@ class Test:
194
194
  def spawn_http_server(
195
195
  directory: Path | str = Path("."),
196
196
  port: int | None = None,
197
+ compile_server_port: int | None = None,
197
198
  open_browser: bool = True,
198
199
  ) -> Process:
199
200
  from fastled.open_browser import open_browser_process
200
201
 
202
+ compile_server_port = compile_server_port or -1
201
203
  if isinstance(directory, str):
202
204
  directory = Path(directory)
203
205
  proc: Process = open_browser_process(
204
- directory, port=port, open_browser=open_browser
206
+ directory,
207
+ port=port,
208
+ compile_server_port=compile_server_port,
209
+ open_browser=open_browser,
205
210
  )
206
211
  return proc
207
212
 
@@ -213,5 +218,6 @@ __all__ = [
213
218
  "CompileResult",
214
219
  "CompileServerError",
215
220
  "BuildMode",
221
+ "FileResponse",
216
222
  "DOCKER_FILE",
217
223
  ]
fastled/client_server.py CHANGED
@@ -188,6 +188,15 @@ def run_client(
188
188
  return DEFAULT_URL
189
189
 
190
190
  url = get_url()
191
+ # parse out the port from the url
192
+ # use a standard host address parser to grab it
193
+ import urllib.parse
194
+
195
+ parsed_url = urllib.parse.urlparse(url)
196
+ if parsed_url.port is not None:
197
+ port = parsed_url.port
198
+ else:
199
+ port = 80
191
200
 
192
201
  try:
193
202
 
@@ -214,7 +223,9 @@ def run_client(
214
223
 
215
224
  browser_proc: Process | None = None
216
225
  if open_web_browser:
217
- browser_proc = open_browser_process(directory / "fastled_js")
226
+ browser_proc = open_browser_process(
227
+ directory / "fastled_js", compile_server_port=port
228
+ )
218
229
  else:
219
230
  print("\nCompilation successful.")
220
231
  if compile_server:
fastled/compile_server.py CHANGED
@@ -1,6 +1,6 @@
1
1
  from pathlib import Path
2
2
 
3
- from fastled.types import BuildMode, CompileResult, Platform
3
+ from fastled.types import BuildMode, CompileResult, FileResponse, Platform
4
4
 
5
5
 
6
6
  class CompileServer:
@@ -53,6 +53,10 @@ class CompileServer:
53
53
 
54
54
  project_init(example=example, outputdir=outputdir)
55
55
 
56
+ def fetch_source_file(self, filepath: str) -> FileResponse | Exception:
57
+ """Get the source file from the server."""
58
+ return self.impl.fetch_source_file(filepath)
59
+
56
60
  @property
57
61
  def name(self) -> str:
58
62
  return self.impl.container_name
@@ -17,7 +17,7 @@ from fastled.docker_manager import (
17
17
  )
18
18
  from fastled.settings import DEFAULT_CONTAINER_NAME, IMAGE_NAME, SERVER_PORT
19
19
  from fastled.sketch import looks_like_fastled_repo
20
- from fastled.types import BuildMode, CompileResult, CompileServerError
20
+ from fastled.types import BuildMode, CompileResult, CompileServerError, FileResponse
21
21
 
22
22
  SERVER_OPTIONS = [
23
23
  "--allow-shutdown", # Allow the server to be shut down without a force kill.
@@ -204,6 +204,29 @@ class CompileServerImpl:
204
204
  return False
205
205
  return False
206
206
 
207
+ def fetch_source_file(self, filepath: str) -> FileResponse | Exception:
208
+ """Get the source file from the server."""
209
+ if not self._port:
210
+ raise RuntimeError("Server has not been started yet")
211
+ try:
212
+ httpx_client = httpx.Client()
213
+ url = f"http://localhost:{self._port}/sourcefiles/{filepath}"
214
+ response = httpx_client.get(url, follow_redirects=True)
215
+ if response.status_code == 200:
216
+ content = response.text
217
+ mimetype: str = response.headers.get("Content-Type", "text/plain")
218
+ return FileResponse(
219
+ content=content,
220
+ mimetype=mimetype,
221
+ filename=filepath,
222
+ )
223
+ else:
224
+ return CompileServerError(
225
+ f"Error fetching file {filepath}: {response.status_code}"
226
+ )
227
+ except httpx.RequestError as e:
228
+ return CompileServerError(f"Error fetching file {filepath}: {e}")
229
+
207
230
  def _start(self) -> int:
208
231
  print("Compiling server starting")
209
232
 
fastled/open_browser.py CHANGED
@@ -14,8 +14,7 @@ PYTHON_EXE = sys.executable
14
14
 
15
15
 
16
16
  def _open_http_server_subprocess(
17
- fastled_js: Path,
18
- port: int,
17
+ fastled_js: Path, port: int, compile_server_port: int
19
18
  ) -> None:
20
19
  print("\n################################################################")
21
20
  print(f"# Opening browser to {fastled_js} on port {port}")
@@ -30,6 +29,8 @@ def _open_http_server_subprocess(
30
29
  str(fastled_js),
31
30
  "--port",
32
31
  str(port),
32
+ "--compile-server-port",
33
+ str(compile_server_port),
33
34
  ]
34
35
  # Pass SSL flags if available
35
36
  if ssl:
@@ -89,6 +90,7 @@ def wait_for_server(port: int, timeout: int = 10) -> None:
89
90
 
90
91
  def open_browser_process(
91
92
  fastled_js: Path,
93
+ compile_server_port: int,
92
94
  port: int | None = None,
93
95
  open_browser: bool = True,
94
96
  ) -> Process:
@@ -100,7 +102,7 @@ def open_browser_process(
100
102
 
101
103
  proc = Process(
102
104
  target=_open_http_server_subprocess,
103
- args=(fastled_js, port),
105
+ args=(fastled_js, port, compile_server_port),
104
106
  daemon=True,
105
107
  )
106
108
  proc.start()
fastled/server_flask.py CHANGED
@@ -2,12 +2,14 @@ import argparse
2
2
  from multiprocessing import Process
3
3
  from pathlib import Path
4
4
 
5
+ import requests
5
6
  from livereload import Server
6
7
 
7
8
 
8
9
  def _run_flask_server(
9
10
  fastled_js: Path,
10
11
  port: int,
12
+ compile_server_port: int,
11
13
  certfile: Path | None = None,
12
14
  keyfile: Path | None = None,
13
15
  ) -> None:
@@ -27,10 +29,38 @@ def _run_flask_server(
27
29
  # Must be a full path or flask will fail to find the file.
28
30
  fastled_js = fastled_js.resolve()
29
31
 
32
+ print(f"Compile server port is at {compile_server_port}")
33
+
30
34
  @app.route("/")
31
35
  def serve_index():
32
36
  return send_from_directory(fastled_js, "index.html")
33
37
 
38
+ @app.route("/static/<path:path>")
39
+ def proxy_static(path):
40
+ """Proxy requests to /static/* to the compile server"""
41
+ from flask import Response, request
42
+
43
+ # Forward the request to the compile server
44
+ target_url = f"http://localhost:{compile_server_port}/static/{path}"
45
+
46
+ # Forward the request with the same method, headers, and body
47
+ resp = requests.request(
48
+ method=request.method,
49
+ url=target_url,
50
+ headers={key: value for key, value in request.headers if key != "Host"},
51
+ data=request.get_data(),
52
+ cookies=request.cookies,
53
+ allow_redirects=True,
54
+ stream=False,
55
+ )
56
+
57
+ # Create a Flask Response object from the requests response
58
+ response = Response(
59
+ resp.raw.read(), status=resp.status_code, headers=dict(resp.headers)
60
+ )
61
+
62
+ return response
63
+
34
64
  @app.route("/<path:path>")
35
65
  def serve_files(path):
36
66
  response = send_from_directory(fastled_js, path)
@@ -83,11 +113,15 @@ def _run_flask_server(
83
113
 
84
114
 
85
115
  def run(
86
- port: int, cwd: Path, certfile: Path | None = None, keyfile: Path | None = None
116
+ port: int,
117
+ cwd: Path,
118
+ compile_server_port: int,
119
+ certfile: Path | None = None,
120
+ keyfile: Path | None = None,
87
121
  ) -> None:
88
122
  """Run the Flask server."""
89
123
  try:
90
- _run_flask_server(cwd, port, certfile, keyfile)
124
+ _run_flask_server(cwd, port, compile_server_port, certfile, keyfile)
91
125
  import warnings
92
126
 
93
127
  warnings.warn("Flask server has stopped")
@@ -128,15 +162,15 @@ def parse_args() -> argparse.Namespace:
128
162
 
129
163
  def run_flask_server_process(
130
164
  port: int,
131
- cwd: Path | None = None,
165
+ cwd: Path,
166
+ compile_server_port: int,
132
167
  certfile: Path | None = None,
133
168
  keyfile: Path | None = None,
134
169
  ) -> Process:
135
170
  """Run the Flask server in a separate process."""
136
- cwd = cwd or Path(".")
137
171
  process = Process(
138
172
  target=run,
139
- args=(port, cwd, certfile, keyfile),
173
+ args=(port, cwd, compile_server_port, certfile, keyfile),
140
174
  )
141
175
  process.start()
142
176
  return process
fastled/server_start.py CHANGED
@@ -9,7 +9,11 @@ from fastled.server_flask import run_flask_server_process
9
9
 
10
10
 
11
11
  def run_server_process(
12
- port: int, cwd: Path, certfile: Path | None = None, keyfile: Path | None = None
12
+ port: int,
13
+ cwd: Path,
14
+ compile_server_port: int,
15
+ certfile: Path | None = None,
16
+ keyfile: Path | None = None,
13
17
  ) -> Process:
14
18
  """Run the server in a separate process."""
15
19
  if True:
@@ -17,6 +21,7 @@ def run_server_process(
17
21
  process = run_flask_server_process(
18
22
  port=port,
19
23
  cwd=cwd,
24
+ compile_server_port=compile_server_port,
20
25
  certfile=certfile,
21
26
  keyfile=keyfile,
22
27
  )
@@ -45,19 +50,18 @@ def get_asset_path(filename: str) -> Path | None:
45
50
  def start_process(
46
51
  path: Path,
47
52
  port: int,
48
- certfile: Path | None = None,
49
- keyfile: Path | None = None,
53
+ compile_server_port: int,
54
+ certfile: Path | None = None, # reserved for future use
55
+ keyfile: Path | None = None, # reserved for future use
50
56
  ) -> Process:
51
57
  """Run the server, using package assets if explicit paths are not provided"""
52
58
  # Use package resources if no explicit path
53
- if certfile is None:
54
- certfile = get_asset_path("localhost.pem")
55
- if keyfile is None:
56
- keyfile = get_asset_path("localhost-key.pem")
57
59
 
58
60
  # _run_flask_server(path, port, certfile, keyfile)
59
61
  # run_fastapi_server_process(port=port, path=path, certfile=certfile, keyfile=keyfile)
60
- proc = run_server_process(port=port, cwd=path)
62
+ proc = run_server_process(
63
+ port=port, cwd=path, compile_server_port=compile_server_port
64
+ )
61
65
  # try:
62
66
  # proc.join()
63
67
  # except KeyboardInterrupt:
@@ -71,6 +75,7 @@ def start_process(
71
75
  class Args:
72
76
  fastled_js: Path
73
77
  port: int
78
+ compile_server_port: int
74
79
  cert: Path | None
75
80
  key: Path | None
76
81
 
@@ -89,6 +94,12 @@ def parse_args() -> Args:
89
94
  default=5500,
90
95
  help="Port to run the server on (default: 5500)",
91
96
  )
97
+ parser.add_argument(
98
+ "--compile-server-port",
99
+ type=int,
100
+ required=True,
101
+ help="Used to forward requests to the compile server",
102
+ )
92
103
  parser.add_argument(
93
104
  "--cert", type=Path, help="(Optional) Path to SSL certificate (PEM format)"
94
105
  )
@@ -99,6 +110,7 @@ def parse_args() -> Args:
99
110
  out: Args = Args(
100
111
  fastled_js=args.fastled_js,
101
112
  port=args.port,
113
+ compile_server_port=args.compile_server_port,
102
114
  cert=args.cert,
103
115
  key=args.key,
104
116
  )
@@ -116,6 +128,7 @@ def main() -> None:
116
128
  proc = start_process(
117
129
  path=fastled_js,
118
130
  port=port,
131
+ compile_server_port=args.compile_server_port,
119
132
  certfile=cert,
120
133
  keyfile=key,
121
134
  )
fastled/types.py CHANGED
@@ -151,3 +151,12 @@ class Platform(Enum):
151
151
  raise ValueError(
152
152
  f"Platform must be one of {valid_modes}, got {platform_str}"
153
153
  )
154
+
155
+
156
+ @dataclass
157
+ class FileResponse:
158
+ """File response from the server."""
159
+
160
+ filename: str
161
+ content: str
162
+ mimetype: str
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastled
3
- Version: 1.2.79
3
+ Version: 1.2.81
4
4
  Summary: FastLED Wasm Compiler
5
5
  Home-page: https://github.com/zackees/fastled-wasm
6
6
  Maintainer: Zachary Vorhies
@@ -1,17 +1,17 @@
1
- fastled/__init__.py,sha256=6fYsskRgPisOqiDsZFYXhWAA0txnvkMGffOfCtAXB1I,6680
1
+ fastled/__init__.py,sha256=E0yN78HV0eXNtDsCcsGLoJTTdhAaXlsN6B17h7nzmjc,6896
2
2
  fastled/app.py,sha256=0W8Mbplo5UCRzj7nMVgkmCBddQGufsUQjkUUT4pMp74,4611
3
3
  fastled/cli.py,sha256=FjVr31ht0UPlAcmX-84NwfAGMQHTkrCe4o744jCAxiw,375
4
4
  fastled/cli_test.py,sha256=qJB9yLRFR3OwOwdIWSQ0fQsWLnA37v5pDccufiP_hTs,512
5
5
  fastled/cli_test_interactive.py,sha256=BjNhveZOk5aCffHbcrxPQQjWmAuj4ClVKKcKX5eY6yM,542
6
- fastled/client_server.py,sha256=_M3EsHOLlQI610qxcmBCLa2K5ERmNHpF1cI2C_xzkmk,14549
7
- fastled/compile_server.py,sha256=rkXvrvdav5vDG8lv_OlBX3YSCHtnHMt25nXbfeg_r78,2960
8
- fastled/compile_server_impl.py,sha256=_DRdt-eWTdOr2mXvO7h6dKqDSonsm523bIqCZr4wf2k,12615
6
+ fastled/client_server.py,sha256=zQF4ioOkQzHkKAP0A-8mqjVt8aGD9Sj9ijmknsdLW0U,14859
7
+ fastled/compile_server.py,sha256=sRiXYzw7lv9vcWJWGPUkzOGZPmvZGV_TGwbHYoRc15s,3155
8
+ fastled/compile_server_impl.py,sha256=0xWJg5b6n_Y-BKPI2ToG4bT7bB_ZuGNQy45JjyJDg6o,13659
9
9
  fastled/docker_manager.py,sha256=SC_qV6grNTGh0QD1ubKrULQblrN-2PORocISlaZg9NQ,35156
10
10
  fastled/filewatcher.py,sha256=3qS3L7zMQhFuVrkeGn1djsB_cB6x_E2YGJmmQWVAU_w,10033
11
11
  fastled/keyboard.py,sha256=UTAsqCn1UMYnB8YDzENiLTj4GeL45tYfEcO7_5fLFEg,3556
12
12
  fastled/keyz.py,sha256=LO-8m_7CpNDiZLM-FXhQ30f9gN1bUYz5lOsUPTIbI-c,4020
13
13
  fastled/live_client.py,sha256=MDauol0mxtXggV1Pv9ahC0Jjg_4wnnV6FjGEtdd9cxU,2763
14
- fastled/open_browser.py,sha256=Fv1w645rrVROaW4jjyU70Cfz6QPbyIqjK5yu16lhBlo,3836
14
+ fastled/open_browser.py,sha256=6Iu1hVve0g1Hy4L0DcInmZJfeMM5-Dqcwlv9UqfCtCg,3983
15
15
  fastled/parse_args.py,sha256=waNeATOEz8D50Py5-9p6HcVSa21piTOAWOXS3ag8PYo,9428
16
16
  fastled/paths.py,sha256=VsPmgu0lNSCFOoEC0BsTYzDygXqy15AHUfN-tTuzDZA,99
17
17
  fastled/print_filter.py,sha256=ZpebuqfWEraSBD3Dm0PVZhQVBnU_NSILniwBHwjC1qM,2342
@@ -19,13 +19,13 @@ fastled/project_init.py,sha256=bBt4DwmW5hZkm9ICt9Qk-0Nr_0JQM7icCgH5Iv-bCQs,3984
19
19
  fastled/select_sketch_directory.py,sha256=-eudwCns3AKj4HuHtSkZAFwbnf005SNL07pOzs9VxnE,1383
20
20
  fastled/server_fastapi.py,sha256=ytsL4poO-yugDIhvYJq6nCNdLZ4fQJ1AFqXkF-uEkqo,1488
21
21
  fastled/server_fastapi_cli.py,sha256=fJGLvbJx5ertsZER_lgg0GfkYTX-V2rxzbNO1lEapU0,1392
22
- fastled/server_flask.py,sha256=i0OtDdrjiF9hjKNnI2ebf6Ag-mxMmtUCxnuHMBOzx7I,4665
23
- fastled/server_start.py,sha256=NfAV5pWdXn2HDvqiMrpHxuNqh2vnB4xVFltV5Pn16GM,3509
22
+ fastled/server_flask.py,sha256=Temr1H-JXMOo0KGOs21BYRz0F7shH6Dsh_7T_bVRpsM,5851
23
+ fastled/server_start.py,sha256=muMreRRYvjme-gETWDWzmT4mRGAXpDJkFy_oJ0lJZFY,3895
24
24
  fastled/settings.py,sha256=oezRvRUJWwauO-kpC4LDbKg6Q-ij4d09UtR2vkjSAPU,575
25
25
  fastled/sketch.py,sha256=tHckjDj8P6BI_LWzUFM071a9qcqPs-r-qFWIe50P5Xw,3391
26
26
  fastled/spinner.py,sha256=VHxmvB92P0Z_zYxRajb5HiNmkHHvZ5dG7hKtZltzpcs,867
27
27
  fastled/string_diff.py,sha256=NbtYxvBFxTUdmTpMLizlgZj2ULJ-7etj72GBdWDTGws,2496
28
- fastled/types.py,sha256=mNchhIW5m6hBBv63OYE0V_u5yGnS505eWjw7HCazb_s,4694
28
+ fastled/types.py,sha256=k1j1y5h1zpRonp1mqRXy797mSbLqzf5K1QEgl8f27jQ,4822
29
29
  fastled/util.py,sha256=17f2A52TfBErJOEGC_Vs72t1mTDocLVTfnR9hWbXW8A,501
30
30
  fastled/web_compile.py,sha256=QTYHtcm55zsFxPhdA-qSPfL5Q4lhL3h3oNmir3m-Y3s,11345
31
31
  fastled/assets/example.txt,sha256=lTBovRjiz0_TgtAtbA1C5hNi2ffbqnNPqkKg6UiKCT8,54
@@ -35,9 +35,9 @@ fastled/site/build.py,sha256=2YKU_UWKlJdGnjdbAbaL0co6kceFMSTVYwH1KCmgPZA,13987
35
35
  fastled/site/examples.py,sha256=s6vj2zJc6BfKlnbwXr1QWY1mzuDBMt6j5MEBOWjO_U8,155
36
36
  fastled/test/can_run_local_docker_tests.py,sha256=LEuUbHctRhNNFWcvnz2kEGmjDJeXO4c3kNpizm3yVJs,400
37
37
  fastled/test/examples.py,sha256=GfaHeY1E8izBl6ZqDVjz--RHLyVR4NRnQ5pBesCFJFY,1673
38
- fastled-1.2.79.dist-info/licenses/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
39
- fastled-1.2.79.dist-info/METADATA,sha256=Xtk4zA6J9YhYTUwjX6pxp6vxhzH4LJhFRBQVuhExk_A,22065
40
- fastled-1.2.79.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
41
- fastled-1.2.79.dist-info/entry_points.txt,sha256=RCwmzCSOS4-C2i9EziANq7Z2Zb4KFnEMR1FQC0bBwAw,101
42
- fastled-1.2.79.dist-info/top_level.txt,sha256=Bbv5kpJpZhWNCvDF4K0VcvtBSDMa8B7PTOrZa9CezHY,8
43
- fastled-1.2.79.dist-info/RECORD,,
38
+ fastled-1.2.81.dist-info/licenses/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
39
+ fastled-1.2.81.dist-info/METADATA,sha256=dJ5jrJBU_ZPYVPE9HHC6S_61BN3-PxC297TXvEpYorc,22065
40
+ fastled-1.2.81.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
41
+ fastled-1.2.81.dist-info/entry_points.txt,sha256=RCwmzCSOS4-C2i9EziANq7Z2Zb4KFnEMR1FQC0bBwAw,101
42
+ fastled-1.2.81.dist-info/top_level.txt,sha256=Bbv5kpJpZhWNCvDF4K0VcvtBSDMa8B7PTOrZa9CezHY,8
43
+ fastled-1.2.81.dist-info/RECORD,,