From e02f79272d388defb5dc23357f85c7639d7dcba0 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Mon, 8 May 2023 11:16:52 +0100 Subject: [PATCH] Pass connection file when opening console Before, we passed the kernel ID when calling `create_client_for_kernel()` in the IPython Console plugin. This worked, even though that function expected the connection file, because that function used `find_connection_file()` to fix the path to the connection file. After the refactor in PR spyder-ide/spyder#19062, the argument passed for the connection file is expected to be really the file path and no attempt to fix it is made, so now we have to really pass the connection file. --- spyder_notebook/notebookplugin.py | 8 ++++++-- spyder_notebook/widgets/main_widget.py | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/spyder_notebook/notebookplugin.py b/spyder_notebook/notebookplugin.py index 35c4162..ff95bf3 100644 --- a/spyder_notebook/notebookplugin.py +++ b/spyder_notebook/notebookplugin.py @@ -6,6 +6,7 @@ """Notebook plugin.""" # Standard library imports +import logging import os.path as osp # Spyder imports @@ -20,6 +21,8 @@ from spyder_notebook.widgets.main_widget import NotebookMainWidget from spyder_notebook.utils.localization import _ +logger = logging.getLogger(__name__) + class NotebookPlugin(SpyderDockablePlugin): """Spyder Notebook plugin.""" @@ -94,10 +97,11 @@ def open_notebook(self, filenames=None): self.get_widget().open_notebook(filenames) # ------ Private API ------------------------------------------------------ - def _open_console(self, kernel_id, tab_name): + def _open_console(self, connection_file, tab_name): """Open an IPython console as requested.""" + logger.info(f'Opening console with {connection_file=}') ipyconsole = self.get_plugin(Plugins.IPythonConsole) - ipyconsole.create_client_for_kernel(kernel_id) + ipyconsole.create_client_for_kernel(connection_file) ipyclient = ipyconsole.get_current_client() ipyclient.allow_rename = False ipyconsole.rename_client_tab(ipyclient, tab_name) diff --git a/spyder_notebook/widgets/main_widget.py b/spyder_notebook/widgets/main_widget.py index e403d36..e76c739 100644 --- a/spyder_notebook/widgets/main_widget.py +++ b/spyder_notebook/widgets/main_widget.py @@ -4,7 +4,11 @@ # Licensed under the terms of the MIT License # (see LICENSE.txt for details) +# Standard library imports +import os.path as osp + # Third-party imports +from jupyter_core.paths import jupyter_runtime_dir from qtpy.QtCore import Signal from qtpy.QtWidgets import QMessageBox, QVBoxLayout @@ -55,8 +59,8 @@ class NotebookMainWidget(PluginMainWidget): Parameters ----------- - kernel_id: str - Id of the kernel to open a console for. + connection_file: str + Name of the connection file for the kernel to open a console for. tab_name: str Tab name to set for the created console. """ @@ -317,8 +321,10 @@ def open_console(self, client=None): ) return + connection_file = f'kernel-{kernel_id}.json' + connection_file = osp.join(jupyter_runtime_dir(), connection_file) self.sig_open_console_requested.emit( - kernel_id, + connection_file, client.get_short_name() )