Skip to content

Commit

Permalink
better way to patch close all
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrockhill committed Jul 22, 2022
1 parent 6d43ed8 commit 4bba703
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
11 changes: 2 additions & 9 deletions mne/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,7 @@ def _use_backend(backend_name, interactive):
try:
yield renderer
finally:
try: # remove when pyvista 0.35.2 patch is released
renderer.backend._close_all()
except AttributeError:
pass
renderer.backend._close_all()


def _check_skip_backend(name):
Expand Down Expand Up @@ -737,11 +734,7 @@ def brain_gc(request):
from mne.viz import Brain
ignore = set(id(o) for o in gc.get_objects())
yield
try: # remove when pyvista 0.35.2 patch is released
close_func()
except AttributeError:
pass

close_func()
# no need to warn if the test itself failed, pytest-harvest helps us here
try:
outcome = request.node.harvest_rep_call
Expand Down
10 changes: 9 additions & 1 deletion mne/viz/backends/_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@
_AbstractWidgetList, _AbstractAction, _AbstractDialog,
_AbstractKeyPress)
from ._pyvista import _PyVistaRenderer, Plotter
from ._pyvista import (_close_all, _close_3d_figure, _check_3d_figure, # noqa: F401,E501 analysis:ignore
from ._pyvista import (_close_3d_figure, _check_3d_figure, # noqa: F401,E501 analysis:ignore
_set_3d_view, _set_3d_title, _take_3d_screenshot) # noqa: F401,E501 analysis:ignore


def _close_all():
from ._pyvista import _close_all
try: # remove when pyvista 0.35.2 patch is released
_close_all()
except AttributeError:
pass


# from: https://fontawesome.com/icons
_ICON_LUT = dict(help='question', play='play', pause='pause',
reset='history', scale='magic',
Expand Down
11 changes: 10 additions & 1 deletion mne/viz/backends/_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
QSpinBox, QStyle, QStyleOptionSlider)

from ._pyvista import _PyVistaRenderer
from ._pyvista import (_close_all, _close_3d_figure, _check_3d_figure, # noqa: F401,E501 analysis:ignore
from ._pyvista import (_close_3d_figure, _check_3d_figure, # noqa: F401,E501 analysis:ignore
_set_3d_view, _set_3d_title, _take_3d_screenshot) # noqa: F401,E501 analysis:ignore
from ._abstract import (_AbstractAppWindow, _AbstractHBoxLayout,
_AbstractVBoxLayout, _AbstractGridLayout,
Expand All @@ -55,6 +55,15 @@
from ...utils import _check_option, get_config
from ...fixes import _compare_version


def _close_all():
from ._pyvista import _close_all
try: # remove when pyvista 0.35.2 patch is released
_close_all()
except AttributeError:
pass


# Adapted from matplotlib
if (sys.platform == 'darwin' and
_compare_version(platform.mac_ver()[0], '>=', '10.16') and
Expand Down
5 changes: 1 addition & 4 deletions mne/viz/backends/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,7 @@ def close_3d_figure(figure):

def close_all_3d_figures():
"""Close all the scenes of the current 3d backend."""
try: # remove when pyvista 0.35.2 patch is released
backend._close_all()
except AttributeError:
pass
backend._close_all()


def get_brain_class():
Expand Down

0 comments on commit 4bba703

Please sign in to comment.