Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions de_shell/js/main/envProgress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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 }
Expand Down
33 changes: 32 additions & 1 deletion de_shell/js/main/pythonEnv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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')
})
33 changes: 33 additions & 0 deletions de_shell/js/main/pythonEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> {
const added: Record<string, string> = {}
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,
Expand Down
6 changes: 4 additions & 2 deletions de_shell/js/packaging/build-wheelhouse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `./<file>`, and Explorer's Extract All rejects the zip.
execFileSync(bsdtar, ['-a', '-c', '-f', zipPath, '-C', dir, ...readdirSync(dir)], { stdio: 'inherit' })
return
}
try {
Expand Down
8 changes: 8 additions & 0 deletions de_shell/js/packaging/installer.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion de_shell/log_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ───────────
Expand Down
50 changes: 50 additions & 0 deletions tests/test_log_stream.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions upcoming_changes/37.bugfix.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
On Windows, first-start setup can clone git dependencies into paths over 260 characters, without changing the user's git config.
1 change: 1 addition & 0 deletions upcoming_changes/37.bugfix.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
First-run setup names the app it is building instead of saying "Building the SpyDE package" in every app.
1 change: 1 addition & 0 deletions upcoming_changes/37.bugfix.3.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Windows Explorer's Extract All opens the offline wheels zip, whose entries no longer start with ``./``.
1 change: 1 addition & 0 deletions upcoming_changes/37.bugfix.4.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Uninstalling removes the auto-updater's copy of the installer from Local AppData, except during an update.
1 change: 1 addition & 0 deletions upcoming_changes/37.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions upcoming_changes/37.new_feature.rst
Original file line number Diff line number Diff line change
@@ -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.
Loading