diff --git a/de_shell/js/main/envProgress.ts b/de_shell/js/main/envProgress.ts index d73bfc8..8b7d3a9 100644 --- a/de_shell/js/main/envProgress.ts +++ b/de_shell/js/main/envProgress.ts @@ -12,11 +12,13 @@ * (test_env_progress.ts) without spawning uv. */ +import { shellConfig } from './config.ts' + export type EnvPhase = | 'resolving' // building the dependency graph | 'downloading' // fetching wheels/sdists | 'installing' // unpacking into the venv - | 'building' // building the editable spyde package (setuptools_scm) + | 'building' // building the app's own package (setuptools_scm) | 'torch' // the per-machine torch step (the big one) | 'working' // fallback: uv said something we don't specifically classify @@ -30,6 +32,15 @@ export interface EnvProgressEvent { const KNOWN_BIG = /\btorch\b/i +/** "Ground Crew package", or "app's package" when the shell is not configured. */ +function appPackageName(): string { + try { + return `${shellConfig().appName} package` + } catch { + return "app's package" + } +} + /** * Classify ONE raw line of uv output. Returns null for noise (blank lines, * lines we can't meaningfully turn into a step) — the caller keeps the last @@ -101,7 +112,7 @@ export function parseUvLine(raw: string): EnvProgressEvent | null { } } if (/^Building\b/i.test(line) || /setuptools[_-]scm|Building wheel|Building editable/i.test(line)) { - return { phase: 'building', step: 'Building the SpyDE package', percent: null } + return { phase: 'building', step: `Building the ${appPackageName()}`, percent: null } } if (/^Audit(ing|ed)\b/i.test(line)) { return { phase: 'installing', step: 'Finalizing the environment', percent: null } diff --git a/de_shell/js/main/pythonEnv.test.ts b/de_shell/js/main/pythonEnv.test.ts index 3c71f7a..67d038b 100644 --- a/de_shell/js/main/pythonEnv.test.ts +++ b/de_shell/js/main/pythonEnv.test.ts @@ -30,7 +30,7 @@ import { findUv, resolvePythonEnv, hasNvidiaGpu, readWheelhouse, findWheelhouse, wheelhouseCandidates, lockStamp, buildSyncArgs, offlinePlan, effectiveExtras, gpuEnvOverride, platformMatches, fileUrl, checkWheelhouseExtras, venvPython, clearBrokenEnv, - withoutPythonDownloadLines, + withoutPythonDownloadLines, uvNetworkEnv, } from './pythonEnv.ts' configureShell({ @@ -399,3 +399,34 @@ test('clearBrokenEnv keeps a real venv and ignores a missing dir', () => { assert.equal(existsSync(join(envDir, 'pyvenv.cfg')), true) assert.equal(clearBrokenEnv(join(tempDir('none-'), 'python-env')), false) }) + +test('uvNetworkEnv trusts the system certificate store under both spellings', () => { + const added = uvNetworkEnv({}, false) + assert.equal(added.UV_SYSTEM_CERTS, '1') + assert.equal(added.UV_NATIVE_TLS, '1') + assert.equal(added.GIT_CONFIG_COUNT, undefined) +}) + +test('uvNetworkEnv leaves a certificate choice the user made, including 0', () => { + assert.deepEqual(uvNetworkEnv({ UV_SYSTEM_CERTS: '0' }, false), {}) + assert.deepEqual(uvNetworkEnv({ UV_NATIVE_TLS: '0' }, false), {}) +}) + +test('uvNetworkEnv turns on git long paths on Windows', () => { + const added = uvNetworkEnv({}, true) + assert.equal(added.GIT_CONFIG_COUNT, '1') + assert.equal(added.GIT_CONFIG_KEY_0, 'core.longpaths') + assert.equal(added.GIT_CONFIG_VALUE_0, 'true') +}) + +test('uvNetworkEnv appends to git environment config already set', () => { + const added = uvNetworkEnv({ GIT_CONFIG_COUNT: '2' }, true) + assert.equal(added.GIT_CONFIG_COUNT, '3') + assert.equal(added.GIT_CONFIG_KEY_2, 'core.longpaths') + assert.equal(added.GIT_CONFIG_KEY_0, undefined) +}) + +test('the building step names the configured app, not SpyDE', () => { + const event = parseUvLine('Building test-app @ file:///C:/app') + assert.equal(event?.step, 'Building the Test App package') +}) diff --git a/de_shell/js/main/pythonEnv.ts b/de_shell/js/main/pythonEnv.ts index cf455d5..030c221 100644 --- a/de_shell/js/main/pythonEnv.ts +++ b/de_shell/js/main/pythonEnv.ts @@ -593,10 +593,43 @@ function uvEnv( // then points at something this app neither owns nor removes, and which // may vanish under it. Seen in testing: a venv linked to a stray launcher. UV_MANAGED_PYTHON: '1', + ...uvNetworkEnv(process.env, isWin), ...extraEnv, } } +/** + * Settings that keep uv's downloads and git clones working on locked-down + * machines. + * + * - Trust the operating system's certificate store. uv defaults to its own + * bundled roots, so behind an institutional proxy that re-signs HTTPS with a + * root installed in the system store, every download fails while browsers on + * the same PC work. Both spellings are set because the uv an app ships is the + * app's choice: `UV_SYSTEM_CERTS` is current, `UV_NATIVE_TLS` is what older uv + * reads. A value the user already set, including `0`, is left alone. + * - On Windows, let git use paths over 260 characters for the clones uv runs + * (`git+https` dependencies). MinGit ships with `core.longpaths` off, and a + * deep user-data folder put a clone past the limit. Passed as git's + * environment config, so the user's own git config is never touched; any + * environment config entries already set are kept. + */ +export function uvNetworkEnv(env: NodeJS.ProcessEnv, windows: boolean): Record { + const added: Record = {} + if (env.UV_SYSTEM_CERTS === undefined && env.UV_NATIVE_TLS === undefined) { + added.UV_SYSTEM_CERTS = '1' + added.UV_NATIVE_TLS = '1' + } + if (windows) { + const existing = Number.parseInt(env.GIT_CONFIG_COUNT ?? '0', 10) + const index = existing > 0 ? existing : 0 + added.GIT_CONFIG_COUNT = String(index + 1) + added[`GIT_CONFIG_KEY_${index}`] = 'core.longpaths' + added[`GIT_CONFIG_VALUE_${index}`] = 'true' + } + return added +} + /** Spawn the bundled (or PATH) uv with `args`, streaming output to onProgress. */ function runUv( projectDir: string, diff --git a/de_shell/js/packaging/build-wheelhouse.mjs b/de_shell/js/packaging/build-wheelhouse.mjs index 4f052b0..08f9ced 100644 --- a/de_shell/js/packaging/build-wheelhouse.mjs +++ b/de_shell/js/packaging/build-wheelhouse.mjs @@ -215,8 +215,10 @@ function zipDir(dir, zipPath) { if (process.platform === 'win32') { // bsdtar ships with Windows 10+ and writes a zip for `-a` on a .zip name. // Named by full path: under Git Bash `tar` is GNU tar, which has no -a. - const bsdtar = join(process.env.SystemRoot ?? 'C:\Windows', 'System32', 'tar.exe') - execFileSync(bsdtar, ['-a', '-c', '-f', zipPath, '-C', dir, '.'], { stdio: 'inherit' }) + const bsdtar = join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'tar.exe') + // List the entries rather than passing `.`: bsdtar keeps the `.` it is given, so + // every name comes out as `./`, and Explorer's Extract All rejects the zip. + execFileSync(bsdtar, ['-a', '-c', '-f', zipPath, '-C', dir, ...readdirSync(dir)], { stdio: 'inherit' }) return } try { diff --git a/de_shell/js/packaging/installer.nsh b/de_shell/js/packaging/installer.nsh index ddfdc4f..49de246 100644 --- a/de_shell/js/packaging/installer.nsh +++ b/de_shell/js/packaging/installer.nsh @@ -224,6 +224,14 @@ Var deShellSetupPid ${endif} deShellKeepData: + ; The auto-updater keeps a copy of the installer here (about the size of the + ; Setup exe). It is not user data, so a real uninstall removes it whatever the + ; answer above. An update runs this uninstaller with --updated and still needs + ; its copy, so leave it then. + ${ifNot} ${isUpdated} + RMDir /r "$LOCALAPPDATA\${APP_PACKAGE_NAME}-updater" + ${endif} + ; Put the context back the way electron-builder's uninstaller expects it. ; $installMode only exists in assisted (non-oneClick) installers. !ifndef ONE_CLICK diff --git a/de_shell/log_stream.py b/de_shell/log_stream.py index 2ab921f..8a95203 100644 --- a/de_shell/log_stream.py +++ b/de_shell/log_stream.py @@ -167,12 +167,25 @@ def set_level(level) -> int: return lv +def buffered() -> list[dict]: + """The buffered log entries, oldest first, as copies. + + Each entry is the same dict a live ``log`` message carries. Empty until + :func:`install` has run. For an app that sends the history somewhere other + than the renderer's log panel, such as a newly attached remote client; + :func:`emit_backfill` would also repopulate a panel the user cleared. + """ + if _handler is None: + return [] + return [dict(entry) for entry in list(_handler.buffer)] + + def emit_backfill() -> None: """Re-emit buffered records so a freshly-opened panel shows recent history.""" if _handler is None: return from de_shell.ipc import emit - emit({"type": "log_backfill", "entries": list(_handler.buffer)}) + emit({"type": "log_backfill", "entries": buffered()}) # ── staged handler (session.py dispatch: fn(session, plot, payload)) ─────────── diff --git a/tests/test_log_stream.py b/tests/test_log_stream.py new file mode 100644 index 0000000..074aa79 --- /dev/null +++ b/tests/test_log_stream.py @@ -0,0 +1,50 @@ +""" +test_log_stream.py — the public view of the buffered log ring. +""" +from __future__ import annotations + +import logging + +import pytest + +from de_shell import ipc, log_stream + + +@pytest.fixture +def handler(monkeypatch): + sent: list[dict] = [] + monkeypatch.setattr(ipc, "emit", sent.append) + installed = log_stream.IPCLogHandler(level=logging.DEBUG) + monkeypatch.setattr(log_stream, "_handler", installed) + installed.sent = sent + return installed + + +def record(message: str, level: int = logging.WARNING) -> logging.LogRecord: + return logging.LogRecord("app.module", level, __file__, 1, message, None, None) + + +class TestBuffered: + def test_empty_before_install(self, monkeypatch): + monkeypatch.setattr(log_stream, "_handler", None) + assert log_stream.buffered() == [] + + def test_returns_the_entries_a_live_log_message_carries(self, handler): + handler.emit(record("first")) + handler.emit(record("second")) + entries = log_stream.buffered() + assert [entry["msg"] for entry in entries] == ["first", "second"] + assert entries == handler.sent + + def test_returns_copies(self, handler): + handler.emit(record("kept")) + log_stream.buffered()[0]["msg"] = "changed" + log_stream.buffered().clear() + assert [entry["msg"] for entry in log_stream.buffered()] == ["kept"] + + def test_backfill_sends_the_same_entries(self, handler): + handler.emit(record("history")) + log_stream.emit_backfill() + backfill = handler.sent[-1] + assert backfill["type"] == "log_backfill" + assert backfill["entries"] == log_stream.buffered() diff --git a/upcoming_changes/37.bugfix.1.rst b/upcoming_changes/37.bugfix.1.rst new file mode 100644 index 0000000..1fd321f --- /dev/null +++ b/upcoming_changes/37.bugfix.1.rst @@ -0,0 +1 @@ +On Windows, first-start setup can clone git dependencies into paths over 260 characters, without changing the user's git config. diff --git a/upcoming_changes/37.bugfix.2.rst b/upcoming_changes/37.bugfix.2.rst new file mode 100644 index 0000000..57ee2bb --- /dev/null +++ b/upcoming_changes/37.bugfix.2.rst @@ -0,0 +1 @@ +First-run setup names the app it is building instead of saying "Building the SpyDE package" in every app. diff --git a/upcoming_changes/37.bugfix.3.rst b/upcoming_changes/37.bugfix.3.rst new file mode 100644 index 0000000..469ffb1 --- /dev/null +++ b/upcoming_changes/37.bugfix.3.rst @@ -0,0 +1 @@ +Windows Explorer's Extract All opens the offline wheels zip, whose entries no longer start with ``./``. diff --git a/upcoming_changes/37.bugfix.4.rst b/upcoming_changes/37.bugfix.4.rst new file mode 100644 index 0000000..74e8278 --- /dev/null +++ b/upcoming_changes/37.bugfix.4.rst @@ -0,0 +1 @@ +Uninstalling removes the auto-updater's copy of the installer from Local AppData, except during an update. diff --git a/upcoming_changes/37.bugfix.rst b/upcoming_changes/37.bugfix.rst new file mode 100644 index 0000000..6564d5b --- /dev/null +++ b/upcoming_changes/37.bugfix.rst @@ -0,0 +1 @@ +First-start setup trusts the operating system's certificate store, so it works behind an institutional proxy that re-signs HTTPS; a setting the user already made is left alone. diff --git a/upcoming_changes/37.new_feature.rst b/upcoming_changes/37.new_feature.rst new file mode 100644 index 0000000..72b74b9 --- /dev/null +++ b/upcoming_changes/37.new_feature.rst @@ -0,0 +1 @@ +``log_stream.buffered()`` returns copies of the buffered log entries, for apps that send the log history somewhere other than the log panel.