Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address deprecation warnings #535

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions neon_utils/metrics_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from socket import gethostname
from time import time, strftime
from ovos_bus_client import Message, MessageBusClient
from ovos_utils.log import LOG
from ovos_utils.log import LOG, deprecated

from neon_utils.message_utils import dig_for_message

Expand Down Expand Up @@ -86,15 +86,16 @@ def report(self):
"duration": self.time}))


@deprecated("Emit `neon.metric` message instead of calling this function.",
"2.0.0")
def report_metric(name: str, **kwargs):
"""
Report a metric over the MQ bus.
:param name: Name of the metric to report
:param kwargs: Arbitrary data to include with metric report
"""
# TODO: Deprecate and move to PHAL plugin
try:
from neon_utils.mq_utils import send_mq_request
from neon_mq_connector.utils.client_utils import send_mq_request
send_mq_request("/neon_metrics", {**{"name": name}, **kwargs},
"neon_metrics_input", expect_response=False)
return True
Expand Down
74 changes: 47 additions & 27 deletions neon_utils/signal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import inspect
import ovos_utils.signal

from time import time, sleep
from typing import Optional, Callable

from mock.mock import Mock
from ovos_bus_client import MessageBusClient, Message
from ovos_utils.log import log_deprecation

from neon_utils.logger import LOG

_BUS: MessageBusClient = None
_MAX_TIMEOUT: int = None
_BUS: Optional[MessageBusClient] = None
_MAX_TIMEOUT: Optional[int] = None

_create_signal = None
_check_for_signal = None
_wait_for_signal_clear = None
_wait_for_signal_create = None
_create_signal: Optional[Callable] = None
_check_for_signal: Optional[Callable] = None
_wait_for_signal_clear: Optional[Callable] = None
_wait_for_signal_create: Optional[Callable] = None


def create_signal(*args, **kwargs):
Expand Down Expand Up @@ -101,35 +105,51 @@ def init_signal_handlers():
global _wait_for_signal_create
global _MAX_TIMEOUT
from ovos_config.config import Configuration
_MAX_TIMEOUT = int(dict(Configuration()).get("signal", {}).get(
"max_wait_seconds") or '300')
signal_config = Configuration().get("signal") or dict()
patch_imports = signal_config.get("patch_imports", True)
_MAX_TIMEOUT = int(signal_config.get("max_wait_seconds") or 300)

if check_signal_manager_available():
LOG.info("Signal Manager Available")
_create_signal = _manager_create_signal
_check_for_signal = _manager_check_for_signal
_wait_for_signal_clear = _manager_wait_for_signal_clear
_wait_for_signal_create = _manager_wait_for_signal_create

ovos_utils.signal.check_for_signal = _check_for_signal
ovos_utils.signal.create_signal = _create_signal
if patch_imports:
log_deprecation("Import patching will be deprecated. Disable in "
"configuration by setting `signal`.`patch_imports` "
"to `False`", "2.0.0")
import ovos_utils.signal
ovos_utils.signal.check_for_signal = _check_for_signal
ovos_utils.signal.create_signal = _create_signal
try:
import mycroft.util.signal
mycroft.util.signal.create_signal = _create_signal
mycroft.util.signal.check_for_signal = _check_for_signal
LOG.info(f"Overrode mycroft.util.signal methods")
except (ImportError, AttributeError) as e:
LOG.debug(e)
except TypeError as e:
# This comes from tests overriding MessageBusClient()
LOG.error(e)

else:
LOG.warning("No signal manager available; falling back to FS signals")
_create_signal = ovos_utils.signal.create_signal
_check_for_signal = ovos_utils.signal.check_for_signal
_wait_for_signal_clear = _fs_wait_for_signal_clear
_wait_for_signal_create = _fs_wait_for_signal_create

try:
import mycroft.util.signal
mycroft.util.signal.create_signal = _create_signal
mycroft.util.signal.check_for_signal = _check_for_signal
LOG.info(f"Overrode mycroft.util.signal methods")
except (ImportError, AttributeError) as e:
LOG.debug(e)
except TypeError as e:
# This comes from tests overriding MessageBusClient()
LOG.error(e)
LOG.warning("FS signals are deprecated. Signal methods will have no effect.")
if patch_imports:
log_deprecation("Import patching will be deprecated. Disable in "
"configuration by setting `signal`.`patch_imports` "
"to `False`", "2.0.0")
import ovos_utils.signal
_create_signal = ovos_utils.signal.create_signal
_check_for_signal = ovos_utils.signal.check_for_signal
_wait_for_signal_clear = _fs_wait_for_signal_clear
_wait_for_signal_create = _fs_wait_for_signal_create
else:
_create_signal = Mock(return_value=False)
_check_for_signal = Mock(return_value=False)
_wait_for_signal_clear = Mock(return_value=False)
_wait_for_signal_create = Mock(return_value=False)


def check_signal_manager_available() -> bool:
Expand Down
Loading