Skip to content

Commit

Permalink
chore: add warnings (#291)
Browse files Browse the repository at this point in the history
* chore: add warnings

make IDEs signal deprecated code instead of relying on runtime logs only

* update python version
  • Loading branch information
JarbasAl authored Jan 4, 2025
1 parent 2cf8bc3 commit dfbac90
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/license_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: '3.11'
- name: Install Build Tools
run: |
python -m pip install build wheel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: '3.11'
- name: Install Build Tools
run: |
python -m pip install build wheel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: '3.11'
- name: Install Build Tools
run: |
python -m pip install build wheel
Expand Down
1 change: 0 additions & 1 deletion ovos_plugin_manager/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from ovos_utils.log import LOG
from ovos_bus_client.util import get_mycroft_bus
from ovos_config import Configuration
from ovos_utils.log import log_deprecation


# TODO - restore this log in next release with updated version string
Expand Down
7 changes: 6 additions & 1 deletion ovos_plugin_manager/microphone.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ovos_config import Configuration
from ovos_utils.log import LOG, deprecated

import warnings
from ovos_plugin_manager.templates.microphone import Microphone
from ovos_plugin_manager.utils import PluginTypes

Expand Down Expand Up @@ -31,6 +31,11 @@ def get_microphone_config(config=None):
@param config: global Configuration OR plugin class-specific configuration
@return: plugin class-specific configuration
"""
warnings.warn(
"get_microphone_config is deprecated, use Configuration() directly",
DeprecationWarning,
stacklevel=2,
)
from ovos_plugin_manager.utils.config import get_plugin_config
return get_plugin_config(config, "microphone")

Expand Down
2 changes: 1 addition & 1 deletion ovos_plugin_manager/stt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ovos_config import Configuration
from ovos_plugin_manager.utils.config import get_valid_plugin_configs, \
sort_plugin_configs, get_plugin_config
from ovos_utils.log import LOG, log_deprecation
from ovos_utils.log import LOG
from ovos_plugin_manager.templates.stt import STT, StreamingSTT, StreamThread


Expand Down
42 changes: 41 additions & 1 deletion ovos_plugin_manager/templates/stt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from queue import Queue
from threading import Thread, Event
from typing import List, Tuple, Optional, Set, Union

import warnings
from ovos_config import Configuration
from ovos_utils import classproperty
from ovos_utils.lang import standardize_lang_tag
Expand Down Expand Up @@ -78,6 +78,11 @@ def runtime_requirements(self):
@deprecated("self.recognizer has been deprecated! "
"if you need it 'from speech_recognition import Recognizer' directly", "1.0.0")
def recognizer(self):
warnings.warn(
"use 'from speech_recognition import Recognizer' directly",
DeprecationWarning,
stacklevel=2,
)
# only imported here to not drag dependency
from speech_recognition import Recognizer
if not self._recognizer:
Expand All @@ -103,6 +108,11 @@ def lang(self, val):
@deprecated("self.keys has been deprecated! "
"implement config handling directly instead", "1.0.0")
def keys(self):
warnings.warn(
"self.keys has been deprecated",
DeprecationWarning,
stacklevel=2,
)
return self._keys or self.config_core.get("keys", {})

@keys.setter
Expand All @@ -114,6 +124,11 @@ def keys(self, val):
@deprecated("self.credential has been deprecated! "
"implement config handling directly instead", "1.0.0")
def credential(self):
warnings.warn(
"self.credential has been deprecated",
DeprecationWarning,
stacklevel=2,
)
return self._credential or self.config.get("credential", {})

@credential.setter
Expand All @@ -125,6 +140,11 @@ def credential(self, val):
@deprecated("self.init_language has been deprecated! "
"implement config handling directly instead", "1.0.0")
def init_language(config_core):
warnings.warn(
"implement config handling directly instead",
DeprecationWarning,
stacklevel=2,
)
lang = config_core.get("lang", "en-US")
return standardize_lang_tag(lang, macro=True)

Expand Down Expand Up @@ -158,13 +178,23 @@ def available_languages(self) -> Set[str]:
class TokenSTT(STT, metaclass=ABCMeta):
@deprecated("TokenSTT is deprecated, please subclass from STT directly", "1.0.0")
def __init__(self, config=None):
warnings.warn(
"please subclass from STT directly",
DeprecationWarning,
stacklevel=2,
)
super().__init__(config)
self.token = self.credential.get("token")


class GoogleJsonSTT(STT, metaclass=ABCMeta):
@deprecated("GoogleJsonSTT is deprecated, please subclass from STT directly", "1.0.0")
def __init__(self, config=None):
warnings.warn(
"please subclass from STT directly",
DeprecationWarning,
stacklevel=2,
)
super().__init__(config)
if not self.credential.get("json") or self.keys.get("google_cloud"):
self.credential["json"] = self.keys["google_cloud"]
Expand All @@ -174,6 +204,11 @@ def __init__(self, config=None):
class BasicSTT(STT, metaclass=ABCMeta):
@deprecated("BasicSTT is deprecated, please subclass from STT directly", "1.0.0")
def __init__(self, config=None):
warnings.warn(
"please subclass from STT directly",
DeprecationWarning,
stacklevel=2,
)
super().__init__(config)
self.username = str(self.credential.get("username"))
self.password = str(self.credential.get("password"))
Expand All @@ -183,6 +218,11 @@ class KeySTT(STT, metaclass=ABCMeta):

@deprecated("KeySTT is deprecated, please subclass from STT directly", "1.0.0")
def __init__(self, config=None):
warnings.warn(
"please subclass from STT directly",
DeprecationWarning,
stacklevel=2,
)
super().__init__(config)
self.id = str(self.credential.get("client_id"))
self.key = str(self.credential.get("client_key"))
Expand Down
Loading

0 comments on commit dfbac90

Please sign in to comment.