2121
2222import datetime
2323from importlib .metadata import version as get_version
24+ from inspect import getsource
2425import ntpath
2526import os
2627from pathlib import Path
2728import re
2829from subprocess import run
2930import sys
31+ from tempfile import gettempdir
3032from urllib .parse import quote
3133import warnings
3234
@@ -409,6 +411,26 @@ def _dotv(version):
409411# -- sphinx-gallery config ----------------------------------------------------
410412# See https://sphinx-gallery.github.io/stable/configuration.html
411413
414+
415+ def reset_modules (gallery_conf , fname ):
416+ """Force re-registering of nc-time-axis with matplotlib for each example.
417+
418+ Required for sphinx-gallery>=0.11.0.
419+ """
420+ from sys import modules
421+
422+ _ = modules .pop ("nc_time_axis" , None )
423+
424+
425+ # https://sphinx-gallery.github.io/dev/configuration.html#importing-callables
426+ reset_modules_dir = Path (gettempdir ()) / reset_modules .__name__
427+ reset_modules_dir .mkdir (exist_ok = True )
428+ (reset_modules_dir / f"{ reset_modules .__name__ } .py" ).write_text (
429+ getsource (reset_modules )
430+ )
431+ sys .path .insert (0 , str (reset_modules_dir ))
432+
433+
412434sphinx_gallery_conf = {
413435 # path to your example scripts
414436 "examples_dirs" : ["../gallery_code" ],
@@ -420,11 +442,7 @@ def _dotv(version):
420442 "ignore_pattern" : r"__init__\.py" ,
421443 # force gallery building, unless overridden (see src/Makefile)
422444 "plot_gallery" : "'True'" ,
423- # force re-registering of nc-time-axis with matplotlib for each example,
424- # required for sphinx-gallery>=0.11.0
425- "reset_modules" : (
426- lambda gallery_conf , fname : sys .modules .pop ("nc_time_axis" , None ),
427- ),
445+ "reset_modules" : f"{ reset_modules .__name__ } .{ reset_modules .__name__ } " ,
428446}
429447
430448# -----------------------------------------------------------------------------
0 commit comments