MCPcopy
hub / github.com/mne-tools/mne-python / reset_modules

Function reset_modules

doc/sphinxext/mne_doc_utils.py:134–239  ·  view source on GitHub ↗

Do the reset.

(gallery_conf, fname, when)

Source from the content-addressed store, hash-verified

132
133
134def reset_modules(gallery_conf, fname, when):
135 """Do the reset."""
136 import matplotlib.pyplot as plt
137
138 mne.viz.set_3d_backend("pyvistaqt")
139 pyvista.OFF_SCREEN = False
140 pyvista.BUILDING_GALLERY = True
141
142 from pyvista import Plotter # noqa
143
144 try:
145 from pyvistaqt import BackgroundPlotter # noqa
146 except ImportError:
147 BackgroundPlotter = None # noqa
148 try:
149 from vtkmodules.vtkCommonDataModel import vtkPolyData # noqa
150 except ImportError:
151 vtkPolyData = None # noqa
152 try:
153 from mne_qt_browser._pg_figure import MNEQtBrowser
154 except ImportError:
155 MNEQtBrowser = None
156 from mne.viz.backends.renderer import backend
157
158 _Renderer = backend._Renderer if backend is not None else None
159 reset_warnings(gallery_conf, fname)
160 # in case users have interactive mode turned on in matplotlibrc,
161 # turn it off here (otherwise the build can be very slow)
162 plt.ioff()
163 plt.rcParams["animation.embed_limit"] = 40.0
164 plt.rcParams["figure.raise_window"] = False
165 # https://github.com/sphinx-gallery/sphinx-gallery/pull/1243#issue-2043332860
166 plt.rcParams["animation.html"] = "html5"
167 # neo holds on to an exception, which in turn holds a stack frame,
168 # which will keep alive the global vars during SG execution
169 try:
170 import neo
171
172 neo.io.stimfitio.STFIO_ERR = None
173 except Exception:
174 pass
175 gc.collect()
176
177 # Agg does not call close_event so let's clean up on our own :(
178 # https://github.com/matplotlib/matplotlib/issues/18609
179 mne.viz.ui_events._cleanup_agg()
180 assert len(mne.viz.ui_events._event_channels) == 0, list(
181 mne.viz.ui_events._event_channels
182 )
183
184 orig_when = when
185 when = f"mne/conf.py:Resetter.__call__:{when}:{fname}"
186 # Support stuff like
187 # MNE_SKIP_INSTANCE_ASSERTIONS="Brain,Plotter,BackgroundPlotter,vtkPolyData,_Renderer" make html-memory # noqa: E501
188 # to just test MNEQtBrowser
189 skips = os.getenv("MNE_SKIP_INSTANCE_ASSERTIONS", "").lower()
190 prefix = ""
191 if skips not in ("true", "1", "all"):

Callers

nothing calls this directly

Calls 5

sizeof_fmtFunction · 0.90
_get_extra_data_pathFunction · 0.90
reset_warningsFunction · 0.85
splitMethod · 0.80
_assert_no_instancesFunction · 0.70

Tested by

no test coverage detected