From 43bfe5b39a62f23fb30582ce7f3773330bfedbcd Mon Sep 17 00:00:00 2001 From: miro Date: Sat, 4 Jan 2025 17:03:36 +0000 Subject: [PATCH] chore: add warnings make IDEs signal deprecated code instead of relying on runtime logs only --- ovos_workshop/backwards_compat.py | 7 +++++++ ovos_workshop/decorators/__init__.py | 7 ++++++- ovos_workshop/decorators/converse.py | 7 +++++++ ovos_workshop/decorators/fallback_handler.py | 7 +++++++ ovos_workshop/intents.py | 12 +++++++++++- ovos_workshop/skill_launcher.py | 2 +- ovos_workshop/skills/common_query_skill.py | 7 ++++++- ovos_workshop/skills/intent_provider.py | 16 ++++++++++++++++ ovos_workshop/skills/layers.py | 7 +++++++ 9 files changed, 68 insertions(+), 4 deletions(-) diff --git a/ovos_workshop/backwards_compat.py b/ovos_workshop/backwards_compat.py index 4a57f4cb..788ab1f8 100644 --- a/ovos_workshop/backwards_compat.py +++ b/ovos_workshop/backwards_compat.py @@ -1,3 +1,10 @@ +import warnings +warnings.warn( + "will be removed soon", + DeprecationWarning, + stacklevel=2, +) + try: # TODO - remove this file in next stable release from ovos_utils.ocp import * except ImportError: diff --git a/ovos_workshop/decorators/__init__.py b/ovos_workshop/decorators/__init__.py index 823361ea..d9a099a8 100644 --- a/ovos_workshop/decorators/__init__.py +++ b/ovos_workshop/decorators/__init__.py @@ -1,7 +1,7 @@ from functools import wraps from typing import Optional, Callable from ovos_utils.log import log_deprecation - +import warnings from ovos_workshop.decorators.killable import killable_intent, killable_event from ovos_workshop.decorators.layers import enables_layer, \ disables_layer, layer_intent, removes_layer, resets_layers, replaces_layer @@ -75,6 +75,11 @@ def intent_file_handler(intent_file: str): """ Deprecated decorator for adding a method as an intent file handler. """ + warnings.warn( + "Use `@intent_handler' instead", + DeprecationWarning, + stacklevel=2, + ) def real_decorator(func): # Store the intent_file inside the function diff --git a/ovos_workshop/decorators/converse.py b/ovos_workshop/decorators/converse.py index f4e5fcc2..8c4c17d5 100644 --- a/ovos_workshop/decorators/converse.py +++ b/ovos_workshop/decorators/converse.py @@ -1,4 +1,11 @@ from ovos_utils.log import log_deprecation +import warnings + +warnings.warn( + "Import from `ovos_workshop.decorators`", + DeprecationWarning, + stacklevel=2, +) def converse_handler(func): diff --git a/ovos_workshop/decorators/fallback_handler.py b/ovos_workshop/decorators/fallback_handler.py index 76ff7861..3e9f8dd6 100644 --- a/ovos_workshop/decorators/fallback_handler.py +++ b/ovos_workshop/decorators/fallback_handler.py @@ -1,5 +1,12 @@ from ovos_utils.log import log_deprecation +import warnings + +warnings.warn( + "Import from `ovos_workshop.decorators`", + DeprecationWarning, + stacklevel=2, +) def fallback_handler(priority=50): log_deprecation("Import from `ovos_workshop.decorators`", "0.1.0") diff --git a/ovos_workshop/intents.py b/ovos_workshop/intents.py index 6355f935..32386598 100644 --- a/ovos_workshop/intents.py +++ b/ovos_workshop/intents.py @@ -3,7 +3,7 @@ from os.path import exists from threading import RLock from typing import List, Tuple, Optional - +import warnings from ovos_bus_client.message import Message, dig_for_message from ovos_bus_client.util import get_mycroft_bus from ovos_utils.log import LOG, log_deprecation @@ -500,6 +500,11 @@ class expect intent_name; this was the weird one expecting the internal name = intent_name.split(':')[1] log_deprecation(f"Update to `self.remove_intent({name})", "0.1.0") + warnings.warn( + "use `self.remove_intent' instead", + DeprecationWarning, + stacklevel=2, + ) self.remove_intent(name) def remove_intent(self, intent_name: str): @@ -614,6 +619,11 @@ def register_padatious_entity(self, entity_name: str, filename: str, def get_intent_names(self): log_deprecation("Reference `intent_names` directly", "0.1.0") + warnings.warn( + "use `self.intent_names' property instead", + DeprecationWarning, + stacklevel=2, + ) return self.intent_names def detach_all(self): diff --git a/ovos_workshop/skill_launcher.py b/ovos_workshop/skill_launcher.py index 0d55fd0d..0458f70b 100644 --- a/ovos_workshop/skill_launcher.py +++ b/ovos_workshop/skill_launcher.py @@ -13,7 +13,7 @@ from ovos_plugin_manager.skills import find_skill_plugins, get_skill_directories from ovos_utils import wait_for_exit_signal from ovos_utils.file_utils import FileWatcher -from ovos_utils.log import LOG, deprecated, log_deprecation +from ovos_utils.log import LOG, log_deprecation from ovos_utils.process_utils import RuntimeRequirements from ovos_workshop.skills.active import ActiveSkill diff --git a/ovos_workshop/skills/common_query_skill.py b/ovos_workshop/skills/common_query_skill.py index eb7564ff..4eaec4fb 100644 --- a/ovos_workshop/skills/common_query_skill.py +++ b/ovos_workshop/skills/common_query_skill.py @@ -18,7 +18,7 @@ from ovos_bus_client import Message from ovos_utils.file_utils import resolve_resource_file from ovos_utils.log import LOG, log_deprecation - +import warnings from ovos_workshop.skills.ovos import OVOSSkill @@ -60,6 +60,11 @@ class CommonQuerySkill(OVOSSkill): def __init__(self, *args, **kwargs): log_deprecation("'CommonQuerySkill' class has been deprecated, use @common_query decorator with regular OVOSSkill instead", "4.0.0") + warnings.warn( + "use '@common_query' decorator with regular OVOSSkill instead", + DeprecationWarning, + stacklevel=2, + ) # these should probably be configurable self.level_confidence = { CQSMatchLevel.EXACT: 0.9, diff --git a/ovos_workshop/skills/intent_provider.py b/ovos_workshop/skills/intent_provider.py index 8009765a..4f8742cb 100644 --- a/ovos_workshop/skills/intent_provider.py +++ b/ovos_workshop/skills/intent_provider.py @@ -4,10 +4,21 @@ from ovos_bus_client.message import Message from ovos_workshop.skills.fallback import FallbackSkill from ovos_config.config import read_mycroft_config, update_mycroft_config +import warnings +warnings.warn( + "use pipeline plugins instead", + DeprecationWarning, + stacklevel=2, +) class BaseIntentEngine: def __init__(self, name, config=None): + warnings.warn( + "make a pipeline plugin instead", + DeprecationWarning, + stacklevel=2, + ) log_deprecation("This base class is not supported", "0.1.0") self.name = name.lower() config = config or read_mycroft_config() @@ -51,6 +62,11 @@ def calc_intent(self, query): class IntentEngineSkill(FallbackSkill): def __init__(self, *args, **kwargs): + warnings.warn( + "make a pipeline plugin instead", + DeprecationWarning, + stacklevel=2, + ) log_deprecation("This base class is not supported", "0.1.0") super().__init__(*args, **kwargs) self.engine = None diff --git a/ovos_workshop/skills/layers.py b/ovos_workshop/skills/layers.py index dcedc619..ff9b3f90 100644 --- a/ovos_workshop/skills/layers.py +++ b/ovos_workshop/skills/layers.py @@ -1,3 +1,10 @@ from ovos_workshop.decorators.layers import IntentLayers from ovos_utils.log import log_deprecation log_deprecation("Import from `ovos_workshop.decorators.layers`", "0.1.0") +import warnings + +warnings.warn( + "Import from `ovos_workshop.decorators.layers`", + DeprecationWarning, + stacklevel=2, +)