powerline / powerline

Powerline is a statusline plugin for vim, and provides statuslines and prompts for several other applications, including zsh, bash, tmux, IPython, Awesome and Qtile.

Home Page:https://powerline.readthedocs.org/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ipython 8 broken

PH111P opened this issue · comments

Powerline seems to break on ipython 8.0.1, sigh. Problem seems to be the removed shutdown_hook; probably needs some work.

Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3.10/pathlib.py", line 1303, in is_dir
    return S_ISDIR(self.stat().st_mode)
AttributeError: 'str' object has no attribute 'stat'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/traitlets/traitlets.py", line 537, in get
    value = obj._trait_values[self.name]
KeyError: 'prompts'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/IPython/utils/ipstruct.py", line 143, in __getattr__
    result = self[key]
KeyError: 'shutdown_hook'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/bin/ipython", line 8, in <module>
    sys.exit(start_ipython())
  File "/usr/lib/python3.10/site-packages/IPython/__init__.py", line 123, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/usr/lib/python3.10/site-packages/traitlets/config/application.py", line 845, in launch_instance
    app.initialize(argv)
  File "/usr/lib/python3.10/site-packages/traitlets/config/application.py", line 88, in inner
    return method(app, *args, **kwargs)
  File "/usr/lib/python3.10/site-packages/IPython/terminal/ipapp.py", line 277, in initialize
    self.init_shell()
  File "/usr/lib/python3.10/site-packages/IPython/terminal/ipapp.py", line 291, in init_shell
    self.shell = self.interactive_shell_class.instance(parent=self,
  File "/usr/lib/python3.10/site-packages/traitlets/config/configurable.py", line 540, in instance
    inst = cls(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 579, in __init__
    self.init_prompt_toolkit_cli()
  File "/usr/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 389, in init_prompt_toolkit_cli
    **self._extra_prompt_options()
  File "/usr/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 486, in _extra_prompt_options
    get_message = get_message()
  File "/usr/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 476, in get_message
    return PygmentsTokens(self.prompts.in_prompt_tokens())
  File "/usr/lib/python3.10/site-packages/traitlets/traitlets.py", line 577, in __get__
    return self.get(obj, cls)
  File "/usr/lib/python3.10/site-packages/traitlets/traitlets.py", line 540, in get
    default = obj.trait_defaults(self.name)
  File "/usr/lib/python3.10/site-packages/traitlets/traitlets.py", line 1580, in trait_defaults
    return self._get_trait_default_generator(names[0])(self)
  File "/usr/lib/python3.10/site-packages/traitlets/traitlets.py", line 977, in __call__
    return self.func(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/IPython/terminal/interactiveshell.py", line 275, in _prompts_default
    return self.prompts_class(self)
  File "/usr/lib/python3.10/site-packages/powerline/bindings/ipython/since_7.py", line 58, in __init__
    shutdown_hook = ShutdownHook(shell)
  File "/usr/lib/python3.10/site-packages/powerline/bindings/ipython/post_0_11.py", line 37, in __init__
    ip.hooks.shutdown_hook.add(self)
  File "/usr/lib/python3.10/site-packages/IPython/utils/ipstruct.py", line 145, in __getattr__
    raise AttributeError(key) from e
AttributeError: shutdown_hook

This works for me.

diff --git a/powerline/bindings/ipython/since_7.py b/powerline/bindings/ipython/since_7.py
index a555d64a..5ce3fd39 100644
--- a/powerline/bindings/ipython/since_7.py
+++ b/powerline/bindings/ipython/since_7.py
@@ -58,10 +58,10 @@ class PowerlinePrompts(Prompts):
     '''Class that returns powerline prompts
     '''
     def __init__(self, shell):
-        shutdown_hook = ShutdownHook(shell)
+        # shutdown_hook = ShutdownHook(shell)
         powerline = ConfigurableIPythonPowerline(shell)
         self.shell = shell
-        powerline.do_setup(shell, self, shutdown_hook)
+        powerline.do_setup(shell, self, None)
         self.last_output_count = None
         self.last_output = {}

However, it is obviously not a good solution.

According to https://github.com/ipython/ipython/blob/master/IPython/core/hooks.py, it seems like the official recommendation is to just use atexit instead. I'm not very familiar with either codebase, but it seems like just replacing the ip.hooks.shutdown_hook.add with atexit.register in post_0_11.py should be all that's needed.