Check at startup that the launcher's Python can read zstd files, and say how to fix it when it cannot.

Run from a checkout, the launcher uses the Python that started it. A Python older than 3.14 without the zstandard
package got through the first-run screen and stopped at Gather Build Tools with only "No module named 'zstandard'",
after the packages were downloaded. toolchain.zstd_missing now looks for compression.zstd or zstandard when the
launcher starts. Without either, the log and the first screen name the Python and give the pip line for
tools/requirements-launcher.txt, and Gather Build Tools stops with the same message before it unpacks anything. A
release's own Python always has the package; if it ever lacks it, the message says to reinstall NX2navi.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 07:16:14 -05:00
parent ee46a19ede
commit d2ab9a00be
6 changed files with 48 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ zbic (GPL-2.0) unpacks the game's compressed program files. The release does not
wheel for its own Python from PyPI and unpacks it into pydeps/, as `pip install zbic` would.
"""
import hashlib
import importlib
import io
import json
import os
@@ -53,6 +54,25 @@ class ToolchainError(Exception):
# ---------------------------------------------------------------- the package database
def zstd_missing(layout):
"""Why this Python cannot read zstd files, or '' when it can. The MSYS2 packages and the game's files are zstd:
Python 3.14 reads them with compression.zstd, an older Python needs the zstandard package. The release's Python
has both; a checkout runs under whatever Python started it, and without either the build stopped at its first
unpack with nothing but "No module named 'zstandard'"."""
for name in ('compression.zstd', 'zstandard'):
try:
importlib.import_module(name)
return ''
except ImportError:
pass
ver = '.'.join(map(str, sys.version_info[:3]))
if not layout.dev:
return f'The launcher\'s Python ({ver}) is missing its zstandard package. Reinstall NX2navi.'
req = layout.app / 'tools' / 'requirements-launcher.txt'
return (f'This Python ({ver}) cannot unpack the build tools: before 3.14 it needs the zstandard package. '
f'Install the launcher\'s packages with: "{sys.executable}" -m pip install -r "{req}"')
def _zstd_decompress_stream(data):
try:
from compression import zstd # Python 3.14