Skip to content

Commit 554f829

Browse files
authored
Enhancement: Add manim version to CLI output, append version name for generated gif+png, add version to metadata of rendered videos (#984)
* Initial commit * black formatting * Changes * Test to see if it works * Changes * Update manim_directive.py * Update manim_directive.py * Update manim_directive.py * Update manim_directive.py * Update scene_file_writer.py * Always forget black.. * Change path separator * Changes * Add blank line in option block * Update scene_file_writer.py * Update metadata messages * No longer add version to video names * Fix test_dash_as_filename * Update __init__.py
1 parent ff1696c commit 554f829

File tree

7 files changed

+40
-10
lines changed

7 files changed

+40
-10
lines changed

docs/source/tutorials/configuration.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@ A list of all CLI flags
374374
print(result.stdout.decode('utf-8'))
375375

376376
.. testoutput::
377-
:options: -ELLIPSIS, +NORMALIZE_WHITESPACE
378-
377+
:options: +ELLIPSIS, +NORMALIZE_WHITESPACE
378+
379+
Manim Community v...
379380
usage: manim file [flags] [scene [scene ...]]
380381
manim {cfg,init,plugins} [opts]
381382

example_scenes/manim.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
logging_keyword = magenta
55
logging_level_notset = dim
66
logging_level_debug = yellow
7-
logging_level_info = dim purple
7+
logging_level_info = dim green
88
logging_level_warning = dim red
99
logging_level_error = red
1010
logging_level_critical = red
1111
log_level =
1212
log_time = dim yellow
1313
log_message = green
14-
log_path = dim blue
14+
log_path = dim
1515

manim/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
import traceback
44

5-
from manim import logger, config
5+
from manim import logger, console, config, __version__
66
from manim.utils.module_ops import (
77
get_module,
88
get_scene_classes_from_module,
@@ -42,6 +42,7 @@ def open_file_if_needed(file_writer):
4242

4343

4444
def main():
45+
console.print(f"Manim Community [green]v{__version__}[/green]")
4546
args = parse_args(sys.argv)
4647

4748
if hasattr(args, "cmd"):

manim/_config/default.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ partial_movie_dir = {media_dir}/partial_movie_files/{scene_name}
136136
logging_keyword = bold yellow
137137
logging_level_notset = dim
138138
logging_level_debug = green
139-
logging_level_info = blue
139+
logging_level_info = green
140140
logging_level_warning = red
141141
logging_level_error = red bold
142142
logging_level_critical = red bold reverse
@@ -147,6 +147,7 @@ log_path = dim
147147
log_width = -1
148148
log_height = -1
149149
log_timestamps = True
150+
repr_number = green
150151

151152
[ffmpeg]
152153
# Uncomment the following line to manually set the loglevel for ffmpeg. See

manim/scene/scene_file_writer.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
from PIL import Image
1414
from pathlib import Path
1515

16+
from manim import __version__
1617
from .. import config, logger
1718
from ..constants import FFMPEG_BIN, GIF_FILE_EXTENSION
1819
from ..utils.file_ops import guarantee_existence
19-
from ..utils.file_ops import add_extension_if_not_present
20+
from ..utils.file_ops import add_extension_if_not_present, add_version_before_extension
2021
from ..utils.file_ops import modify_atime
2122
from ..utils.sounds import get_full_sound_file_path
2223

@@ -291,6 +292,9 @@ def save_final_image(self, image):
291292
The pixel array of the image to save.
292293
"""
293294
file_path = self.image_file_path
295+
if not config["output_file"]:
296+
file_path = add_version_before_extension(file_path)
297+
294298
image.save(file_path)
295299
self.print_file_ready_message(file_path)
296300

@@ -359,6 +363,8 @@ def open_movie_pipe(self):
359363
"-an", # Tells FFMPEG not to expect any audio
360364
"-loglevel",
361365
config["ffmpeg_loglevel"].lower(),
366+
"-metadata",
367+
f"comment=Rendered with Manim Community v{__version__}",
362368
]
363369
if config["transparent"]:
364370
command += ["-vcodec", "qtrle"]
@@ -445,13 +451,19 @@ def combine_movie_files(self):
445451
file_list,
446452
"-loglevel",
447453
config["ffmpeg_loglevel"].lower(),
454+
"-metadata",
455+
f"comment=Rendered with Manim Community v{__version__}",
448456
"-nostdin",
449457
]
450458

451459
if config["write_to_movie"] and not config["save_as_gif"]:
452460
commands += ["-c", "copy", movie_file_path]
453461

454462
if config["save_as_gif"]:
463+
if not config["output_file"]:
464+
self.gif_file_path = str(
465+
add_version_before_extension(self.gif_file_path)
466+
)
455467
commands += [self.gif_file_path]
456468

457469
if not self.includes_sound:
@@ -492,6 +504,8 @@ def combine_movie_files(self):
492504
"1:a:0",
493505
"-loglevel",
494506
config["ffmpeg_loglevel"].lower(),
507+
"-metadata",
508+
f"comment=Rendered with Manim Community v{__version__}",
495509
# "-shortest",
496510
temp_file_path,
497511
]

manim/utils/file_ops.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import subprocess as sp
1616
from pathlib import Path
1717

18+
from manim import __version__
19+
1820

1921
def add_extension_if_not_present(file_name, extension):
2022
if file_name.suffix != extension:
@@ -23,6 +25,12 @@ def add_extension_if_not_present(file_name, extension):
2325
return file_name
2426

2527

28+
def add_version_before_extension(file_name):
29+
file_name = Path(file_name)
30+
path, name, suffix = file_name.parent, file_name.stem, file_name.suffix
31+
return Path(path, f"{name}_ManimCE_v{__version__}{suffix}")
32+
33+
2634
def guarantee_existence(path):
2735
if not os.path.exists(path):
2836
os.makedirs(path)

tests/test_scene_rendering/test_cli_flags.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55

66
from ..utils.video_tester import *
7+
from manim.utils.file_ops import add_version_before_extension
78

89

910
@pytest.mark.slow
@@ -137,7 +138,9 @@ def test_r_flag(tmp_path, manim_cfg_file, simple_scenes_path):
137138
is_not_empty = any((tmp_path / "images").iterdir())
138139
assert is_not_empty, "running manim with -s, -r flag did not render a file"
139140

140-
filename = tmp_path / "images" / "simple_scenes" / "SquareToCircle.png"
141+
filename = add_version_before_extension(
142+
tmp_path / "images" / "simple_scenes" / "SquareToCircle.png"
143+
)
141144
assert np.asarray(Image.open(filename)).shape == (100, 200, 4)
142145

143146

@@ -162,7 +165,7 @@ def test_custom_folders(tmp_path, manim_cfg_file, simple_scenes_path):
162165
exists = (tmp_path / "videos").exists()
163166
assert not exists, "--custom_folders produced a 'videos/' dir"
164167

165-
exists = (tmp_path / "SquareToCircle.png").exists()
168+
exists = add_version_before_extension(tmp_path / "SquareToCircle.png").exists()
166169
assert exists, "--custom_folders did not produce the output file"
167170

168171

@@ -181,5 +184,7 @@ def test_dash_as_filename(tmp_path):
181184
]
182185
out, err, exit_code = capture(command, command_input=code)
183186
assert exit_code == 0, err
184-
exists = (tmp_path / "images" / "-" / "Test.png").exists()
187+
exists = add_version_before_extension(
188+
(tmp_path / "images" / "-" / "Test.png")
189+
).exists()
185190
assert exists, out

0 commit comments

Comments
 (0)