Skip to content

fix: detect available Linux terminal emulator instead of hardcoding gnome-terminal - #622

Open
tusharbana-ansys wants to merge 1 commit into
mainfrom
fix/wsl-terminal-detection-591
Open

fix: detect available Linux terminal emulator instead of hardcoding gnome-terminal#622
tusharbana-ansys wants to merge 1 commit into
mainfrom
fix/wsl-terminal-detection-591

Conversation

@tusharbana-ansys

Copy link
Copy Markdown
Contributor

Summary

Fixes #591 — Ansys Python Manager silently did nothing when clicking any action (Console, Install, Create venv, Uninstall, etc.) on Linux/WSL systems that don't have gnome-terminal installed, which is the common case on WSL.

Root cause

  • execute_linux_command() in linux_functions.py hardcoded gnome-terminal for every Linux command execution, via a bare os.system(...) call whose exit status was never checked.
  • WSL distributions (and many minimal Linux installs) don't ship gnome-terminal by default, so the command silently failed with no feedback to the user.
  • Compounding this, the Ubuntu prerequisites (docs + installer.sh) told users to install the entire gnome desktop metapackage instead of just gnome-terminal.

Changes

  • Terminal detection & fallback (linux_functions.py):
    • Added find_linux_terminal(), which detects the first available terminal emulator via shutil.which() from a prioritized list: gnome-terminal, konsole, xfce4-terminal, mate-terminal, tilix, xterm, x-terminal-emulator.
    • execute_linux_command() now uses whichever terminal is found, building the command with subprocess argv lists instead of os.system() (also fixes a latent shell-quoting bug from the old string-interpolated approach).
    • Raises a new NoLinuxTerminalError with a clear, actionable message (e.g. sudo apt-get install xterm) when no terminal emulator is available, instead of failing silently.
  • Surface errors to the user instead of failing silently or misleadingly:
    • installed_table.py: Console/launch/package-management actions now show an error dialog via show_error() on failure.
    • uninstall.py: the uninstall confirmation flow previously had no error handling at all around the terminal launch — now wrapped and surfaced via show_error().
    • create_virtual_environment.py: venv creation previously showed a failure dialog and then unconditionally also showed a "successfully created" dialog right after — fixed to stop after the failure dialog.
  • Fixed a related latent bug: find_miniforge_linux() passed a shell pipe (printenv | grep ...) to subprocess.check_output() without shell=True, so it always silently failed to detect system conda. Replaced with a direct os.environ["CONDA_PYTHON_EXE"] lookup.
  • Docs & installer script: Ubuntu prerequisites now require gnome-terminal (not the full gnome desktop), matching what CentOS9/RHEL9/Fedora docs already said, plus a note recommending a lightweight xterm install for WSL.
  • Tests: added regression tests for terminal detection and the no-terminal error path (tests/test_linux_functions.py).

Testing

  • pytest tests/test_linux_functions.py tests/test_auto_updater.py tests/test_metadata.py — all passing.
  • Verified end-to-end on real WSL distributions via WSLg (genuine Qt/xcb GUI, real button clicks), covering both the "no terminal" and "xterm installed" scenarios, across:
    • Ubuntu 22.04 (apt)
    • AlmaLinux 9 (RHEL9/CentOS9 family, dnf)
    • Fedora 43 (dnf)
  • For each distribution: confirmed a clear error dialog (not a silent no-op) when no terminal emulator is present, and confirmed a real terminal process actually launches and the requested command completes once a terminal (e.g. xterm) is installed — for the Console action, virtual environment creation, and the uninstall flow.

Notes / follow-ups (out of scope for this PR)

  • execute_linux_command() only verifies that the terminal launched, not that the wrapped script succeeded — pre-existing design gap (also applies to the Windows code path), not something we changed here.

…nome-terminal (#591)

- Add find_linux_terminal() to detect gnome-terminal, konsole, xfce4-terminal, mate-terminal, tilix, xterm, or x-terminal-emulator via shutil.which
- Raise a clear NoLinuxTerminalError with actionable guidance when none are found, instead of silently doing nothing (the root cause of #591 on WSL, which ships no terminal emulator by default)
- Rewrite execute_linux_command to use subprocess argv lists instead of os.system, fixing a latent shell-quoting bug
- Surface terminal-launch failures to the user via show_error() in installed_table.py (Console/launch actions), uninstall.py (uninstall flow), and create_virtual_environment.py (venv creation), instead of failing silently or showing a misleading success dialog after a failure
- Fix find_miniforge_linux() silently failing to detect system conda (invalid shell pipe passed to subprocess without shell=True)
- Fix Ubuntu prerequisites (docs + installer.sh) requiring the full gnome desktop metapackage instead of just gnome-terminal
- Add regression tests for terminal detection and the no-terminal error path
@github-actions github-actions Bot added documentation Improvements or additions to documentation bug Something isn't working labels Aug 5, 2026
@tusharbana-ansys

Copy link
Copy Markdown
Contributor Author

Although automated tests have passed, I am still testing this manually on each supported distro. Please do not merge yet.
cc - @RobPasMue

@tusharbana-ansys tusharbana-ansys added the enhancement New features or code improvements label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New features or code improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WSL not working with Ansys Python Manager

1 participant