Skip to content

SG-45110 Make QtOpenGL import optional in PySide6Patcher - #1133

Closed
julien-lang wants to merge 3 commits into
masterfrom
ticket/SG-45110-qtopengl-optional-import
Closed

julien-lang wants to merge 3 commits into
masterfrom
ticket/SG-45110-qtopengl-optional-import

Conversation

@julien-lang

Copy link
Copy Markdown
Member

Problem

PySide6Patcher.patch() does an unconditional from PySide6 import (QtCore, QtGui, QtOpenGL, QtWidgets). QtOpenGL requires OpenGL/EGL shared libraries (e.g. libGL.so.1, libEGL) that may not be present on headless servers, such as the machine that runs Rundeck's Sphinx doc-generation job for tk-framework-qtwidgets (SG-45110).

When that import fails, the ImportError propagates out of PySide6Patcher.patch(), and qt_importer.py's _import_modules() silently swallows it (except ImportError: pass), so QtImporter().QtCore ends up None entirely, breaking all Qt functionality in that environment, not just the handful of Qt4-compat OpenGL classes QtOpenGL provides.

Fix

Follow the same pattern already established for QtWebEngineWidgets/QtWebEngineCore (SG-38470, #1012): fetch QtOpenGL via the existing _import_module_by_name() helper, which catches any exception and returns None on failure, and pass it into PySide6Patcher.patch() as an optional parameter. When QtOpenGL is unavailable, patch() now degrades gracefully (skips restoring the ~15 Qt4-compat OpenGL classes into QtGui, emits a RuntimeWarning) instead of losing the entire PySide6 binding.

Behavior impact

  • No change when QtOpenGL imports successfully (the normal case for DCCs bundling a full Qt with OpenGL support).
  • When QtOpenGL fails to import: previously QtCore/QtGui were both None (all Qt functionality broken). Now they're valid, minus QOpenGLBuffer, QOpenGLShader, and similar rarely used classes. A workspace-wide search across all tk-* repos found no app/engine/framework code referencing any of these classes through the Qt shim.

Testing

  • Existing tests/util_tests/test_pyside6_patcher.py::PySide6PatcherTests::test_patch still passes (now emits the new RuntimeWarning since it calls patch(None, None) without QtOpenGL).
  • Manually verified locally with a PySide6 environment that patch() returns valid, working QtCore/QtGui shims both with and without QtOpenGL passed in.

Related to SG-45110 (Rundeck doc-build failure) and SG-44795 (PySide as a tk-toolchain dependency).

QtOpenGL requires OpenGL/EGL shared libraries (e.g. libGL, libEGL) that may be
missing on headless servers such as Rundeck's doc-build environment. Today,
if that import fails, QtImporter silently swallows the ImportError and
returns None for QtCore/QtGui entirely, breaking all Qt functionality instead
of just the handful of Qt4-compat OpenGL classes it provides.

Follow the same pattern already used for QtWebEngineWidgets/QtWebEngineCore
(SG-38470): fetch QtOpenGL via _import_module_by_name() so a failure only
degrades gracefully (with a warning) instead of taking down the whole
PySide6 binding.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Add an importer-boundary regression test covering failed QtOpenGL loading.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Makes QtOpenGL optional so PySide6 remains usable in headless environments.

Changes:

  • Loads QtOpenGL separately with graceful failure handling.
  • Skips OpenGL compatibility classes and emits a warning when unavailable.
  • Passes optional QtOpenGL support to the patcher.
File summaries
File Description
python/tank/util/qt_importer.py Handles optional QtOpenGL loading.
python/tank/util/pyside6_patcher.py Gracefully handles missing OpenGL support.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

# QtOpenGL requires OpenGL/EGL shared libraries that may be missing on headless
# servers, so import it separately rather than letting it take down the whole
# PySide6 import.
QtOpenGL = self._import_module_by_name("PySide6", "QtOpenGL")
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.11%. Comparing base (889c1cd) to head (77cf770).

Files with missing lines Patch % Lines
python/tank/util/qt_importer.py 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1133      +/-   ##
==========================================
+ Coverage   80.09%   80.11%   +0.01%     
==========================================
  Files         203      203              
  Lines       19537    19538       +1     
==========================================
+ Hits        15649    15652       +3     
+ Misses       3888     3886       -2     
Flag Coverage Δ
Linux 79.54% <33.33%> (+<0.01%) ⬆️
Python-3.10 79.92% <0.00%> (+<0.01%) ⬆️
Python-3.11 79.81% <33.33%> (+<0.01%) ⬆️
Python-3.13 79.81% <33.33%> (+<0.01%) ⬆️
Python-3.9 79.88% <0.00%> (+<0.01%) ⬆️
Windows 79.57% <33.33%> (+0.01%) ⬆️
macOS 79.51% <33.33%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@julien-lang
julien-lang deleted the ticket/SG-45110-qtopengl-optional-import branch September 16, 2026 17:47
Sign up for free to 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