From cc1db9b10a4daace8b03eb803695e9323a525d18 Mon Sep 17 00:00:00 2001 From: miro Date: Thu, 5 Sep 2024 11:26:59 +0100 Subject: [PATCH] fix/restore_dead_code with deprecation warnings --- ovos_plugin_manager/templates/tts.py | 39 +++++++++++++++++++++++++-- ovos_plugin_manager/utils/__init__.py | 6 +++-- test/unittests/test_tts.py | 25 +++-------------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/ovos_plugin_manager/templates/tts.py b/ovos_plugin_manager/templates/tts.py index c4fc9f96..b05ecaf5 100644 --- a/ovos_plugin_manager/templates/tts.py +++ b/ovos_plugin_manager/templates/tts.py @@ -9,7 +9,7 @@ from pathlib import Path from queue import Queue from threading import Thread -from typing import AsyncIterable, List, Dict +from typing import AsyncIterable, List, Dict, Tuple, Optional import quebra_frases import requests @@ -21,7 +21,6 @@ from ovos_utils import classproperty from ovos_utils.fakebus import FakeBus from ovos_utils.file_utils import get_cache_directory -from ovos_utils.file_utils import resolve_resource_file from ovos_utils.lang.visimes import VISIMES from ovos_utils.log import LOG, deprecated, log_deprecation from ovos_utils.metrics import Stopwatch @@ -132,6 +131,42 @@ def curate_caches(cls): for cache in TTSContext._caches.values(): cache.curate() + ########### + # deprecated methods + @deprecated("'get_message' has been deprecated without replacement", "1.0.0") + def get_message(self, kwargs) -> Optional[Message]: + msg = kwargs.get("message") or dig_for_message() + if msg and isinstance(msg, Message): + return msg + + @deprecated("'self.get_lang' has been deprecated, access self.lang directly", "1.0.0") + def get_lang(self, kwargs) -> str: + return kwargs.get("lang") or self.lang + + @deprecated("'self.get_gender' has been deprecated, access self.voice and self.lang directly", "1.0.0") + def get_gender(self, kwargs) -> Optional[str]: + gender = kwargs.get("gender") + message = self.get_message(kwargs) + if not gender and message: + gender = message.data.get("gender") or \ + message.context.get("gender") + return gender + + @deprecated("'self.get_voice' has been deprecated, access self.voice directly", "1.0.0") + def get_voice(self, kwargs): + voice = kwargs.get("voice") + message = self.get_message(kwargs) + if not voice and message: + # get voice from message object if possible + voice = message.data.get("voice") or \ + message.context.get("voice") + return voice or self.voice + + @deprecated("'self.get' has been deprecated, access self.voice and self.lang directly", "1.0.0") + def get(self, kwargs=None) -> Tuple[str, Optional[str]]: + kwargs = kwargs or {} + return self.get_lang(kwargs), self.get_voice(kwargs) + class TTS: """TTS abstract class to be implemented by all TTS engines. diff --git a/ovos_plugin_manager/utils/__init__.py b/ovos_plugin_manager/utils/__init__.py index c1c4ee21..8972c4bf 100644 --- a/ovos_plugin_manager/utils/__init__.py +++ b/ovos_plugin_manager/utils/__init__.py @@ -18,7 +18,7 @@ from typing import Optional import pkg_resources -from ovos_utils.log import LOG +from ovos_utils.log import LOG, log_deprecation class PluginTypes(str, Enum): @@ -198,7 +198,9 @@ class ReadWriteStream: with an optional maximum buffer size """ - def __init__(self, s=b'', max_size=None): + def __init__(self, s=b'', chop_samples=-1, max_size=None): + if chop_samples != -1: + log_deprecation("'chop_samples' kwarg has been deprecated and will be ignored", "1.0.0") self.buffer = deque(s) self.write_event = Event() self.lock = Lock() diff --git a/test/unittests/test_tts.py b/test/unittests/test_tts.py index b5602921..6ad28ba9 100644 --- a/test/unittests/test_tts.py +++ b/test/unittests/test_tts.py @@ -3,7 +3,6 @@ from unittest.mock import patch, Mock from ovos_bus_client.session import Session -from ovos_config import Configuration from ovos_utils.fakebus import FakeBus, Message from ovos_plugin_manager.templates.tts import TTS, TTSContext @@ -119,24 +118,8 @@ def test_format_speak_tags_with_speech_no_tags(self): tagged_with_exclusion = TTS.format_speak_tags("Don'tSpeak This.But Not this.", False) self.assertEqual(tagged_with_exclusion, valid_output) - def test_playback_thread(self): - pass - # TODO - - def test_tts_context(self): - pass - # TODO - def test_tts_validator(self): - pass - # TODO - - def test_concat_tts(self): - pass - # TODO - - def test_remote_tt(self): - pass + from ovos_plugin_manager.templates.tts import TTSValidator # TODO @@ -193,15 +176,15 @@ def test_get_tts_config(self, get_config): self.CONFIG_SECTION, None) def test_get_voice_id(self): - pass + from ovos_plugin_manager.tts import get_voice_id # TODO def test_scan_voices(self): - pass + from ovos_plugin_manager.tts import scan_voices # TODO def test_get_voices(self): - pass + from ovos_plugin_manager.tts import get_voices # TODO