Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Enhancement: Add manim version to CLI output, append version name for generated gif+png, add version to metadata of rendered videos (#984)

KingWampy554f82984865
diff --git a/docs/source/tutorials/configuration.rst b/docs/source/tutorials/configuration.rst
index 40e295e9b..248cb3338 100644
--- a/docs/source/tutorials/configuration.rst
+++ b/docs/source/tutorials/configuration.rst
@@ -374,8 +374,9 @@ A list of all CLI flags
print(result.stdout.decode('utf-8'))
.. testoutput::
- :options: -ELLIPSIS, +NORMALIZE_WHITESPACE
-
+ :options: +ELLIPSIS, +NORMALIZE_WHITESPACE
+
+ Manim Community v...
usage: manim file [flags] [scene [scene ...]]
manim {cfg,init,plugins} [opts]
diff --git a/example_scenes/manim.cfg b/example_scenes/manim.cfg
index a11d17e5b..02ca266bb 100644
--- a/example_scenes/manim.cfg
+++ b/example_scenes/manim.cfg
@@ -4,12 +4,12 @@
logging_keyword = magenta
logging_level_notset = dim
logging_level_debug = yellow
-logging_level_info = dim purple
+logging_level_info = dim green
logging_level_warning = dim red
logging_level_error = red
logging_level_critical = red
log_level =
log_time = dim yellow
log_message = green
-log_path = dim blue
+log_path = dim
diff --git a/manim/__main__.py b/manim/__main__.py
index 7d603de10..5863b592e 100644
--- a/manim/__main__.py
+++ b/manim/__main__.py
@@ -2,7 +2,7 @@ import os
import sys
import traceback
-from manim import logger, config
+from manim import logger, console, config, __version__
from manim.utils.module_ops import (
get_module,
get_scene_classes_from_module,
@@ -42,6 +42,7 @@ def open_file_if_needed(file_writer):
def main():
+ console.print(f"Manim Community [green]v{__version__}[/green]")
args = parse_args(sys.argv)
if hasattr(args, "cmd"):
diff --git a/manim/_config/default.cfg b/manim/_config/default.cfg
index 36aa8dc47..9d89e008a 100644
--- a/manim/_config/default.cfg
+++ b/manim/_config/default.cfg
@@ -136,7 +136,7 @@ partial_movie_dir = {media_dir}/partial_movie_files/{scene_name}
logging_keyword = bold yellow
logging_level_notset = dim
logging_level_debug = green
-logging_level_info = blue
+logging_level_info = green
logging_level_warning = red
logging_level_error = red bold
logging_level_critical = red bold reverse
@@ -147,6 +147,7 @@ log_path = dim
log_width = -1
log_height = -1
log_timestamps = True
+repr_number = green
[ffmpeg]
# Uncomment the following line to manually set the loglevel for ffmpeg. See
diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.py
index 114a770f4..db80530c8 100644
--- a/manim/scene/scene_file_writer.py
+++ b/manim/scene/scene_file_writer.py
@@ -13,10 +13,11 @@ import datetime
from PIL import Image
from pathlib import Path
+from manim import __version__
from .. import config, logger
from ..constants import FFMPEG_BIN, GIF_FILE_EXTENSION
from ..utils.file_ops import guarantee_existence
-from ..utils.file_ops import add_extension_if_not_present
+from ..utils.file_ops import add_extension_if_not_present, add_version_before_extension
from ..utils.file_ops import modify_atime
from ..utils.sounds import get_full_sound_file_path
@@ -291,6 +292,9 @@ class SceneFileWriter(object):
The pixel array of the image to save.
"""
file_path = self.image_file_path
+ if not config["output_file"]:
+ file_path = add_version_before_extension(file_path)
+
image.save(file_path)
self.print_file_ready_message(file_path)
@@ -359,6 +363,8 @@ class SceneFileWriter(object):
"-an", # Tells FFMPEG not to expect any audio
"-loglevel",
config["ffmpeg_loglevel"].lower(),
+ "-metadata",
+ f"comment=Rendered with Manim Community v{__version__}",
]
if config["transparent"]:
command += ["-vcodec", "qtrle"]
@@ -445,6 +451,8 @@ class SceneFileWriter(object):
file_list,
"-loglevel",
config["ffmpeg_loglevel"].lower(),
+ "-metadata",
+ f"comment=Rendered with Manim Community v{__version__}",
"-nostdin",
]
@@ -452,6 +460,10 @@ class SceneFileWriter(object):
commands += ["-c", "copy", movie_file_path]
if config["save_as_gif"]:
+ if not config["output_file"]:
+ self.gif_file_path = str(
+ add_version_before_extension(self.gif_file_path)
+ )
commands += [self.gif_file_path]
if not self.includes_sound:
@@ -492,6 +504,8 @@ class SceneFileWriter(object):
"1:a:0",
"-loglevel",
config["ffmpeg_loglevel"].lower(),
+ "-metadata",
+ f"comment=Rendered with Manim Community v{__version__}",
# "-shortest",
temp_file_path,
]
diff --git a/manim/utils/file_ops.py b/manim/utils/file_ops.py
index 6b450cb42..2c9b76afa 100644
--- a/manim/utils/file_ops.py
+++ b/manim/utils/file_ops.py
@@ -15,6 +15,8 @@ import time
import subprocess as sp
from pathlib import Path
+from manim import __version__
+
def add_extension_if_not_present(file_name, extension):
if file_name.suffix != extension:
@@ -23,6 +25,12 @@ def add_extension_if_not_present(file_name, extension):
return file_name
+def add_version_before_extension(file_name):
+ file_name = Path(file_name)
+ path, name, suffix = file_name.parent, file_name.stem, file_name.suffix
+ return Path(path, f"{name}_ManimCE_v{__version__}{suffix}")
+
+
def guarantee_existence(path):
if not os.path.exists(path):
os.makedirs(path)
diff --git a/tests/test_scene_rendering/test_cli_flags.py b/tests/test_scene_rendering/test_cli_flags.py
index 068c66df3..ef786383e 100644
--- a/tests/test_scene_rendering/test_cli_flags.py
+++ b/tests/test_scene_rendering/test_cli_flags.py
@@ -4,6 +4,7 @@ from PIL import Image
from pathlib import Path
from ..utils.video_tester import *
+from manim.utils.file_ops import add_version_before_extension
@pytest.mark.slow
@@ -137,7 +138,9 @@ def test_r_flag(tmp_path, manim_cfg_file, simple_scenes_path):
is_not_empty = any((tmp_path / "images").iterdir())
assert is_not_empty, "running manim with -s, -r flag did not render a file"
- filename = tmp_path / "images" / "simple_scenes" / "SquareToCircle.png"
+ filename = add_version_before_extension(
+ tmp_path / "images" / "simple_scenes" / "SquareToCircle.png"
+ )
assert np.asarray(Image.open(filename)).shape == (100, 200, 4)
@@ -162,7 +165,7 @@ def test_custom_folders(tmp_path, manim_cfg_file, simple_scenes_path):
exists = (tmp_path / "videos").exists()
assert not exists, "--custom_folders produced a 'videos/' dir"
- exists = (tmp_path / "SquareToCircle.png").exists()
+ exists = add_version_before_extension(tmp_path / "SquareToCircle.png").exists()
assert exists, "--custom_folders did not produce the output file"
@@ -181,5 +184,7 @@ def test_dash_as_filename(tmp_path):
]
out, err, exit_code = capture(command, command_input=code)
assert exit_code == 0, err
- exists = (tmp_path / "images" / "-" / "Test.png").exists()
+ exists = add_version_before_extension(
+ (tmp_path / "images" / "-" / "Test.png")
+ ).exists()
assert exists, out