fix(desktop): don't follow venv python symlink in Linux .desktop Exec - #92278
flowersjus wants to merge 1 commit into
Conversation
Path(sys.executable).resolve() turned venv/bin/python3 into /usr/bin/python3.11. The menu then launched system Python against the venv console script, which dies with ModuleNotFoundError: hermes_cli and no window (Terminal=false). Also treat #!/usr/bin/env python3 as always needing a prefix — exe_dir /usr/bin is a substring of /usr/bin/env and skipped the NousResearch#90292 fix when the running interpreter lived under /usr/bin.
Duplicate of #92090: both preserve the unresolved venv interpreter in the generated Linux desktop |
This is the more complete of the two open fixes for the venv-symlink
Comparing against the unresolved Two suggestions:
|
Bug Description
After
hermes desktoprebuilds the Linux menu entry, launching Hermes from the app menu does nothing. A TTYhermes desktopworks (including after the chrome-sandbox sudo).The generated
~/.local/share/applications/hermes.desktopcontained:That command exits 1 with
ModuleNotFoundError: hermes_cli.Terminal=false, so there is no window and no error.Follow-up to #90292 (still open). That fix prefixed
sys.executable, but.resolve()followed the venvpythonsymlink back out to the system interpreter.Root Cause
A venv's
bin/python3is typically a symlink to/usr/bin/python3.11. Invoking the system path does not activate the venv —sys.prefixstays/usr, sohermes_cliis missing.resolve_exec_command()wrotePath(sys.executable).resolve()intoExec=. After a successful TTY launch (which does use the venv shebang), the rewritten menu entry pointed at system Python.A second hole in the same helper:
_needs_interpreterusedexe_dir not in shebang. When the running interpreter lives under/usr/bin, that substring matches#!/usr/bin/env python3and skips the #90292 prefix.Fix
_running_interpreter()returnsPath(sys.executable)without following the venv→system symlink, and that path is what gets written intoExec=when a prefix is needed.venv/bin/hermes→venv/bin/python3) are left alone.#!/usr/bin/env python3always gets the prefix (no more/usr/bin⊂/usr/bin/envfalse negative).How to Verify
bin/python3is a symlink to/usr/bin/python3.X, runhermes desktoponce from a TTY.awk -F= '/^Exec=/{print substr($0,6)}' ~/.local/share/applications/hermes.desktop/usr/bin/python3.11~/.local/bin/hermes desktopor…/venv/bin/hermes desktop(or…/venv/bin/python3 …if prefixed)/usr/bin/python3.11 ~/.hermes/hermes-agent/venv/bin/hermes --version→ModuleNotFoundError: hermes_cliTest Plan
test_exec_does_not_follow_venv_python_symlink)tests/hermes_cli/test_linux_desktop_entry.pystill pass (16 passed, 2 skipped).desktopExec and confirmed--versionworks; the old Exec line fails as aboveRisk Assessment
Low — Linux
.desktopwriter only. macOS/Windows installers are no-ops here. Worst case a prefixed Exec uses the unresolved venv interpreter (correct) instead of the resolved system one (broken).