Skip to content

Commit

Permalink
Remote client: Show message when there's a mismatch between Spyder an…
Browse files Browse the repository at this point in the history
…d the server
  • Loading branch information
ccordoba12 authored and hlouzada committed Nov 25, 2024
1 parent d6c4cb5 commit bbe54b6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
14 changes: 9 additions & 5 deletions spyder/plugins/remoteclient/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def __emit_connection_status(self, status, message):
)
)

def __emit_version_mismatch(self, version):
def __emit_version_mismatch(self, version: str):
if self._plugin is not None:
self._plugin.sig_version_mismatch.emit(version)
self._plugin.sig_version_mismatch.emit(self.config_id, version)

@property
def _api_token(self):
Expand Down Expand Up @@ -438,17 +438,21 @@ async def ensure_server_installed(self) -> bool:
self._logger.error("Checking server version timed out")
return False

version = Version(output.stdout.splitlines()[-1].strip())
version = output.stdout.splitlines()[-1].strip()

if version >= Version(SPYDER_REMOTE_MAX_VERSION):
if Version(version) >= Version(SPYDER_REMOTE_MAX_VERSION):
self._logger.error(
f"Server version mismatch: {version} is greater than "
f"the maximum supported version {SPYDER_REMOTE_MAX_VERSION}"
)
self.__emit_version_mismatch(version)
self.__emit_connection_status(
status=ConnectionStatus.Error,
message=_("Error connecting to the remote server"),
)
return False

if version < Version(SPYDER_REMOTE_MIN_VERSION):
if Version(version) < Version(SPYDER_REMOTE_MIN_VERSION):
self._logger.error(
f"Server version mismatch: {version} is lower than "
f"the minimum supported version {SPYDER_REMOTE_MIN_VERSION}"
Expand Down
6 changes: 4 additions & 2 deletions spyder/plugins/remoteclient/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# Third-party imports
from qtpy.QtCore import Signal, Slot
from packaging.version import Version

# Local imports
from spyder.api.asyncdispatcher import AsyncDispatcher
Expand Down Expand Up @@ -67,7 +66,7 @@ class RemoteClient(SpyderPluginV2):
sig_connection_lost = Signal(str)
sig_connection_status_changed = Signal(dict)

sig_version_mismatch = Signal(Version)
sig_version_mismatch = Signal(str, str)

_sig_kernel_started = Signal(object, dict)

Expand Down Expand Up @@ -115,6 +114,9 @@ def on_initialize(self):
self.sig_client_message_logged.connect(
container.sig_client_message_logged
)
self.sig_version_mismatch.connect(
container.on_server_version_mismatch
)
self._sig_kernel_started.connect(container.on_kernel_started)

def on_first_registration(self):
Expand Down
26 changes: 26 additions & 0 deletions spyder/plugins/remoteclient/widgets/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

# Third-party imports
from qtpy.QtCore import Signal
from qtpy.QtWidgets import QMessageBox

# Local imports
from spyder.api.translations import _
from spyder.api.widgets.main_container import PluginMainContainer
from spyder.plugins.ipythonconsole.utils.kernel_handler import KernelHandler
from spyder.plugins.remoteclient import SPYDER_REMOTE_MAX_VERSION
from spyder.plugins.remoteclient.api import (
MAX_CLIENT_MESSAGES,
RemoteClientActions,
Expand Down Expand Up @@ -262,6 +264,30 @@ def on_kernel_started(self, ipyclient, kernel_info):
# Connect client to the kernel
ipyclient.connect_kernel(kernel_handler)

def on_server_version_mismatch(self, config_id, version: str):
"""
Actions to take when there's a mismatch between the
spyder-remote-services version installed in the server and the one
supported by Spyder.
"""
auth_method = self.get_conf(f"{config_id}/auth_method")
server_name = self.get_conf(f"{config_id}/{auth_method}/name")

QMessageBox.critical(
self,
_("Remote server error"),
_(
"When trying to connect to the server <b>{}</b>, we detected "
"that the version of <tt>spyder-remote-services</tt>, the "
"package Spyder needs to communicate to, is <b>{}</b>, which "
"is greater than the maximum one currently supported "
"(<b>{}</b>)."
"<br><br>"
"Please update Spyder to fix this problem."
).format(server_name, version, SPYDER_REMOTE_MAX_VERSION),
QMessageBox.Ok,
)

# ---- Private API
# -------------------------------------------------------------------------
def _show_connection_dialog(self):
Expand Down

0 comments on commit bbe54b6

Please sign in to comment.