Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from . import constants


def main():
def main():
args = config.parse_cli()
cfg = config.get_configuration(args)
config.initialize_directories(cfg)
Expand Down
6 changes: 3 additions & 3 deletions manim/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import numpy as np

from ..constants import *
from ..logger import logger
from ..mobject.types.image_mobject import AbstractImageMobject
from ..mobject.mobject import Mobject
from ..mobject.types.point_cloud_mobject import PMobject
Expand All @@ -24,7 +25,6 @@
from ..utils.space_ops import angle_of_vector
from ..utils.space_ops import get_norm


class Camera(object):
"""
Base Camera class.
Expand Down Expand Up @@ -348,14 +348,14 @@ def make_background_from_func(self, coords_to_colors_func):
The pixel array which can then be passed to set_background.
"""

print("Starting set_background; for reference, the current time is ", time.strftime("%H:%M:%S"))
logger.info("Starting set_background; for reference, the current time is ", time.strftime("%H:%M:%S"))
coords = self.get_coords_of_all_pixels()
new_background = np.apply_along_axis(
coords_to_colors_func,
2,
coords
)
print("Ending set_background; for reference, the current time is ", time.strftime("%H:%M:%S"))
logger.info("Ending set_background; for reference, the current time is ", time.strftime("%H:%M:%S"))

return self.convert_pixel_array(new_background, convert_from_floats=True)

Expand Down
7 changes: 4 additions & 3 deletions manim/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from . import constants
from . import dirs
from .logger import logger

def parse_cli():
try:
Expand Down Expand Up @@ -138,7 +139,7 @@ def parse_cli():
)
return parser.parse_args()
except argparse.ArgumentError as err:
print(str(err))
logger.error(str(err))
sys.exit(2)


Expand Down Expand Up @@ -225,8 +226,8 @@ def get_camera_configuration(args):
try:
camera_config["background_color"] = colour.Color(args.color)
except AttributeError as err:
print("Please use a valid color")
print(err)
logger.warning("Please use a valid color")
logger.error(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two should be logged at the same level; it looks like it should be error here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you could be fancy and use logger.exception(). Likewise inside the other exception blocks.

sys.exit(2)

# If rendering a transparent image/move, make sure the
Expand Down
8 changes: 4 additions & 4 deletions manim/constants.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import numpy as np
import os
from .logger import logger

NOT_SETTING_FONT_MSG='''
Warning:
You haven't set a font.
If you are not using English, this may cause text rendering problems.
You set fonts like:
You haven't set font.
If you are not using English, this may cause text rendering problem.
You set font like:
text = Text('your text', font='your font')
or:
class MyText(Text):
Expand Down
12 changes: 6 additions & 6 deletions manim/extract_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .utils.sounds import play_error_sound
from .utils.sounds import play_finish_sound
from . import constants
from .logger import logger


def open_file_if_needed(file_writer, **config):
Expand Down Expand Up @@ -83,7 +84,7 @@ def prompt_user_for_choice(scene_classes):
for num_str in user_input.split(",")
]
except KeyError:
print(constants.INVALID_NUMBER_MESSAGE)
logger.error(constants.INVALID_NUMBER_MESSAGE)
sys.exit(2)
user_input = input(constants.CHOOSE_NUMBER_MESSAGE)
return [
Expand All @@ -96,7 +97,7 @@ def prompt_user_for_choice(scene_classes):

def get_scenes_to_render(scene_classes, config):
if len(scene_classes) == 0:
print(constants.NO_SCENE_MESSAGE)
logger.error(constants.NO_SCENE_MESSAGE)
return []
if config["write_all"]:
return scene_classes
Expand All @@ -109,11 +110,10 @@ def get_scenes_to_render(scene_classes, config):
found = True
break
if not found and (scene_name != ""):
print(
logger.error(
constants.SCENE_NOT_FOUND_MESSAGE.format(
scene_name
),
file=sys.stderr
)
)
if result:
return result
Expand Down Expand Up @@ -141,7 +141,7 @@ def get_module(file_name):
exec(code, module.__dict__)
return module
except Exception as e:
print(f"Failed to render scene: {str(e)}")
logger.error(f"Failed to render scene: {str(e)}")
sys.exit(2)
else:
module_name = file_name.replace(os.sep, ".").replace(".py", "")
Expand Down
12 changes: 12 additions & 0 deletions manim/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import logging
from rich.logging import RichHandler


logging.basicConfig(
level="NOTSET",
format="%(message)s",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think the filename could come in handy in logs. Maybe something that could be flag-configurable later.

datefmt="[%X]",
handlers=[RichHandler()]
)

logger = logging.getLogger("rich")
3 changes: 2 additions & 1 deletion manim/mobject/svg/text_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ...constants import *
from ... import dirs
from ...container.container import Container
from ...logger import logger
from ...mobject.geometry import Dot, Rectangle
from ...mobject.svg.svg_mobject import SVGMobject
from ...mobject.types.vectorized_mobject import VGroup
Expand Down Expand Up @@ -289,7 +290,7 @@ def text2svg(self):

if self.font == '':
if NOT_SETTING_FONT_MSG != '':
print(NOT_SETTING_FONT_MSG)
logger.warning(NOT_SETTING_FONT_MSG)

dir_name = dirs.TEXT_DIR
hash_name = self.text2hash()
Expand Down
4 changes: 2 additions & 2 deletions manim/mobject/vector_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import random

from ..constants import *

from ..logger import logger
from ..animation.composition import AnimationGroup
from ..animation.indication import ShowPassingFlash
from ..mobject.geometry import Vector
Expand Down Expand Up @@ -85,7 +85,7 @@ def get_color_field_image_file(scalar_func,
file_name = "%d.png" % func_hash
full_path = os.path.join(RASTER_IMAGE_DIR, file_name)
if not os.path.exists(full_path):
print("Rendering color field image " + str(func_hash))
logger.info("Rendering color field image " + str(func_hash))
rgb_gradient_func = get_rgb_gradient_function(
min_value=min_value,
max_value=max_value,
Expand Down
3 changes: 2 additions & 1 deletion manim/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ..camera.camera import Camera
from ..constants import *
from ..container.container import Container
from ..logger import logger
from ..mobject.mobject import Mobject
from ..scene.scene_file_writer import SceneFileWriter
from ..utils.iterables import list_update
Expand Down Expand Up @@ -110,7 +111,7 @@ def print_end_message(self):
Used internally to print the number of
animations played after the scene ends.
"""
print("Played {} animations".format(self.num_plays))
logger.info("Played {} animations".format(self.num_plays))

def set_variables_as_attrs(self, *objects, **newly_named_objects):
"""
Expand Down
5 changes: 3 additions & 2 deletions manim/scene/scene_file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ..constants import STREAMING_PORT
from ..constants import STREAMING_PROTOCOL
from .. import dirs
from ..logger import logger
from ..utils.config_ops import digest_config
from ..utils.file_ops import guarantee_existence
from ..utils.file_ops import add_extension_if_not_present
Expand Down Expand Up @@ -467,7 +468,7 @@ def combine_movie_files(self):
**kwargs
)
if len(partial_movie_files) == 0:
print("No animations in this scene")
logger.error("No animations in this scene")
return

# Write a file partial_file_list.txt containing all
Expand Down Expand Up @@ -536,4 +537,4 @@ def print_file_ready_message(self, file_path):
"""
Prints the "File Ready" message to STDOUT.
"""
print("\nFile ready at {}\n".format(file_path))
logger.info("\nFile ready at {}\n".format(file_path))
3 changes: 2 additions & 1 deletion manim/scene/scene_from_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import cv2

from ..scene.scene import Scene
from ..logger import logger


# TODO, is this depricated?
Expand All @@ -24,7 +25,7 @@ def construct(self, file_name,
start_frame, end_frame = [fps * t for t in time_range]

frame_count = end_frame - start_frame
print("Reading in " + file_name + "...")
logger.info("Reading in " + file_name + "...")
for count in show_progress(list(range(start_frame, end_frame + 1))):
returned, frame = cap.read()
if not returned:
Expand Down
3 changes: 2 additions & 1 deletion manim/utils/tex_file_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ..constants import TEX_TEXT_TO_REPLACE
from ..constants import TEX_USE_CTEX
from .. import dirs
from ..logger import logger

def tex_hash(expression, template_tex_file_body):
id_str = str(expression + template_tex_file_body)
Expand All @@ -27,7 +28,7 @@ def generate_tex_file(expression, template_tex_file_body):
tex_hash(expression, template_tex_file_body)
) + ".tex"
if not os.path.exists(result):
print("Writing \"%s\" to %s" % (
logger.info("Writing \"%s\" to %s" % (
"".join(expression), result
))
new_body = template_tex_file_body.replace(
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ opencv-python
pycairo
pydub
pygments
pyreadline; sys_platform == 'win32'
pyreadline; sys_platform == 'win32',
rich
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
"pydub",
"pygments",
"pyreadline; sys_platform == 'win32'",
"rich"
],
)