joouha / euporie

Jupyter notebooks in the terminal
https://euporie.readthedocs.io
MIT License
1.54k stars 36 forks source link

Euporie Notebook freezes when typing `df[` #79

Closed danielcs88 closed 1 year ago

danielcs88 commented 1 year ago

Euporie freezes into an error when typing df[. This is very common operation in Pandas, as typing df[column].

I've recorded a video of the crash.

asciicast

I'm using iTerm2 in MacOS with CSI u mode or WezTerm with the suggested settings.

local wezterm = require 'wezterm'

return {
     keys = {
     {key="Enter", mods="CTRL", action=wezterm.action{SendString="\x1b[13;5u"}},
     {key="Enter", mods="SHIFT", action=wezterm.action{SendString="\x1b[13;2u"}},
   },

Traceback

Traceback (most recent call last):
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/eventloop/utils.py", line 73, in schedule
    func()
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/application/application.py", line 476, in redraw
    self._redraw()
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/application/application.py", line 548, in _redraw
    self.context.copy().run(run_in_context)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/application/application.py", line 531, in run_in_context
    self.renderer.render(self, self.layout)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/core/renderer.py", line 411, in render
    self._cursor_pos, self._last_style = _output_screen_diff(
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/core/renderer.py", line 167, in _output_screen_diff
    new_max_line_len = min(width - 1, get_max_column_index(new_row, zwe_row))
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/core/renderer.py", line 121, in get_max_column_index
    {
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/euporie/core/renderer.py", line 124, in <setcomp>
    if cell.char != " " or style_string_has_style[cell.style]
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/renderer.py", line 306, in __missing__
    attrs = self.style_string_to_attrs[style_str]
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/renderer.py", line 284, in __missing__
    attrs = self.get_attrs_for_style_str(style_str)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/styles/style.py", line 397, in get_attrs_for_style_str
    return self._merged_style.get_attrs_for_style_str(style_str, default)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/styles/style.py", line 311, in get_attrs_for_style_str
    inline_attrs = _parse_style_str(part)
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/styles/style.py", line 171, in _parse_style_str
    attrs = attrs._replace(color=parse_color(part))
  File "/Users/daniel/miniforge3/envs/euporie/lib/python3.10/site-packages/prompt_toolkit/styles/style.py", line 75, in parse_color
    raise ValueError("Wrong color format %r" % text)
ValueError: Wrong color format 'key'

conda list

# packages in environment at /Users/daniel/miniforge3/envs/euporie:
#
# Name                    Version                   Build  Channel
aenum                     3.1.12                   pypi_0    pypi
aiofiles                  22.1.0                   pypi_0    pypi
aiohttp                   3.8.4                    pypi_0    pypi
aiosignal                 1.3.1                    pypi_0    pypi
aiosqlite                 0.19.0                   pypi_0    pypi
anyio                     3.7.0                    pypi_0    pypi
appdirs                   1.4.4                    pypi_0    pypi
appnope                   0.1.3                    pypi_0    pypi
argon2-cffi               21.3.0                   pypi_0    pypi
argon2-cffi-bindings      21.2.0                   pypi_0    pypi
arrow                     1.2.3                    pypi_0    pypi
asttokens                 2.2.1                    pypi_0    pypi
async-timeout             4.0.2                    pypi_0    pypi
asyncssh                  2.13.1                   pypi_0    pypi
attrs                     23.1.0                   pypi_0    pypi
babel                     2.12.1                   pypi_0    pypi
backcall                  0.2.0                    pypi_0    pypi
beautifulsoup4            4.12.2                   pypi_0    pypi
black                     23.3.0                   pypi_0    pypi
bleach                    6.0.0                    pypi_0    pypi
bzip2                     1.0.8                h3422bc3_4    conda-forge
ca-certificates           2023.5.7             hf0a4a13_0    conda-forge
certifi                   2023.5.7                 pypi_0    pypi
cffi                      1.15.1                   pypi_0    pypi
charset-normalizer        3.1.0                    pypi_0    pypi
click                     8.1.3                    pypi_0    pypi
comm                      0.1.3                    pypi_0    pypi
contourpy                 1.0.7                    pypi_0    pypi
cryptography              41.0.0                   pypi_0    pypi
cycler                    0.11.0                   pypi_0    pypi
debugpy                   1.6.7                    pypi_0    pypi
decorator                 5.1.1                    pypi_0    pypi
defusedxml                0.7.1                    pypi_0    pypi
entrypoints               0.4                      pypi_0    pypi
euporie                   2.4.1                    pypi_0    pypi
exceptiongroup            1.1.1                    pypi_0    pypi
executing                 1.2.0                    pypi_0    pypi
fastjsonschema            2.17.1                   pypi_0    pypi
flatlatex                 0.15                     pypi_0    pypi
fonttools                 4.39.4                   pypi_0    pypi
fqdn                      1.5.1                    pypi_0    pypi
frozenlist                1.3.3                    pypi_0    pypi
fsspec                    2023.5.0                 pypi_0    pypi
idna                      3.4                      pypi_0    pypi
imagesize                 1.4.1                    pypi_0    pypi
ipykernel                 6.23.1                   pypi_0    pypi
ipython                   8.13.2                   pypi_0    pypi
ipython-genutils          0.2.0                    pypi_0    pypi
ipywidgets                8.0.6                    pypi_0    pypi
isoduration               20.11.0                  pypi_0    pypi
isort                     5.12.0                   pypi_0    pypi
jedi                      0.18.2                   pypi_0    pypi
jinja2                    3.1.2                    pypi_0    pypi
jldracula                 0.1.0                    pypi_0    pypi
json5                     0.9.14                   pypi_0    pypi
jsonpointer               2.3                      pypi_0    pypi
jsonschema                4.17.3                   pypi_0    pypi
jupyter-client            7.4.9                    pypi_0    pypi
jupyter-core              5.3.0                    pypi_0    pypi
jupyter-events            0.6.3                    pypi_0    pypi
jupyter-lsp               2.2.0                    pypi_0    pypi
jupyter-server            2.6.0                    pypi_0    pypi
jupyter-server-fileid     0.9.0                    pypi_0    pypi
jupyter-server-terminals  0.4.4                    pypi_0    pypi
jupyter-server-ydoc       0.8.0                    pypi_0    pypi
jupyter-ydoc              0.2.4                    pypi_0    pypi
jupyterlab                3.6.3                    pypi_0    pypi
jupyterlab-code-formatter 2.2.1                    pypi_0    pypi
jupyterlab-lsp            4.2.0                    pypi_0    pypi
jupyterlab-pygments       0.2.2                    pypi_0    pypi
jupyterlab-server         2.22.1                   pypi_0    pypi
jupyterlab-widgets        3.0.7                    pypi_0    pypi
jupytext                  1.14.5                   pypi_0    pypi
kiwisolver                1.4.4                    pypi_0    pypi
libffi                    3.4.2                h3422bc3_5    conda-forge
libsqlite                 3.42.0               hb31c410_0    conda-forge
libzlib                   1.2.13               h03a7124_4    conda-forge
linkify-it-py             1.0.3                    pypi_0    pypi
markdown-it-py            2.1.0                    pypi_0    pypi
markupsafe                2.1.2                    pypi_0    pypi
matplotlib                3.7.1                    pypi_0    pypi
matplotlib-inline         0.1.6                    pypi_0    pypi
mdit-py-plugins           0.3.5                    pypi_0    pypi
mdurl                     0.1.2                    pypi_0    pypi
mistune                   2.0.5                    pypi_0    pypi
multidict                 6.0.4                    pypi_0    pypi
mypy-extensions           1.0.0                    pypi_0    pypi
nbclassic                 1.0.0                    pypi_0    pypi
nbclient                  0.8.0                    pypi_0    pypi
nbconvert                 7.4.0                    pypi_0    pypi
nbformat                  5.8.0                    pypi_0    pypi
ncurses                   6.3                  h07bb92c_1    conda-forge
nest-asyncio              1.5.6                    pypi_0    pypi
notebook                  6.5.4                    pypi_0    pypi
notebook-shim             0.2.3                    pypi_0    pypi
numpy                     1.24.3                   pypi_0    pypi
openssl                   3.1.0                h53f4e23_3    conda-forge
overrides                 7.3.1                    pypi_0    pypi
packaging                 23.1                     pypi_0    pypi
pandas                    2.0.2                    pypi_0    pypi
pandocfilters             1.5.0                    pypi_0    pypi
parso                     0.8.3                    pypi_0    pypi
pathspec                  0.11.1                   pypi_0    pypi
pexpect                   4.8.0                    pypi_0    pypi
pickleshare               0.7.5                    pypi_0    pypi
pillow                    9.5.0                    pypi_0    pypi
pip                       23.1.2             pyhd8ed1ab_0    conda-forge
platformdirs              3.5.1                    pypi_0    pypi
prometheus-client         0.17.0                   pypi_0    pypi
prompt-toolkit            3.0.38                   pypi_0    pypi
psutil                    5.9.5                    pypi_0    pypi
ptyprocess                0.7.0                    pypi_0    pypi
pure-eval                 0.2.2                    pypi_0    pypi
pyarrow                   12.0.0                   pypi_0    pypi
pycparser                 2.21                     pypi_0    pypi
pygments                  2.15.1                   pypi_0    pypi
pyparsing                 3.0.9                    pypi_0    pypi
pyperclip                 1.8.2                    pypi_0    pypi
pyrsistent                0.19.3                   pypi_0    pypi
python                    3.10.11         h3ba56d0_0_cpython    conda-forge
python-dateutil           2.8.2                    pypi_0    pypi
python-json-logger        2.0.7                    pypi_0    pypi
pytz                      2023.3                   pypi_0    pypi
pyyaml                    6.0                      pypi_0    pypi
pyzmq                     25.1.0                   pypi_0    pypi
readline                  8.2                  h92ec313_1    conda-forge
regex                     2023.5.5                 pypi_0    pypi
requests                  2.31.0                   pypi_0    pypi
rfc3339-validator         0.1.4                    pypi_0    pypi
rfc3986-validator         0.1.1                    pypi_0    pypi
rich                      13.3.1                   pypi_0    pypi
seaborn                   0.12.2                   pypi_0    pypi
send2trash                1.8.2                    pypi_0    pypi
setuptools                67.7.2             pyhd8ed1ab_0    conda-forge
six                       1.16.0                   pypi_0    pypi
sixelcrop                 0.1.3                    pypi_0    pypi
sniffio                   1.3.0                    pypi_0    pypi
soupsieve                 2.4.1                    pypi_0    pypi
sqlalchemy                2.0.15                   pypi_0    pypi
stack-data                0.6.2                    pypi_0    pypi
tabulate                  0.9.0                    pypi_0    pypi
terminado                 0.17.1                   pypi_0    pypi
timg                      1.1.6                    pypi_0    pypi
tinycss2                  1.2.1                    pypi_0    pypi
tk                        8.6.12               he1e0b03_0    conda-forge
tokenize-rt               5.0.0                    pypi_0    pypi
toml                      0.10.2                   pypi_0    pypi
tomli                     2.0.1                    pypi_0    pypi
tornado                   6.3.2                    pypi_0    pypi
traitlets                 5.9.0                    pypi_0    pypi
typing-extensions         4.6.2                    pypi_0    pypi
tzdata                    2023.3                   pypi_0    pypi
uc-micro-py               1.0.2                    pypi_0    pypi
universal-pathlib         0.0.23                   pypi_0    pypi
uri-template              1.2.0                    pypi_0    pypi
urllib3                   2.0.2                    pypi_0    pypi
wcwidth                   0.2.6                    pypi_0    pypi
webcolors                 1.13                     pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
websocket-client          1.5.2                    pypi_0    pypi
wheel                     0.40.0             pyhd8ed1ab_0    conda-forge
widgetsnbextension        4.0.7                    pypi_0    pypi
xz                        5.2.6                h57fd34a_0    conda-forge
y-py                      0.5.9                    pypi_0    pypi
yapf                      0.33.0                   pypi_0    pypi
yarl                      1.9.2                    pypi_0    pypi
ypy-websocket             0.8.2                    pypi_0    pypi
joouha commented 1 year ago

Hi,

Thanks for the detailed bug report. I've not able to reproduce this yet, unfortunately.

Could you send your euporie configuration? (~/Library/Application Support/euporie/config.json on MacOS, possibly).

Also, do you have any ipython start-up scripts which could be affecting things?

danielcs88 commented 1 year ago

~/Library/Application Support/euporie/config.json

{
  "syntax_theme": "dracula",
  "autoformat": true,
  "autocomplete": true,
  "notebook": {
    "show_cell_borders": true,
    "background_pattern": 4,
    "edit_mode": "micro",
    "syntax_theme": "dracula",
    "set_cursor_shape": false,
    "always_show_tab_bar": false,
    "show_side_bar": false,
    "color_scheme": "default",
    "show_top_bar": true,
    "expand": true
  },
  "console": {
    "syntax_theme": "dracula"
  }
}

iPython startup

I do have startup scripts running at startup but mainly helper functions.

I suspect it might be a configuration on my ipython_config.py file. Recently, on an update, iPython's auto suggest wasn't working properly and the fix was the last line of the following configuration options: `

c = get_config()

c.TerminalInteractiveShell.highlighting_style = "dracula"
c.TerminalInteractiveShell.true_color = True
c.TerminalInteractiveShell.editor = "micro"
c.InteractiveShell.color_info = True
c.TerminalInteractiveShell.highlight_matching_brackets = True
c.TerminalInteractiveShell.autoformatter = "black"

# Last line option
c.TerminalInteractiveShell.shortcuts = [
    {"command": "IPython:auto_suggest.resume_hinting", "new_keys": []}
]

I'll check on my end if disabling this option resolves the Euporie crash.

danielcs88 commented 1 year ago

~/Library/Application Support/euporie/config.json

{
  "syntax_theme": "dracula",
  "autoformat": true,
  "autocomplete": true,
  "notebook": {
    "show_cell_borders": true,
    "background_pattern": 4,
    "edit_mode": "micro",
    "syntax_theme": "dracula",
    "set_cursor_shape": false,
    "always_show_tab_bar": false,
    "show_side_bar": false,
    "color_scheme": "default",
    "show_top_bar": true,
    "expand": true
  },
  "console": {
    "syntax_theme": "dracula"
  }
}

iPython startup

I do have startup scripts running at startup but mainly helper functions.

I suspect it might be a configuration on my ipython_config.py file. Recently, on an update, iPython's auto suggest wasn't working properly and the fix was the last line of the following configuration options: `

c = get_config()

c.TerminalInteractiveShell.highlighting_style = "dracula"
c.TerminalInteractiveShell.true_color = True
c.TerminalInteractiveShell.editor = "micro"
c.InteractiveShell.color_info = True
c.TerminalInteractiveShell.highlight_matching_brackets = True
c.TerminalInteractiveShell.autoformatter = "black"

# Last line option
c.TerminalInteractiveShell.shortcuts = [
    {"command": "IPython:auto_suggest.resume_hinting", "new_keys": []}
]

I'll check on my end if disabling this option resolves the Euporie crash.

Update: Still crashing.

joouha commented 1 year ago

Thanks - I've fixed this and made a new release, v2.4.3.

This issue occurred when the type of a completion contained a space, which was happening with "dict key" completions.

danielcs88 commented 1 year ago

@joouha

Amazing! Bug gone!

asciicast