From 9759d992428c00316f130382c6048afa8b20ccc6 Mon Sep 17 00:00:00 2001 From: Cyberfisch14 <274916610+chewinggum604-art@users.noreply.github.com> Date: Mon, 11 May 2026 13:37:44 +0200 Subject: [PATCH] Fix Windows compatibility: UTF-8 stdout, pip self-upgrade, complete UA --- scripts/config.py | 2 +- scripts/run.py | 24 ++++++++++++++++++++---- scripts/setup_environment.py | 6 ++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index 4486b55..0a6bee5 100755 --- a/scripts/config.py +++ b/scripts/config.py @@ -36,7 +36,7 @@ '--no-default-browser-check' ] -USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' +USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36' # Timeouts LOGIN_TIMEOUT_MINUTES = 10 diff --git a/scripts/run.py b/scripts/run.py index 7c47a92..0b2ab77 100755 --- a/scripts/run.py +++ b/scripts/run.py @@ -4,8 +4,15 @@ Ensures all scripts run with the correct virtual environment """ -import os import sys + +# Force UTF-8 for stdout/stderr so emoji prints don't crash on Windows, +# where the default console encoding is cp1252. +if hasattr(sys.stdout, 'reconfigure'): + sys.stdout.reconfigure(encoding='utf-8', errors='replace') + sys.stderr.reconfigure(encoding='utf-8', errors='replace') + +import os import subprocess from pathlib import Path @@ -34,8 +41,11 @@ def ensure_venv(): print("šŸ”§ First-time setup: Creating virtual environment...") print(" This may take a minute...") - # Run setup with system Python - result = subprocess.run([sys.executable, str(setup_script)]) + # Run setup with system Python; propagate UTF-8 so the setup + # script's emoji prints survive on Windows. + setup_env = os.environ.copy() + setup_env.setdefault('PYTHONIOENCODING', 'utf-8') + result = subprocess.run([sys.executable, str(setup_script)], env=setup_env) if result.returncode != 0: print("āŒ Failed to set up environment") sys.exit(1) @@ -86,9 +96,15 @@ def main(): # Build command cmd = [str(venv_python), str(script_path)] + script_args + # Propagate UTF-8 to the child process so emoji prints in the called + # script (auth_manager / notebook_manager / ask_question) don't crash + # on Windows. + child_env = os.environ.copy() + child_env.setdefault('PYTHONIOENCODING', 'utf-8') + # Run the script try: - result = subprocess.run(cmd) + result = subprocess.run(cmd, env=child_env) sys.exit(result.returncode) except KeyboardInterrupt: print("\nāš ļø Interrupted by user") diff --git a/scripts/setup_environment.py b/scripts/setup_environment.py index a4167d0..bebd08e 100755 --- a/scripts/setup_environment.py +++ b/scripts/setup_environment.py @@ -50,9 +50,11 @@ def ensure_venv(self) -> bool: if self.requirements_file.exists(): print("šŸ“¦ Installing dependencies...") try: - # Upgrade pip first + # Upgrade pip via `python -m pip` (instead of `pip.exe install + # --upgrade pip`) so Windows can replace pip without hitting a + # FileLock on the running pip.exe. subprocess.run( - [str(self.venv_pip), "install", "--upgrade", "pip"], + [str(self.venv_python), "-m", "pip", "install", "--upgrade", "pip"], check=True, capture_output=True, text=True