Skip to content

Commit 2ae6712

Browse files
authored
MAINT: Simplify OpenGL and warn about bad config (#378)
1 parent bc9f024 commit 2ae6712

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ jobs:
153153
# Avoid a problematic versions of PySide6
154154
# https://wiki.qt.io/Qt_for_Python_Development_Notes#1._Juni_2023
155155
if [[ "$QT_LIB" == "PySide6" ]]; then
156-
QT_LIB_INSTALL="PySide6!=6.5.1,!=6.7.0,!=6.7.1,!=6.8.0,!=6.8.0.1,!=6.9.1"
156+
if [[ "$RUNNER_OS" == "macOS" ]]; then
157+
QT_LIB_INSTALL="PySide6!=6.5.1,!=6.7.0,!=6.7.1,!=6.8.0,!=6.8.0.1,!=6.9.1,!=6.10.0"
158+
else
159+
QT_LIB_INSTALL="PySide6!=6.5.1,!=6.7.0,!=6.7.1,!=6.8.0,!=6.8.0.1,!=6.9.1"
160+
fi
157161
else
158162
QT_LIB_INSTALL="$QT_LIB"
159163
fi
@@ -162,6 +166,7 @@ jobs:
162166
else
163167
PIP_OPTION="[tests]"
164168
fi
169+
set -x
165170
python -m pip install -ve .${PIP_OPTION} ${QT_LIB_INSTALL}
166171
- run: bash ./tools/get_testing_version.sh
167172
working-directory: ../mne-python

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies = [
2424
"mne>=1.0",
2525
"pyqtgraph>=0.12.3",
2626
"pyopengl; platform_system=='Darwin'",
27+
"packaging",
2728
"darkdetect",
2829
"qdarkstyle",
2930
]

src/mne_qt_browser/_pg_figure.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@
3333
from mne.viz._figure import BrowserBase
3434
from mne.viz.backends._utils import _init_mne_qtapp, _qt_raise_window
3535
from mne.viz.utils import _merge_annotations, _simplify_float
36+
from packaging.version import parse
3637
from pyqtgraph import (
3738
InfiniteLine,
3839
PlotItem,
3940
Point,
4041
mkPen,
4142
setConfigOption,
4243
)
43-
from qtpy import API_NAME
44+
from qtpy import API_NAME, QT_VERSION
4445
from qtpy.QtCore import (
4546
QEvent,
4647
QSettings,
@@ -459,38 +460,17 @@ def __init__(self, **kwargs):
459460
self._add_scalebars()
460461

461462
# Check for OpenGL
462-
# If a user doesn't specify whether or not to use it:
463-
# 1. If on macOS, enable it by default to avoid segfault
464-
# 2. Otherwise, disable it (performance differences seem minimal, and PyOpenGL
465-
# is an optional requirement)
463+
# If a user doesn't specify whether or not to use it, disable it (performance
464+
# differences seem minimal, and PyOpenGL is an optional requirement)
466465
opengl_key = "MNE_BROWSER_USE_OPENGL"
467466
if self.mne.use_opengl is None: # default: opt-in
468-
# OpenGL needs to be enabled on macOS
469-
# (https://github.com/mne-tools/mne-qt-browser/issues/53)
470-
default = "true" if platform.system() == "Darwin" else ""
471-
config_val = get_config(opengl_key, default).lower()
467+
config_val = get_config(opengl_key, "").lower()
472468
self.mne.use_opengl = config_val == "true"
473469

474470
if self.mne.use_opengl:
475471
try:
476472
import OpenGL
477-
except (ModuleNotFoundError, ImportError) as exc:
478-
# On macOS, if use_opengl is True we raise an error because it can lead
479-
# to segfaults. If a user really knows what they are doing, they can
480-
# pass use_opengl=False (or set MNE_BROWSER_USE_OPENGL=false)
481-
if platform.system() == "Darwin":
482-
raise RuntimeError(
483-
"Plotting on macOS without OpenGL may be unstable! "
484-
"We recommend installing PyOpenGL, but it could not "
485-
f"be imported, got:\n{exc}\n\n"
486-
"If you want to try plotting without OpenGL, "
487-
"you can pass use_opengl=False (use at your own "
488-
"risk!). If you know non-OpenGL plotting is stable "
489-
"on your system, you can also set the config value "
490-
f"{opengl_key}=false to permanently change "
491-
"the default behavior on your system."
492-
) from None
493-
# otherwise, emit a warning
473+
except (ModuleNotFoundError, ImportError):
494474
warn(
495475
"PyOpenGL was not found and OpenGL cannot be used. "
496476
"Consider installing pyopengl with pip or conda or set "
@@ -499,6 +479,19 @@ def __init__(self, **kwargs):
499479
self.mne.use_opengl = False
500480
else:
501481
logger.info(f"Using pyopengl with version {OpenGL.__version__}")
482+
# detect a problematic config
483+
if (
484+
platform.system() == "Darwin"
485+
and parse(QT_VERSION) >= parse("6.10.0")
486+
and self.mne.use_opengl
487+
and not check_version("pyqtgraph", "0.13.8")
488+
): # pragma: no cover
489+
warn(
490+
"On macOS, Qt 6.10.0, pyqtgraph < 0.13.8, with use_opengl=True results "
491+
f"in very slow performance. Consider downgrading {API_NAME}, "
492+
"setting use_opengl=False (which can hurt performance), or "
493+
"upgrading pyqtgraph once 0.13.8 is released"
494+
)
502495
# Initialize BrowserView (inherits QGraphicsView)
503496
self.mne.view = BrowserView(
504497
self.mne.plt, useOpenGL=self.mne.use_opengl, background="w"

0 commit comments

Comments
 (0)