Skip to content

Commit

Permalink
actually cleanup usage of loggers, remove logger-imports; black
Browse files Browse the repository at this point in the history
  • Loading branch information
behackl committed Jul 13, 2024
1 parent 78dfd41 commit c800ba1
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 17 deletions.
4 changes: 3 additions & 1 deletion manim/cli/render/global_options.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from __future__ import annotations

import logging
import re

from cloup import Choice, option, option_group

from ... import logger

__all__ = ["global_options"]

logger = logging.getLogger("manim")


def validate_gui_location(ctx, param, value):
if value:
Expand Down
4 changes: 3 additions & 1 deletion manim/cli/render/render_options.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from __future__ import annotations

import logging
import re

from cloup import Choice, option, option_group

from manim.constants import QUALITIES, RendererType

from ... import logger

__all__ = ["render_options"]

logger = logging.getLogger("manim")


def validate_scene_range(ctx, param, value):
try:
Expand Down
5 changes: 3 additions & 2 deletions manim/renderer/shader_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import re
from pathlib import Path

import logging
import moderngl
import numpy as np

from .. import logger

# Mobjects that should be rendered with
# the same shader will be organized and
# clumped together based on keeping track
Expand All @@ -17,6 +16,8 @@

__all__ = ["ShaderWrapper"]

logger = logging.getLogger("manim")


def get_shader_dir():
return Path(__file__).parent / "shaders"
Expand Down
9 changes: 6 additions & 3 deletions manim/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@


import inspect
import logging
import re
from collections.abc import Iterable
from typing import Any, Callable

from decorator import decorate, decorator

from .. import logger
logger = logging.getLogger("manim")


def _get_callable_info(callable: Callable) -> tuple[str, str]:
Expand Down Expand Up @@ -218,6 +219,7 @@ def deprecate(func: Callable, *args, **kwargs):
The return value of the given callable when being passed the given
arguments.
"""
print("about to emit warning")
logger.warning(warning_msg())
return func(*args, **kwargs)

Expand All @@ -236,8 +238,9 @@ def deprecated_params(
since: str | None = None,
until: str | None = None,
message: str | None = "",
redirections: None
| (Iterable[tuple[str, str] | Callable[..., dict[str, Any]]]) = None,
redirections: None | (
Iterable[tuple[str, str] | Callable[..., dict[str, Any]]]
) = None,
) -> Callable:
"""Decorator to mark parameters of a callable as deprecated.
Expand Down
4 changes: 3 additions & 1 deletion manim/utils/testing/_frames_testers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
import warnings
from pathlib import Path

import logging
import numpy as np

from manim import logger

from ._show_diff import show_diff_helper

FRAME_ABSOLUTE_TOLERANCE = 1.01
FRAME_MISMATCH_RATIO_TOLERANCE = 1e-5

logger = logging.getLogger("manim")


class _FramesTester:
def __init__(self, file_path: Path, show_diff=False) -> None:
Expand Down
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
import sys
from pathlib import Path

Expand Down Expand Up @@ -45,6 +46,15 @@ def pytest_collection_modifyitems(config, items):
item.add_marker(slow_skip)


@pytest.fixture
def manim_caplog(caplog):
logger = logging.getLogger("manim")
logger.propagate = True
caplog.set_level(logging.INFO, logger="manim")
yield caplog
logger.propagate = False


@pytest.fixture
def config():
saved = manim.config.copy()
Expand Down
4 changes: 3 additions & 1 deletion tests/helpers/graphical_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

from __future__ import annotations

import logging
import tempfile
from pathlib import Path

import numpy as np

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


logger = logging.getLogger("manim")

def set_test_scene(scene_object: type[Scene], module_name: str, config):
"""Function used to set up the test data for a new feature. This will basically set up a pre-rendered frame for a scene. This is meant to be used only
when setting up tests. Please refer to the wiki.
Expand Down
8 changes: 4 additions & 4 deletions tests/module/animation/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ def test_animation_forbidden_run_time(run_time):
test_scene.play(FadeIn(None, run_time=run_time))


def test_animation_run_time_shorter_than_frame_rate(caplog, config):
def test_animation_run_time_shorter_than_frame_rate(manim_caplog, config):
test_scene = Scene()
test_scene.play(FadeIn(None, run_time=1 / (config.frame_rate + 1)))
assert (
"Original run time of FadeIn(Mobject) is shorter than current frame rate"
in caplog.text
in manim_caplog.text
)


@pytest.mark.parametrize("frozen_frame", [False, True])
def test_wait_run_time_shorter_than_frame_rate(caplog, frozen_frame):
def test_wait_run_time_shorter_than_frame_rate(manim_caplog, frozen_frame):
test_scene = Scene()
test_scene.wait(1e-9, frozen_frame=frozen_frame)
assert (
"Original run time of Wait(Mobject) is shorter than current frame rate"
in caplog.text
in manim_caplog.text
)
5 changes: 2 additions & 3 deletions tests/module/mobject/geometry/test_unit_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ def test_get_arc_center():
)


def test_BackgroundRectangle(caplog):
caplog.set_level(logging.INFO)
def test_BackgroundRectangle(manim_caplog):
c = Circle()
bg = BackgroundRectangle(c)
bg.set_style(fill_opacity=0.42)
assert bg.get_fill_opacity() == 0.42
bg.set_style(fill_opacity=1, hello="world")
assert (
"Argument {'hello': 'world'} is ignored in BackgroundRectangle.set_style."
in caplog.text
in manim_caplog.text
)
5 changes: 4 additions & 1 deletion tests/module/utils/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ def _get_caplog_record_msg(warn_caplog_manim):

@pytest.fixture()
def warn_caplog_manim(caplog):
caplog.set_level(logging.WARNING, logger="manim")
logger = logging.getLogger("manim")
logger.propagate = True
caplog.set_level(logging.INFO, logger="manim")
yield caplog
logger.propagate = False


@deprecated
Expand Down

0 comments on commit c800ba1

Please sign in to comment.