Skip to content

emrg: installer: write bin\pyvenv.cfg on Windows so bundled python venv works (#966 follow-up) - #969

Merged
argszero merged 1 commit into
masterfrom
feature/windows-pyvenv-cfg
Aug 25, 2026
Merged

emrg: installer: write bin\pyvenv.cfg on Windows so bundled python venv works (#966 follow-up)#969
argszero merged 1 commit into
masterfrom
feature/windows-pyvenv-cfg

Conversation

@pm25coder

Copy link
Copy Markdown
Collaborator

Follow-up to #966 (POSIX venv fix). On Windows, the bundled bin\python.exe / bin\python3.exe are copies of the python-dist interpreter and require a same-directory pyvenv.cfg to locate the stdlib — without it, python -m venv <dir> produces a venv whose python fails with Could not find platform independent libraries + ModuleNotFoundError: No module named 'encodings', blocking tasks that install research dependencies.

Driving rant (verbatim):

install 打包 Python 创建的 venv 不可用(pyvenv.cfg home 路径错误),任务无法安装科研依赖 — ~/.emrg/install/bin/python(Python 3.13.9)执行 python -m venv

生成的 pyvenv.cfg 中 home = ~/.emrg/install/bin,但解释器实际位于 ~/.emrg/install/bin/python-dist/bin/ —— home 路径错误导致 venv 内 python 无法定位标准库(Could not find platform independent libraries + ModuleNotFoundError: No module named 'encodings')

Changes:

  • packaging/make-installer.sh: new Inno [Code] procedure WritePyvenvCfg runs on ssPostInstall, writing {app}\bin\pyvenv.cfg with home = {app}\bin\python-dist (absolute path via ExpandConstant — a relative home fails with Failed to import encodings, verified locally). CfgContent is declared AnsiString to match SaveStringToFile's signature (same rule as the existing LogText precedent).
  • packaging/smoke-test.sh: item 14 now exercises bin\python.exe on Windows — regenerates the same cfg in-test (mirroring the installer's ssPostInstall) with an absolute home, then runs python -m venv and verifies stdlib import + pip. POSIX path unchanged (bin/python wrapper from emrg: packaging: fix bundled python venv (pyvenv.cfg home) via bin/python wrapper #966).
  • emrg/server/prompts/upgrade_prompt.j2: instructs the upgrade agent to write bin/pyvenv.cfg with the native absolute path during local equivalent installs.
  • tests/test_installer_stop.py: pure-text regression test pinning the new wiring (procedure presence, AnsiString declaration, absolute-home content, CurStepChanged ordering, smoke Windows branch, upgrade-prompt mention).
  • Agent.md: doc-count guard sync (1051 → 1052).

Verified locally: pytest 987 passed / 65 skipped, import + CLI checks green, Windows venv regression (bin\python.exe -m venv → venv OK, pip 25.2). Full installer/Inno compilation is validated by the windows Build Release CI.

@argszeroargszero left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle

Reviewed the full diff against rant 2026-08-24T21:46:53 (#966 Windows follow-up):

  • make-installer.sh: WritePyvenvCfg writes {app}\\bin\\pyvenv.cfg with absolute home = {app}\\bin\\python-dist (ExpandConstant), called in ssPostInstall BEFORE AddBinDirToPath. CfgContent: AnsiString matches Inno Setup 6.7.1+ SaveStringToFile signature (UnicodeString would fail to compile) — the dedicated test pins this exactly. CRLF (#13#10) correct for Windows.
  • smoke-test.sh: Windows branch (${WINDIR:-}) replicates the installer-written cfg with cygpath -w absolute path and exercises bin\python.exe directly — good that the 'missing DLL' R100 conclusion is corrected (DLLs are in bin; the real missing piece was the cfg).
  • upgrade_prompt.j2: local-equivalent install also writes bin/pyvenv.cfg with native absolute path, POSIX skip documented — symmetric with the installer path.
  • Test: text-assertion regression test (no iscc/cmd execution, CI-safe) covering installer [Code], smoke-test branch, and upgrade prompt; Agent.md count 1051→1052 consistent (doc-count guard green).
  • CI: test + test-windows both green (run 32799604676).

Solid follow-up completing the #966 story on Windows.

@argszeroargszero left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle (2/3)

Re-checked this cycle: head 4c709a6 unchanged, CI test + test-windows still green (run 32799604676). Confirmations from re-review:

  • WritePyvenvCfg uses AnsiString for SaveStringToFile (Inno Setup 6.7.1+ signature — UnicodeString would not compile) and writes CRLF-terminated home = {app}\bin\python-dist absolute path.
  • ssPostInstall ordering: WritePyvenvCfg before AddBinDirToPath (pinned by the regression test).
  • smoke-test.sh Windows branch replicates the cfg via cygpath -w absolute path before exercising bin\python.exe — consistent with the installer path.
  • upgrade_prompt.j2 covers local-equivalent installs (POSIX skip documented) — symmetric.
  • Doc count 1051→1052 matches the new test (#511 guard green).

No issues found; ready to merge once the 3rd LGTM lands.

@argszeroargszero left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle (3/3)

Final re-check: head 4c709a6 unchanged, CI test + test-windows green (run 32799604676), MERGEABLE. Three consecutive LGTMs from distinct cycles (100311, 101045, 101729) with no ❌. Windows pyvenv.cfg story (#966 follow-up) complete — merging.

@argszero
argszero merged commit c0a464e into masterAug 25, 2026
2 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@pm25coder@argszero