Skip to content

Commit

Permalink
LoggerMixin renamed to StatusMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
pozitronik committed Oct 14, 2024
1 parent e93358e commit 840cd77
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions sinner/BatchProcessingCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
from sinner.handlers.frame.ImageHandler import ImageHandler
from sinner.handlers.frame.VideoHandler import VideoHandler
from sinner.models.NumberedFrame import NumberedFrame
from sinner.models.logger.LoggerMixin import LoggerMixin
from sinner.models.logger.Mood import Mood
from sinner.models.status.StatusMixin import StatusMixin
from sinner.models.status.Mood import Mood
from sinner.processors.frame.BaseFrameProcessor import BaseFrameProcessor
from sinner.typing import Frame
from sinner.utilities import list_class_descendants, resolve_relative_path, is_image, is_video, get_mem_usage, suggest_max_memory, path_exists, is_dir, normalize_path, suggest_execution_threads, suggest_temp_dir
from sinner.validators.AttributeLoader import Rules, AttributeLoader


class BatchProcessingCore(AttributeLoader, LoggerMixin):
class BatchProcessingCore(AttributeLoader, StatusMixin):
target_path: str
output_path: str
frame_processor: List[str]
Expand Down
4 changes: 2 additions & 2 deletions sinner/Benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import torch

from sinner.BatchProcessingCore import BatchProcessingCore
from sinner.models.logger.LoggerMixin import LoggerMixin
from sinner.models.status.StatusMixin import StatusMixin
from sinner.utilities import resolve_relative_path, get_app_dir, suggest_execution_providers, decode_execution_providers, list_class_descendants
from sinner.validators.AttributeLoader import Rules, AttributeLoader


class Benchmark(AttributeLoader, LoggerMixin):
class Benchmark(AttributeLoader, StatusMixin):
emoji: str = '📏'

source_path: str
Expand Down
12 changes: 6 additions & 6 deletions sinner/gui/GUIModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from sinner.models.PerfCounter import PerfCounter
from sinner.models.State import State
from sinner.models.audio.BaseAudioBackend import BaseAudioBackend
from sinner.models.logger.LoggerMixin import LoggerMixin
from sinner.models.logger.Mood import Mood
from sinner.models.status.StatusMixin import StatusMixin
from sinner.models.status.Mood import Mood
from sinner.processors.frame.BaseFrameProcessor import BaseFrameProcessor
from sinner.processors.frame.FrameExtractor import FrameExtractor
from sinner.typing import FramesList
Expand All @@ -33,7 +33,7 @@
EXTRACTING_PROGRESS_NAME = "Extracting"


class GUIModel(AttributeLoader, LoggerMixin):
class GUIModel(AttributeLoader, StatusMixin):
# configuration variables
frame_processor: List[str]
_source_path: str
Expand Down Expand Up @@ -456,7 +456,7 @@ def process_done(future_: Future[tuple[float, int] | None]) -> None:
if step < 1: # preventing going backwards
step = 1
next_frame += step
# self.logger.debug(msg=f"NEXT: {next_frame}, STEP: {step}, DELTA: {processing_delta}, LAST: {self.TimeLine.last_added_index}, AVG: {self._average_frame_skip.get_average()} ")
# self.status.debug(msg=f"NEXT: {next_frame}, STEP: {step}, DELTA: {processing_delta}, LAST: {self.TimeLine.last_added_index}, AVG: {self._average_frame_skip.get_average()} ")

def _process_frame(self, frame_index: int) -> tuple[float, int] | None:
"""
Expand All @@ -473,7 +473,7 @@ def _process_frame(self, frame_index: int) -> tuple[float, int] | None:
with PerfCounter() as frame_render_time:
for _, processor in self.processors.items():
n_frame.frame = processor.process_frame(n_frame.frame)
# self.logger.debug(msg=f"DONE: {n_frame.index}")
# self.status.debug(msg=f"DONE: {n_frame.index}")
self.TimeLine.add_frame(n_frame)
return frame_render_time.execution_time, n_frame.index

Expand All @@ -489,7 +489,7 @@ def _show_frames(self) -> None:
break
if n_frame is not None:
if n_frame.index != last_shown_frame_index: # check if frame is really changed
# self.logger.debug(msg=f"REQ: {self.TimeLine.last_requested_index}, SHOW: {n_frame.index}, ASYNC: {self.TimeLine.last_requested_index - n_frame.index}")
# self.status.debug(msg=f"REQ: {self.TimeLine.last_requested_index}, SHOW: {n_frame.index}, ASYNC: {self.TimeLine.last_requested_index - n_frame.index}")
self.Player.show_frame(n_frame.frame)
last_shown_frame_index = n_frame.index
if self.TimeLine.last_returned_index is None:
Expand Down
4 changes: 2 additions & 2 deletions sinner/handlers/frame/BaseFrameHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from typing import List

from sinner.models.NumberedFrame import NumberedFrame
from sinner.models.logger.LoggerMixin import LoggerMixin
from sinner.models.status.StatusMixin import StatusMixin
from sinner.validators.AttributeLoader import Rules, AttributeLoader
from sinner.typing import NumeratedFramePath
from sinner.utilities import load_class, get_file_name, is_file, normalize_path


class BaseFrameHandler(AttributeLoader, ABC, LoggerMixin):
class BaseFrameHandler(AttributeLoader, ABC, StatusMixin):
current_frame_index: int = 0

_target_path: str
Expand Down
2 changes: 1 addition & 1 deletion sinner/handlers/frame/CV2VideoHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from cv2 import VideoCapture
from tqdm import tqdm

from sinner.models.logger.Mood import Mood
from sinner.models.status.Mood import Mood
from sinner.handlers.frame.BaseFrameHandler import BaseFrameHandler
from sinner.handlers.frame.EOutOfRange import EOutOfRange
from sinner.helpers.FrameHelper import write_to_image, read_from_image
Expand Down
2 changes: 1 addition & 1 deletion sinner/handlers/frame/FFmpegVideoHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sinner.handlers.frame.BaseFrameHandler import BaseFrameHandler
from sinner.handlers.frame.EOutOfRange import EOutOfRange
from sinner.models.NumberedFrame import NumberedFrame
from sinner.models.logger.Mood import Mood
from sinner.models.status.Mood import Mood
from sinner.typing import NumeratedFramePath
from sinner.validators.AttributeLoader import Rules

Expand Down
2 changes: 1 addition & 1 deletion sinner/handlers/frame/ImageHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from typing import List

from sinner.models.logger.Mood import Mood
from sinner.models.status.Mood import Mood
from sinner.handlers.frame.BaseFrameHandler import BaseFrameHandler
from sinner.handlers.frame.EOutOfRange import EOutOfRange
from sinner.helpers.FrameHelper import read_from_image
Expand Down
6 changes: 3 additions & 3 deletions sinner/models/State.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

from sinner.helpers.FrameHelper import write_to_image, EmptyFrame
from sinner.models.NumberedFrame import NumberedFrame
from sinner.models.logger.LoggerMixin import LoggerMixin
from sinner.models.logger.Mood import Mood
from sinner.models.status.StatusMixin import StatusMixin
from sinner.models.status.Mood import Mood
from sinner.utilities import is_absolute_path, format_sequences, path_exists, is_file, normalize_path
from sinner.validators.AttributeLoader import Rules, AttributeLoader


class State(AttributeLoader, LoggerMixin):
class State(AttributeLoader, StatusMixin):
emoji: str = '👀'
source_path: str | None = None
initial_target_path: str | None = None
Expand Down
4 changes: 2 additions & 2 deletions sinner/models/audio/BaseAudioBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from argparse import Namespace
from typing import Any

from sinner.models.logger.LoggerMixin import LoggerMixin
from sinner.models.status.StatusMixin import StatusMixin
from sinner.utilities import normalize_path, load_class, list_class_descendants
from sinner.validators.AttributeLoader import AttributeLoader


class BaseAudioBackend(AttributeLoader, ABC, LoggerMixin):
class BaseAudioBackend(AttributeLoader, ABC, StatusMixin):
_media_path: str | None = None

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion sinner/models/audio/PygameAudioBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from moviepy.editor import AudioFileClip
import pygame

from sinner.models.logger.Mood import Mood
from sinner.models.status.Mood import Mood
from sinner.models.audio.BaseAudioBackend import BaseAudioBackend
from sinner.utilities import get_file_name, normalize_path

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from colorama import Back, Fore

from sinner.models.logger.Mood import Mood
from sinner.models.status.Mood import Mood


class LoggerMixin:
class StatusMixin:
enable_emoji: bool = False
emoji: str

Expand Down
4 changes: 2 additions & 2 deletions sinner/processors/frame/BaseFrameProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

from sinner.handlers.frame.BaseFrameHandler import BaseFrameHandler
from sinner.models.State import State
from sinner.models.logger.LoggerMixin import LoggerMixin
from sinner.models.status.StatusMixin import StatusMixin
from sinner.validators.AttributeLoader import Rules, AttributeLoader
from sinner.typing import Frame
from sinner.utilities import load_class, suggest_execution_providers, decode_execution_providers


class BaseFrameProcessor(ABC, AttributeLoader, LoggerMixin):
class BaseFrameProcessor(ABC, AttributeLoader, StatusMixin):
execution_provider: List[str]
self_processing: bool = False

Expand Down
2 changes: 1 addition & 1 deletion sinner/processors/frame/FaceSwapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from insightface.app.common import Face

from sinner.FaceAnalyser import FaceAnalyser
from sinner.models.logger.Mood import Mood
from sinner.models.status.Mood import Mood
from sinner.helpers.FrameHelper import read_from_image
from sinner.validators.AttributeLoader import Rules
from sinner.processors.frame.BaseFrameProcessor import BaseFrameProcessor
Expand Down
6 changes: 3 additions & 3 deletions sinner/webcam/WebCam.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from pyvirtualcam import Camera

from sinner.models.PerfCounter import PerfCounter
from sinner.models.logger.LoggerMixin import LoggerMixin
from sinner.models.logger.Mood import Mood
from sinner.models.status.StatusMixin import StatusMixin
from sinner.models.status.Mood import Mood
from sinner.processors.frame.BaseFrameProcessor import BaseFrameProcessor
from sinner.typing import Frame
from sinner.utilities import list_class_descendants, resolve_relative_path, is_image, is_video
Expand All @@ -23,7 +23,7 @@
from sinner.webcam.VideoCamera import VideoCamera


class WebCam(AttributeLoader, LoggerMixin):
class WebCam(AttributeLoader, StatusMixin):
emoji: str = '🤳'

stop: bool = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@
from unittest.mock import patch, MagicMock
from io import StringIO

from sinner.models.logger.LoggerMixin import LoggerMixin
from sinner.models.logger.Mood import Mood
from sinner.models.status.StatusMixin import StatusMixin
from sinner.models.status.Mood import Mood


class TestLoggerMixin:
class TestStatusMixin:
@pytest.fixture
def logger(self):
class TestLogger(LoggerMixin):
class TestStatus(StatusMixin):
pass

return TestLogger()
return TestStatus()

def test_set_position(self):
with patch('sys.stdout.write') as mock_write:
LoggerMixin.set_position((5, 10))
StatusMixin.set_position((5, 10))
mock_write.assert_called_once_with("\033[5;10H")

def test_set_position_negative(self):
with patch('sys.stdout.write') as mock_write, \
patch('shutil.get_terminal_size') as mock_get_terminal_size:
mock_get_terminal_size.return_value = MagicMock(lines=24, columns=80)
LoggerMixin.set_position((-1, -1))
StatusMixin.set_position((-1, -1))
mock_write.assert_called_once_with("\033[23;79H")

def test_restore_position(self):
with patch('sys.stdout.write') as mock_write:
LoggerMixin.restore_position((5, 10))
StatusMixin.restore_position((5, 10))
mock_write.assert_called_once_with("\033[u")

@pytest.mark.parametrize("encoding,expected", [
Expand All @@ -37,7 +37,7 @@ def test_restore_position(self):
])
def test_is_emoji_supported(self, encoding, expected):
with patch('locale.getpreferredencoding', return_value=encoding):
assert LoggerMixin.is_emoji_supported() == expected
assert StatusMixin.is_emoji_supported() == expected

def test_update_status(self, logger):
logger.enable_emoji = True
Expand Down

0 comments on commit 840cd77

Please sign in to comment.