Skip to content

Commit 9b61e3d

Browse files
committed
Fix #453: log files naming, when scene is not specified, is fixed
1 parent de16dad commit 9b61e3d

File tree

5 files changed

+49
-10
lines changed

5 files changed

+49
-10
lines changed

manim/config/config.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,18 @@ def _parse_config(config_parser, args):
157157
set_rich_logger(config_parser["logger"], file_writer_config["verbosity"])
158158
if file_writer_config["log_to_file"]:
159159
# 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.
160+
scene_name_suffix = "".join(file_writer_config["scene_names"])
161+
scene_file_name = os.path.basename(args.file).split(".")[
162+
0
163+
] # takes filename and removes extension
164+
log_file_name = (
165+
f"{scene_file_name}_{scene_name_suffix}.log"
166+
if scene_name_suffix
167+
else f"{scene_file_name}.log"
168+
)
160169
log_file_path = os.path.join(
161170
file_writer_config["log_dir"],
162-
"".join(file_writer_config["scene_names"]) + ".log",
171+
log_file_name,
163172
)
164173
set_file_logger(log_file_path)
165-
logger.info("Log file wil be saved in %(logpath)s", {"logpath": log_file_path})
174+
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)