From 467c0a2a6b30343ff0580a354bb7cd7e16fa101e Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 4 Oct 2022 12:01:49 +0200 Subject: [PATCH] imgmath: Cleanup math dir in embed mode --- sphinx/ext/imgmath.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sphinx/ext/imgmath.py b/sphinx/ext/imgmath.py index e48146bebae..f744830b7b6 100644 --- a/sphinx/ext/imgmath.py +++ b/sphinx/ext/imgmath.py @@ -294,6 +294,19 @@ def cleanup_tempdir(app: Sphinx, exc: Exception) -> None: pass +def cleanup_mathdir(app: Sphinx, exc: Exception) -> None: + if exc: + return + # in embed mode, the images are generated in the math output dir to be + # shared across workers, but are not useful to the document + if app.builder.config.imgmath_embed: + mathdir = path.join(app.builder.outdir, app.builder.imagedir, 'math') + try: + shutil.rmtree(mathdir) # type: ignore + except Exception: + pass + + def get_tooltip(self: HTMLTranslator, node: Element) -> str: if self.builder.config.imgmath_add_tooltips: return ' alt="%s"' % self.encode(node.astext()).strip() @@ -385,4 +398,5 @@ def setup(app: Sphinx) -> Dict[str, Any]: app.add_config_value('imgmath_font_size', 12, 'html') app.add_config_value('imgmath_embed', False, 'html', [bool]) app.connect('build-finished', cleanup_tempdir) + app.connect('build-finished', cleanup_mathdir) return {'version': sphinx.__display_version__, 'parallel_read_safe': True}