From b9f598ce471ed614d1d870f6278c4b1a24cfd858 Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Fri, 3 Feb 2023 23:46:18 +0000 Subject: [PATCH] Fix mailman shell to work with iPython >= 8.0 and display banner. Fixes #1062 * Fix mailman shell to work with iPython >= 8.0 and display banner. --- src/mailman/commands/cli_withlist.py | 4 +--- src/mailman/commands/tests/test_cli_shell.py | 8 ++++---- src/mailman/docs/NEWS.rst | 2 ++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mailman/commands/cli_withlist.py b/src/mailman/commands/cli_withlist.py index aaf39d637..f1ec041c4 100644 --- a/src/mailman/commands/cli_withlist.py +++ b/src/mailman/commands/cli_withlist.py @@ -22,7 +22,6 @@ import sys import click from contextlib import ExitStack, suppress -from functools import partial from lazr.config import as_boolean from mailman.config import config from mailman.core.i18n import _ @@ -57,12 +56,11 @@ def start_ipython1(overrides, banner, *, debug=False): def start_ipython4(overrides, banner, *, debug=False): try: from IPython.terminal.embed import InteractiveShellEmbed - shell = InteractiveShellEmbed.instance() except ImportError: if debug: print_exc() return None - return partial(shell.mainloop, local_ns=overrides, display_banner=banner) + return InteractiveShellEmbed.instance(banner1=banner, user_ns=overrides) def start_ipython(overrides, banner, debug): diff --git a/src/mailman/commands/tests/test_cli_shell.py b/src/mailman/commands/tests/test_cli_shell.py index 8453829f3..dd38d8365 100644 --- a/src/mailman/commands/tests/test_cli_shell.py +++ b/src/mailman/commands/tests/test_cli_shell.py @@ -79,9 +79,9 @@ class TestShell(unittest.TestCase): mock = MagicMock() with hacked_sys_modules('IPython.terminal.embed', mock): self._command.invoke(shell, ('--interactive',)) - posargs, kws = mock.InteractiveShellEmbed.instance().mainloop.call_args + posargs, kws = mock.InteractiveShellEmbed.instance.call_args self.assertEqual( - kws['display_banner'], """Welcome to the GNU Mailman shell + kws['banner1'], """Welcome to the GNU Mailman shell Use commit() to commit changes. Use abort() to discard changes since the last commit. Exit with ctrl+D does an implicit commit() but exit() does not.\n""") @@ -103,9 +103,9 @@ Exit with ctrl+D does an implicit commit() but exit() does not.\n""") mock = MagicMock() with hacked_sys_modules('IPython.terminal.embed', mock): self._command.invoke(shell, ('--interactive',)) - posargs, kws = mock.InteractiveShellEmbed.instance().mainloop.call_args + posargs, kws = mock.InteractiveShellEmbed.instance.call_args self.assertEqual( - kws['display_banner'], """Welcome to the GNU Mailman shell + kws['banner1'], """Welcome to the GNU Mailman shell Use commit() to commit changes. Use abort() to discard changes since the last commit. Exit with ctrl+D does an implicit commit() but exit() does not.\n""") diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 5dd46cca1..9e0f18c4d 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -30,6 +30,8 @@ Bugs fixed postmap_command: no longer throws an exception. (Closes #1058) * When bounce processing disables delivery for a user, the user's score is reset so it will be zero if delivery is enabled. (Closes #1061) +* The ``mailman shell`` command now works and displays the banner with + ``use_ipython: yes``. (Closes #1062) .. _news-3.3.8: -- 2.11.4.GIT