Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Build the docs - Logging (#1461)

Anton Ballmaierdf7a2f5dfcd5
diff --git a/.gitignore b/.gitignore
index e1490a2b5..7f73a6874 100644
--- a/.gitignore
+++ b/.gitignore
@@ -59,6 +59,7 @@ docs/build/
docs/source/_autosummary/
docs/source/reference/
docs/source/_build/
+docs/rendering_times.csv
# PyBuilder
target/
diff --git a/docs/Makefile b/docs/Makefile
index 846802dda..f503fce4e 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -19,8 +19,9 @@ help:
# Like make clean but also remove files generated by autosummary and
# rendered videos.
cleanall: clean
- rm source/reference/*
- rm -rf source/media
+ @rm source/reference/*
+ @rm -rf source/media
+ @rm -f rendering_times.csv
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
diff --git a/docs/source/manim_directive.py b/docs/source/manim_directive.py
index af6829626..90242dcb3 100644
--- a/docs/source/manim_directive.py
+++ b/docs/source/manim_directive.py
@@ -72,9 +72,15 @@ directive:
that is rendered in a reference block after the source code.
"""
+import csv
+import itertools as it
+import os
+import re
import shutil
+import sys
from pathlib import Path
-from typing import List
+from timeit import timeit
+from typing import Callable, List
import jinja2
from docutils import nodes
@@ -205,6 +211,8 @@ class ManimDirective(Directive):
config.video_dir = "{media_dir}/videos/{quality}"
output_file = f"{clsname}-{classnamedict[clsname]}"
config.assets_dir = Path("_static")
+ config.progress_bar = "none"
+ config.verbosity = "WARNING"
config_code = [
f'config["frame_rate"] = {frame_rate}',
@@ -231,7 +239,13 @@ class ManimDirective(Directive):
*user_code,
f"{clsname}().render()",
]
- exec("\n".join(code), globals())
+ run_time = timeit(lambda: exec("\n".join(code), globals()), number=1)
+
+ _write_rendering_stats(
+ clsname,
+ run_time,
+ self.state.document.settings.env.docname,
+ )
# copy video file to output directory
if not (save_as_gif or save_last_frame):
@@ -265,6 +279,51 @@ class ManimDirective(Directive):
return []
+rendering_times_file_path = Path("../rendering_times.csv")
+
+
+def _write_rendering_stats(scene_name, run_time, file_name):
+ with open(rendering_times_file_path, "a") as file:
+ csv.writer(file).writerow(
+ [
+ re.sub("^(reference\/)|(manim\.)", "", file_name),
+ scene_name,
+ "%.3f" % run_time,
+ ]
+ )
+
+
+def _log_rendering_times(*args):
+ if rendering_times_file_path.exists():
+ with open(rendering_times_file_path) as file:
+ data = list(csv.reader(file))
+ if len(data) == 0:
+ sys.exit()
+
+ print("\nRendering Summary\n-----------------\n")
+
+ max_file_length = max([len(row[0]) for row in data])
+ for key, group in it.groupby(data, key=lambda row: row[0]):
+ key = key.ljust(max_file_length + 1, ".")
+ group = list(group)
+ if len(group) == 1:
+ row = group[0]
+ print(f"{key}{row[2].rjust(7, '.')}s {row[1]}")
+ continue
+ time_sum = sum([float(row[2]) for row in group])
+ print(
+ f"{key}{f'{time_sum:.3f}'.rjust(7, '.')}s => {len(group)} EXAMPLES"
+ )
+ for row in group:
+ print(f"{' '*(max_file_length)} {row[2].rjust(7)}s {row[1]}")
+ print("")
+
+
+def _delete_rendering_times(*args):
+ if rendering_times_file_path.exists():
+ os.remove(rendering_times_file_path)
+
+
def setup(app):
import manim
@@ -276,6 +335,9 @@ def setup(app):
app.add_directive("manim", ManimDirective)
+ app.connect("builder-inited", _delete_rendering_times)
+ app.connect("build-finished", _log_rendering_times)
+
metadata = {"parallel_read_safe": False, "parallel_write_safe": True}
return metadata
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py
index e79a4f182..c2f7f76e5 100644
--- a/manim/mobject/mobject.py
+++ b/manim/mobject/mobject.py
@@ -2335,9 +2335,9 @@ class Mobject(Container):
Examples
--------
- .. manim:: SuffleSumobjectsExample
+ .. manim:: ShuffleSubmobjectsExample
- class SuffleSumobjectsExample(Scene):
+ class ShuffleSubmobjectsExample(Scene):
def construct(self):
s= VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])
s2= s.copy()