From e23e44bfe935ce4912bc50e55a3886f4ab9fcd3c Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 15 Sep 2023 21:56:31 +0100 Subject: [PATCH] Simplify tempfile setup --- hooks/pygments-styles.py | 9 +++++---- hooks/tags.py | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/hooks/pygments-styles.py b/hooks/pygments-styles.py index d067bd1..9252bdc 100644 --- a/hooks/pygments-styles.py +++ b/hooks/pygments-styles.py @@ -1,15 +1,16 @@ import tempfile -import shutil import os from pygments.formatters.html import HtmlFormatter from mkdocs.structure.files import File from minify_html import minify -from mkdocs.utils import write_file +from mkdocs.utils import write_file, clean_directory PYGMENTS_STYLE_DIR = tempfile.mkdtemp() -shutil.rmtree(PYGMENTS_STYLE_DIR, ignore_errors=True) -os.mkdir(PYGMENTS_STYLE_DIR) +def on_post_build(config): + clean_directory(PYGMENTS_STYLE_DIR) + +on_build_error = on_pre_build = on_post_build def minify_css(styles: str) -> str: wrapped_styles = f"