Skip to content

Commit 043cc53

Browse files
authored
Merge pull request #521 from charlie4fun/fix_453
Fix #453: log files when scene is not specified
2 parents de75f5d + a144dd1 commit 043cc53

File tree

5 files changed

+50
-11
lines changed

5 files changed

+50
-11
lines changed

manim/config/config.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,19 @@ def _parse_config(config_parser, args):
169169
camera_config = config
170170

171171
if file_writer_config["log_to_file"]:
172-
# IMPORTANT note about file name : The log file name will be the scene_name get from the args (contained in file_writer_config). So it can differ from the real name of the scene.
172+
# Note about log_file_name : The log file name will be the <name_of_animation_file>_<name_of_scene>.log
173+
# get from the args (contained in file_writer_config). So it can differ from the real name of the scene.
174+
# <name_of_scene> would only appear if scene name was provided on manim call
175+
scene_name_suffix = "".join(file_writer_config["scene_names"])
176+
scene_file_name = os.path.basename(args.file).split(".")[0]
177+
log_file_name = (
178+
f"{scene_file_name}_{scene_name_suffix}.log"
179+
if scene_name_suffix
180+
else f"{scene_file_name}.log"
181+
)
173182
log_file_path = os.path.join(
174183
file_writer_config["log_dir"],
175-
"".join(file_writer_config["scene_names"]) + ".log",
184+
log_file_name,
176185
)
177186
set_file_logger(log_file_path)
178-
logger.info("Log file wil be saved in %(logpath)s", {"logpath": log_file_path})
187+
logger.info("Log file will be saved in %(logpath)s", {"logpath": log_file_path})

tests/control_data/logs_data/BasicSceneLoggingTest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{"levelname": "INFO", "module": "config", "message": "Log file wil be saved in <>"}
1+
{"levelname": "INFO", "module": "config", "message": "Log file will be saved in <>"}
22
{"levelname": "DEBUG", "module": "hashing", "message": "Hashing ..."}
33
{"levelname": "DEBUG", "module": "hashing", "message": "Hashing done in <> s."}
44
{"levelname": "INFO", "module": "scene_file_writer", "message": "Animation 0 : Partial movie file written in <>"}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from manim import *
2+
3+
# This module is used in the CLI tests in tests_CLi.py.
4+
5+
6+
class SquareToCircle(Scene):
7+
def construct(self):
8+
self.play(Transform(Square(), Circle()))

tests/test_logging/basic_scenes.py renamed to tests/test_logging/basic_scenes_wirte_stuff.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
# This module is used in the CLI tests in tests_CLi.py.
44

55

6-
class SquareToCircle(Scene):
7-
def construct(self):
8-
self.play(Transform(Square(), Circle()))
9-
10-
116
class WriteStuff(Scene):
127
def construct(self):
138
example_text = Tex("This is a some text", tex_to_color_map={"text": YELLOW})

tests/test_logging/test_logging.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99

1010

1111
@logs_comparison(
12-
"BasicSceneLoggingTest.txt", os.path.join("logs", "SquareToCircle.log")
12+
"BasicSceneLoggingTest.txt",
13+
os.path.join("logs", "basic_scenes_square_to_circle_SquareToCircle.log"),
1314
)
1415
def test_logging_to_file(tmp_path, python_version):
15-
path_basic_scene = os.path.join("tests", "test_logging", "basic_scenes.py")
16+
path_basic_scene = os.path.join(
17+
"tests", "test_logging", "basic_scenes_square_to_circle.py"
18+
)
1619
command = [
1720
python_version,
1821
"-m",
@@ -28,3 +31,27 @@ def test_logging_to_file(tmp_path, python_version):
2831
]
2932
_, err, exitcode = capture(command)
3033
assert exitcode == 0, err
34+
35+
36+
@logs_comparison(
37+
"BasicSceneLoggingTest.txt",
38+
os.path.join("logs", "basic_scenes_square_to_circle.log"),
39+
)
40+
def test_logging_when_scene_is_not_specified(tmp_path, python_version):
41+
path_basic_scene = os.path.join(
42+
"tests", "test_logging", "basic_scenes_square_to_circle.py"
43+
)
44+
command = [
45+
python_version,
46+
"-m",
47+
"manim",
48+
path_basic_scene,
49+
"-l",
50+
"--log_to_file",
51+
"-v",
52+
"DEBUG",
53+
"--media_dir",
54+
str(tmp_path),
55+
]
56+
_, err, exitcode = capture(command)
57+
assert exitcode == 0, err

0 commit comments

Comments
 (0)