@danhachuel/thunderbolt 0.5.13 → 0.5.14

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.5.09 (normalizado pelo npm para 0.5.9)
4
+
5
+ Adicionado um shim de compatibilidade que intercepta a escrita de saída do Click antes do carregamento do Streamlit e grava directamente em UTF-8, evitando o caminho nativo que volta a procurar `utf-16-le` durante o shutdown do Windows. Incluídos testes com um console simulado em `utf-16-le`.
6
+
7
+ ## 0.5.08 (normalizado pelo npm para 0.5.8)
8
+
9
+ Corrigido o erro `LookupError: unknown encoding: utf-16-le` que podia ocorrer durante o shutdown do Streamlit no Windows. O launcher Node agora materializa as variáveis de encoding e `CLICK_NO_WIN_CONSOLE` no processo pai antes de iniciar Python; os workers de automação e pipeline também aplicam as mesmas definições antes dos imports restantes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danhachuel/thunderbolt",
3
- "version": "0.5.13",
3
+ "version": "0.5.14",
4
4
  "description": "Thunderbolt — interface local para operação de canais faceless e motor MoneyPrinterTurbo",
5
5
  "license": "MIT",
6
6
  "main": "scripts/cli.mjs",
@@ -25,6 +25,7 @@
25
25
  "seed/references/*.md",
26
26
  "seed/references/*.sql",
27
27
  "README.md",
28
+ "CHANGELOG.md",
28
29
  "MANUAL-INSTALACAO.md",
29
30
  "THIRD-PARTY-NOTICES.md",
30
31
  "requirements.txt",
@@ -1,8 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
- import io
4
3
  import os
5
4
  import sys
5
+ from windows_encoding_compat import install as install_windows_encoding, wrap_stream
6
6
 
7
7
  # Este ficheiro é o primeiro módulo Python executado pelo launcher. As
8
8
  # variáveis e os streams precisam de ser corrigidos antes de qualquer import
@@ -11,6 +11,7 @@ os.environ["PYTHONIOENCODING"] = "utf-8"
11
11
  os.environ["PYTHONUTF8"] = "1"
12
12
  os.environ["PYTHONLEGACYWINDOWSSTDIO"] = "1"
13
13
  os.environ["CLICK_NO_WIN_CONSOLE"] = "1"
14
+ install_windows_encoding()
14
15
 
15
16
 
16
17
  def _utf8_stream(stream: object) -> object:
@@ -20,7 +21,7 @@ def _utf8_stream(stream: object) -> object:
20
21
  if buffer is None:
21
22
  return stream
22
23
  try:
23
- return io.TextIOWrapper(buffer, encoding="utf-8", errors="replace", line_buffering=True)
24
+ return wrap_stream(stream)
24
25
  except (AttributeError, OSError, ValueError):
25
26
  return stream
26
27
 
@@ -0,0 +1,67 @@
1
+ """Windows console compatibility for Click/Streamlit shutdown output."""
2
+ from __future__ import annotations
3
+
4
+ import io
5
+ import os
6
+ import sys
7
+ from typing import Any, Callable
8
+
9
+
10
+ _UTF8_ENV = {
11
+ "CLICK_NO_WIN_CONSOLE": "1",
12
+ "PYTHONIOENCODING": "utf-8",
13
+ "PYTHONUTF8": "1",
14
+ }
15
+
16
+
17
+ def _safe_click_echo(original: Callable[..., Any]) -> Callable[..., Any]:
18
+ def echo(message: Any = None, file: Any = None, nl: bool = True, err: bool = False, color: Any = None) -> Any:
19
+ target = file if file is not None else (sys.stderr if err else sys.stdout)
20
+ if message is None:
21
+ message = ""
22
+ text = str(message) + ("\n" if nl else "")
23
+ buffer = getattr(target, "buffer", None)
24
+ try:
25
+ if buffer is not None and hasattr(buffer, "write"):
26
+ buffer.write(text.encode("utf-8", "replace"))
27
+ if hasattr(buffer, "flush"):
28
+ buffer.flush()
29
+ else:
30
+ target.write(text)
31
+ if hasattr(target, "flush"):
32
+ target.flush()
33
+ return None
34
+ except (AttributeError, OSError, UnicodeError, ValueError, LookupError):
35
+ # Fall back to Click for non-console streams (files, testing runners).
36
+ return original(message, file=file, nl=nl, err=err, color=color)
37
+
38
+ echo.__name__ = getattr(original, "__name__", "echo")
39
+ echo.__doc__ = getattr(original, "__doc__", None)
40
+ return echo
41
+
42
+
43
+ def install(*, force: bool = False) -> None:
44
+ """Install the Windows-safe Click output path before Streamlit imports Click."""
45
+ os.environ.update(_UTF8_ENV)
46
+ if not force and os.name != "nt":
47
+ return
48
+ try:
49
+ import click
50
+ except ImportError:
51
+ return
52
+ if getattr(click, "_thunderbolt_utf8_echo", False):
53
+ return
54
+ click.echo = _safe_click_echo(click.echo)
55
+ click._thunderbolt_utf8_echo = True
56
+
57
+
58
+ def wrap_stream(stream: Any) -> Any:
59
+ """Wrap a text stream as UTF-8 without closing its inherited buffer twice."""
60
+ if stream is None or getattr(stream, "buffer", None) is None:
61
+ return stream
62
+ try:
63
+ wrapper = io.TextIOWrapper(stream.buffer, encoding="utf-8", errors="replace", line_buffering=True)
64
+ setattr(wrapper, "_thunderbolt_utf8", True)
65
+ return wrapper
66
+ except (AttributeError, OSError, ValueError):
67
+ return stream