diff --git a/src/sage_docbuild/conf.py b/src/sage_docbuild/conf.py index 7ab0e036cca..88cd836b52c 100644 --- a/src/sage_docbuild/conf.py +++ b/src/sage_docbuild/conf.py @@ -919,9 +919,17 @@ class will be properly documented inside its surrounding class. return skip def clean_jupyter_execute(app, exception): - jupyter_execute_path = os.path.join(app.outdir, 'jupyter_execute') - if os.path.exists(jupyter_execute_path): - shutil.rmtree(jupyter_execute_path) + """ + If there was no exception during the doc build, we remove the useless + ``jupyter_execute`` directory, which would only bloat the doc tree. + + If there was an exception, the ``jupyter_execute`` directory may be useful + for debugging and hence we don't remove it. + """ + if exception is None: # only proceed if there were no build errors + jupyter_execute_path = os.path.join(app.outdir, 'jupyter_execute') + if os.path.exists(jupyter_execute_path): + shutil.rmtree(jupyter_execute_path) class SagecodeTransform(SphinxTransform):