mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 14:39:58 -04:00
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:
@@ -29,6 +29,10 @@ class Context:
|
||||
self._file = None
|
||||
self.log(f'--- NX2navi launcher {self.version} ({"checkout" if self.layout.dev else "release"}) in '
|
||||
f'{self.layout.root}')
|
||||
from .toolchain import zstd_missing
|
||||
self.zstd_missing = zstd_missing(self.layout)
|
||||
if self.zstd_missing:
|
||||
self.log(self.zstd_missing)
|
||||
if self.settings.unreadable:
|
||||
self.log(f'{self.layout.settings} is not valid JSON: the settings start from their defaults; the file as '
|
||||
'it was is kept as launcher.json.bad')
|
||||
|
||||
@@ -276,6 +276,9 @@ class Job:
|
||||
def ensure_tools(self, sid):
|
||||
layout = self.ctx.layout
|
||||
self.begin(sid)
|
||||
missing = toolchain.zstd_missing(layout)
|
||||
if missing:
|
||||
raise toolchain.ToolchainError(missing)
|
||||
lock = toolchain.load_lock(layout, self.ctx.version)
|
||||
if toolchain.is_current(layout, lock):
|
||||
have_tools = True
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -744,6 +744,8 @@ class App:
|
||||
self.ctx.log(f'the stub went back from {a.rolled_back} to {self.layout.version}')
|
||||
self.settings['rolled_back'] = versions.display(a.rolled_back) # never installed again by itself
|
||||
self.settings.save()
|
||||
if self.ctx.zstd_missing: # told at once, not when Begin Installation stops at the build tools
|
||||
self.message = self.ctx.zstd_missing
|
||||
for old in self.layout.root.glob('python.old*'): # the Python an update replaced (launcher/native/nx2navi.c)
|
||||
shutil.rmtree(old, ignore_errors=True)
|
||||
if gd or self.settings.get('dump'):
|
||||
|
||||
Reference in New Issue
Block a user