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

PR: Remove double message on restart after kernel dies (IPython console) #21540

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
IPython console: Improve banner when IPython version is missing
Also, add a small test to check that the version is shown as expected
for internal and external interpreters.
  • Loading branch information
ccordoba12 committed Nov 17, 2023
commit 00bcac39e06f2e624362a0e8396e99b48b68fead
12 changes: 9 additions & 3 deletions spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Standard library imports
import os
import os.path as osp
import re
import shutil
import sys
from textwrap import dedent
Expand Down Expand Up @@ -1382,11 +1383,16 @@ def test_kernel_kill(ipyconsole, qtbot, external_interpreter):
assert len(old_open_comms) == 1
with qtbot.waitSignal(shell.sig_prompt_ready, timeout=30000):
shell.execute(crash_string)
assert crash_string in shell._control.toPlainText()
assert "The kernel died, restarting..." in shell._control.toPlainText()

console_text = shell._control.toPlainText()
assert crash_string in console_text
assert "The kernel died, restarting..." in console_text

# Check we don't show error generated by `conda run`
assert "conda.cli.main_run" not in shell._control.toPlainText()
assert "conda.cli.main_run" not in console_text

# Check IPython version is shown as expected
assert list(re.finditer(r"IPython \d+\.", console_text))

# Check a new comm replaced the old one
new_open_comms = list(shell.kernel_handler.kernel_comm._comms.keys())
Expand Down
10 changes: 7 additions & 3 deletions spyder/plugins/ipythonconsole/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os
import os.path as osp
import shlex
import subprocess
import sys

# Third-party imports
Expand Down Expand Up @@ -1368,24 +1369,27 @@ def interpreter_versions(self, path_to_custom_interpreter=None):
ipython_version=release.version
)
else:
import subprocess
versions = {}
pyexec = self.get_conf('executable', section='main_interpreter')
if path_to_custom_interpreter:
pyexec = path_to_custom_interpreter
py_cmd = u'%s -c "import sys; print(sys.version)"' % pyexec

py_cmd = '%s -c "import sys; print(sys.version)"' % pyexec
ipy_cmd = (
u'%s -c "import IPython.core.release as r; print(r.version)"'
'%s -c "import IPython.core.release as r; print(r.version)"'
% pyexec
)

for cmd in [py_cmd, ipy_cmd]:
try:
# Use clean environment
proc = programs.run_shell_command(cmd, env={})
output, _err = proc.communicate()
except subprocess.CalledProcessError:
output = ''

output = output.decode().split('\n')[0].strip()

if 'IPython' in cmd:
versions['ipython_version'] = output
else:
Expand Down
9 changes: 8 additions & 1 deletion spyder/plugins/ipythonconsole/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,15 @@ def long_banner(self):
'Python %s\n' % py_ver,
'Type "copyright", "credits" or "license" for more information.',
'\n\n',
'IPython %s -- An enhanced Interactive Python.\n' % ipy_ver
]

if ipy_ver:
banner_parts.append(
'IPython %s -- An enhanced Interactive Python.\n' % ipy_ver
)
else:
banner_parts.append('IPython -- An enhanced Interactive Python.\n')

banner = ''.join(banner_parts)

# Pylab additions
Expand Down