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

Feature/add line numbers to prompt #14223

Merged
merged 5 commits into from Dec 17, 2023

Conversation

cohml
Copy link

@cohml cohml commented Oct 29, 2023

This PR adds line numbers to the default prompt (#13965).

Emacs mode preview:

image

Vim mode preview:

image

Note: These changes are untested for now. I am struggling to run the existing tests in my dev environment. Are there any instructions on how to get everything set up for testing purposes?

@Carreau
Copy link
Member

Carreau commented Oct 29, 2023

$ pip install -e '.[test]' # all the necessary fro test
$ pip install -e '.[test_extra]' # all the optional deps
$ pip install -e '.[all]' # everything

and then just

$ pytest

I recommend using the --lf/--ff (only last failed, or failed first tests), when iterating.

@cohml
Copy link
Author

cohml commented Oct 30, 2023

Sorry to be a bother, but I have followed those steps and still the tests are failing, even on main.

Here are my commands, from the root directory, with relevant output:

$ conda create -p ./env pip
$ conda activate ./env
$ pip install -e '.[test]'
$ pip install -e '.[test_extra]'
$ pip install -e '.[all]'
$ git checkout main
$ git pull
Already up to date.
$ cd IPython
$ pytest --version
pytest 6.2.5
$ pytest
platform darwin -- Python 3.12.0, pytest-6.2.5, py-1.11.0, pluggy-1.3.0
rootdir: /Users/<redacted>/forks/ipython, configfile: pyproject.toml
plugins: anyio-4.0.0, asyncio-0.20.3
asyncio: mode=Mode.STRICT
collected 1336 items / 17 errors / 1319 selected
[...]
================================================ short test summary info ================================================
ERROR core/tests/test_async_helpers.py - AttributeError: module 'multiprocessing.connection' has no attribute 'CHALLEN...
ERROR core/tests/test_async_helpers.py - AttributeError: module 'multiprocessing.connection' has no attribute 'CHALLEN...
ERROR core/tests/test_inputsplitter.py - Failed: DID NOT WARN. No warnings of type (<class 'DeprecationWarning'>,) was...
ERROR core/tests/test_inputsplitter.py - Failed: DID NOT WARN. No warnings of type (<class 'DeprecationWarning'>,) was...
ERROR external/qt_for_kernel.py - ImportError:
ERROR terminal/console.py - AttributeError: __file__
ERROR terminal/pt_inputhooks/glut.py - ModuleNotFoundError: No module named 'OpenGL'
ERROR terminal/pt_inputhooks/gtk.py - ModuleNotFoundError: No module named 'gtk'
ERROR terminal/pt_inputhooks/gtk3.py - ModuleNotFoundError: No module named 'gi'
ERROR terminal/pt_inputhooks/gtk4.py - ModuleNotFoundError: No module named 'gi'
ERROR terminal/pt_inputhooks/pyglet.py - ModuleNotFoundError: No module named 'pyglet'
ERROR terminal/pt_inputhooks/qt.py - ImportError:
ERROR terminal/pt_inputhooks/wx.py - ModuleNotFoundError: No module named 'wx'
ERROR utils/_process_cli.py - ModuleNotFoundError: No module named 'clr'
ERROR utils/_process_win32_controller.py - ModuleNotFoundError: No module named 'msvcrt'
ERROR utils/daemonize.py - ModuleNotFoundError: No module named 'ipyparallel.apps.daemonize'
ERROR utils/eventful.py - ModuleNotFoundError: No module named 'traitlets.eventful'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 17 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================ 13 warnings, 17 errors in 1.63s ============================================

So it seems to me like some necessary packages are still not getting installed. What am I doing wrong?

@Carreau
Copy link
Member

Carreau commented Oct 31, 2023

pyest seem to not pick up its config in pyproject.toml, not sure why. I've pushed some commit that shoudl make the test pass in CI.

@Carreau
Copy link
Member

Carreau commented Oct 31, 2023

I've also made it a tad more generic, with a template parameter for the line numbering.

@Carreau
Copy link
Member

Carreau commented Oct 31, 2023

Also I'll let you look at the function def _extra_prompt_options somewhere, I think this is where the bug if that prevent the fist line to refresh with relative line number when using emacs mode.

@cohml cohml force-pushed the feature/add-line-numbers-to-prompt branch from 9675993 to 29315b8 Compare December 7, 2023 19:48
@cohml
Copy link
Author

cohml commented Dec 7, 2023

@Carreau -- I'm finally able to get back to this, but am confused by what I see wrt these failing tests.

The build log shows that the first failure is in core/tests/test_completer.py. However I cannot reproduce this failure as all test are passing for me locally:

❯ git branch
* feature/add-line-numbers-to-prompt
  main
❯ git pull
Already up to date.
❯ pytest core/tests/test_completer.py
/Users/chamill/git/forks/ipython/ipython/env/lib/python3.12/site-packages/pytest_asyncio/plugin.py:173: DeprecationWarning: You're using an outdated version of pytest. Newer releases of pytest-asyncio will not be compatible with this pytest version. Please update pytest to version 7 or later.
  warnings.warn(
========================================================= test session starts =========================================================
platform darwin -- Python 3.12.0, pytest-6.2.5, py-1.11.0, pluggy-1.3.0
rootdir: /Users/chamill/git/forks/ipython/ipython, configfile: pyproject.toml
plugins: asyncio-0.20.3, anyio-4.1.0
asyncio: mode=Mode.STRICT
collected 88 items

core/tests/test_completer.py ...............X........................................................................           [100%]

========================================================== warnings summary ===========================================================
../env/lib/python3.12/site-packages/dateutil/tz/tz.py:37
  /Users/chamill/git/forks/ipython/ipython/env/lib/python3.12/site-packages/dateutil/tz/tz.py:37: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
    EPOCH = datetime.datetime.utcfromtimestamp(0)

IPython/core/tests/test_completer.py: 65 warnings
  /Users/chamill/git/forks/ipython/ipython/env/lib/python3.12/unittest/case.py:580: RuntimeWarning: TestResult has no addDuration method
    warnings.warn("TestResult has no addDuration method",

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================================================== slowest 10 durations =========================================================
0.61s call     IPython/core/tests/test_completer.py::test_unicode_range
0.38s call     IPython/core/tests/test_completer.py::TestCompleter::test_dict_key_completion_string
0.14s call     IPython/core/tests/test_completer.py::TestCompleter::test_dict_key_completion_unicode_py3
0.12s call     IPython/core/tests/test_completer.py::TestCompleter::test_jedi
0.07s call     IPython/core/tests/test_completer.py::TestCompleter::test_matcher_suppression_with_jedi
0.07s call     IPython/core/tests/test_completer.py::TestCompleter::test_func_kw_completions
0.07s call     IPython/core/tests/test_completer.py::TestCompleter::test_greedy_completions
0.05s call     IPython/core/tests/test_completer.py::TestCompleter::test_abspath_file_completions
0.02s call     IPython/core/tests/test_completer.py::TestCompleter::test_aimport_module_completer
0.02s call     IPython/core/tests/test_completer.py::TestCompleter::test_import_module_completer
============================================= 87 passed, 1 xpassed, 66 warnings in 1.88s ==============================================

In fact, out of fully 1303 tests just a single one is failing for me locally (and, incidentally, I checked and it was also failing on main?):

❯ pytest core/tests/ extensions/tests/ external/tests/ lib/tests/ terminal/tests/ testing/tests/ tests/ utils/tests/
/Users/chamill/git/forks/ipython/ipython/env/lib/python3.12/site-packages/pytest_asyncio/plugin.py:173: DeprecationWarning: You're using an outdated version of pytest. Newer releases of pytest-asyncio will not be compatible with this pytest version. Please update pytest to version 7 or later.
  warnings.warn(
========================================================= test session starts =========================================================
platform darwin -- Python 3.12.0, pytest-6.2.5, py-1.11.0, pluggy-1.3.0
rootdir: /Users/chamill/git/forks/ipython/ipython, configfile: pyproject.toml
plugins: asyncio-0.20.3, anyio-4.1.0
asyncio: mode=Mode.STRICT
collected 1331 items

core/tests/test_alias.py ....                                                                                                   [  0%]
core/tests/test_application.py ...                                                                                              [  0%]
core/tests/test_async_helpers.py ..s........                                                                                    [  1%]
core/tests/test_autocall.py ..                                                                                                  [  1%]
core/tests/test_compilerop.py ......                                                                                            [  1%]
core/tests/test_completer.py ...............X........................................................................           [  8%]
core/tests/test_completerlib.py ............                                                                                    [  9%]
core/tests/test_debugger.py ........ss..                                                                                        [ 10%]
core/tests/test_display.py .........................                                                                            [ 12%]
core/tests/test_displayhook.py .......                                                                                          [ 12%]
core/tests/test_events.py .....                                                                                                 [ 13%]
core/tests/test_exceptiongroup_tb.py .........                                                                                  [ 13%]
core/tests/test_extension.py ...                                                                                                [ 14%]
core/tests/test_formatters.py ..............................                                                                    [ 16%]
core/tests/test_guarded_eval.py ............................................................................................... [ 23%]
............................................................................................................................... [ 32%]
.                                                                                                                               [ 33%]
core/tests/test_handlers.py .                                                                                                   [ 33%]
core/tests/test_history.py .........                                                                                            [ 33%]
core/tests/test_hooks.py ...                                                                                                    [ 34%]
core/tests/test_imports.py .................                                                                                    [ 35%]
core/tests/test_inputsplitter.py ........................................................................                       [ 40%]
core/tests/test_inputtransformer.py .................                                                                           [ 41%]
core/tests/test_inputtransformer2.py .........................................                                                  [ 45%]
core/tests/test_inputtransformer2_line.py ......                                                                                [ 45%]
core/tests/test_interactiveshell.py ......................................................................................      [ 51%]
core/tests/test_iplib.py .......                                                                                                [ 52%]
core/tests/test_logger.py ..                                                                                                    [ 52%]
core/tests/test_magic.py ..........................................................F........................................... [ 60%]
...                                                                                                                             [ 60%]
core/tests/test_magic_arguments.py .                                                                                            [ 60%]
core/tests/test_magic_terminal.py ...........                                                                                   [ 61%]
core/tests/test_oinspect.py ..................................                                                                  [ 64%]
core/tests/test_page.py .                                                                                                       [ 64%]
core/tests/test_paths.py ...........                                                                                            [ 64%]
core/tests/test_prefilter.py ......                                                                                             [ 65%]
core/tests/test_profile.py .....                                                                                                [ 65%]
core/tests/test_prompts.py ...                                                                                                  [ 65%]
core/tests/test_pylabtools.py ..............                                                                                    [ 67%]
core/tests/test_run.py .....s...............................                                                                    [ 69%]
core/tests/test_shellapp.py ...                                                                                                 [ 70%]
core/tests/test_splitinput.py ..                                                                                                [ 70%]
core/tests/test_ultratb.py .......................                                                                              [ 71%]
extensions/tests/test_autoreload.py ..........                                                                                  [ 72%]
extensions/tests/test_storemagic.py ..                                                                                          [ 72%]
external/tests/test_qt_loaders.py .                                                                                             [ 72%]
lib/tests/test_backgroundjobs.py ....                                                                                           [ 73%]
lib/tests/test_clipboard.py .                                                                                                   [ 73%]
lib/tests/test_deepreload.py ...                                                                                                [ 73%]
lib/tests/test_display.py ............................                                                                          [ 75%]
lib/tests/test_editorhooks.py .                                                                                                 [ 75%]
lib/tests/test_imports.py ...                                                                                                   [ 75%]
lib/tests/test_latextools.py ..ss........s.                                                                                     [ 76%]
lib/tests/test_lexers.py .                                                                                                      [ 77%]
lib/tests/test_pretty.py ...................................                                                                    [ 79%]
lib/tests/test_pygments.py ...                                                                                                  [ 79%]
terminal/tests/test_debug_magic.py .                                                                                            [ 79%]
terminal/tests/test_embed.py ..                                                                                                 [ 80%]
terminal/tests/test_help.py .......                                                                                             [ 80%]
terminal/tests/test_interactivshell.py .........                                                                                [ 81%]
terminal/tests/test_pt_inputhooks.py s                                                                                          [ 81%]
terminal/tests/test_shortcuts.py ........................................................                                       [ 85%]
testing/tests/test_decorators.py .ss..s.ss....s                                                                                 [ 86%]
testing/tests/test_ipunittest.py .....                                                                                          [ 87%]
testing/tests/test_tools.py .s........                                                                                          [ 87%]
utils/tests/test_capture.py ........................                                                                            [ 89%]
utils/tests/test_decorators.py .                                                                                                [ 89%]
utils/tests/test_deprecated.py .                                                                                                [ 89%]
utils/tests/test_dir2.py ....                                                                                                   [ 90%]
utils/tests/test_imports.py ......                                                                                              [ 90%]
utils/tests/test_importstring.py ...                                                                                            [ 90%]
utils/tests/test_io.py ...                                                                                                      [ 90%]
utils/tests/test_module_paths.py ......                                                                                         [ 91%]
utils/tests/test_openpy.py ...                                                                                                  [ 91%]
utils/tests/test_path.py ss...s.....s.....s...........s                                                                         [ 93%]
utils/tests/test_process.py .s.....ssss........                                                                                 [ 95%]
utils/tests/test_pycolorize.py ........                                                                                         [ 95%]
utils/tests/test_shimmodule.py ..                                                                                               [ 96%]
utils/tests/test_sysinfo.py ..                                                                                                  [ 96%]
utils/tests/test_tempdir.py ..                                                                                                  [ 96%]
utils/tests/test_text.py ........................                                                                               [ 98%]
utils/tests/test_tokenutil.py ...................                                                                               [ 99%]
utils/tests/test_wildcard.py ......                                                                                             [100%]

============================================================== FAILURES ===============================================================
___________________________________________________________ test_extension ____________________________________________________________

    def test_extension():
        # Debugging information for failures of this test
        print('sys.path:')
        for p in sys.path:
            print(' ', p)
        print('CWD', os.getcwd())

>       pytest.raises(ImportError, _ip.magic, "load_ext daft_extension")
E       Failed: DID NOT RAISE <class 'ImportError'>

core/tests/test_magic.py:833: Failed

[...]

======================================================= short test summary info =======================================================
FAILED core/tests/test_magic.py::test_extension - Failed: DID NOT RAISE <class 'ImportError'>
================================ 1 failed, 1303 passed, 26 skipped, 1 xpassed, 454 warnings in 46.25s =================================

Do you have any insights? This is my first exposure to GitHub builds so perhaps there are variables I'm unaware of when it comes to reproducibility...

For context, all outputs above were generated with a fresh clone of the repository created using the same commands from my earlier comment, though thanks to you they now seem to work.

@cohml
Copy link
Author

cohml commented Dec 7, 2023

To add further confusion, when I run that (single) failing test module directly, it actually passes, both on my branch and on main:

❯ pytest core/tests/test_magic.py
/Users/chamill/git/forks/ipython/ipython/env/lib/python3.12/site-packages/pytest_asyncio/plugin.py:173: DeprecationWarning: You're using an outdated version of pytest. Newer releases of pytest-asyncio will not be compatible with this pytest version. Please update pytest to version 7 or later.
  warnings.warn(
========================================================= test session starts =========================================================
platform darwin -- Python 3.12.0, pytest-6.2.5, py-1.11.0, pluggy-1.3.0
rootdir: /Users/chamill/git/forks/ipython/ipython, configfile: pyproject.toml
plugins: asyncio-0.20.3, anyio-4.1.0
asyncio: mode=Mode.STRICT
collected 105 items

core/tests/test_magic.py ...................................................................................................... [ 97%]
...                                                                                                                             [100%]

========================================================== warnings summary ===========================================================
IPython/core/tests/test_magic.py: 12 warnings
  /Users/chamill/git/forks/ipython/ipython/env/lib/python3.12/unittest/case.py:580: RuntimeWarning: TestResult has no addDuration method
    warnings.warn("TestResult has no addDuration method",

IPython/core/tests/test_magic.py::test_doctest_mode
  /Users/chamill/git/forks/ipython/ipython/IPython/core/magics/basic.py:461: DeprecationWarning: `magic(...)` is deprecated since IPython 0.13 (warning added in 8.1), use run_line_magic(magic_name, parameter_s).
    shell.magic('xmode Plain')

IPython/core/tests/test_magic.py::test_doctest_mode
  /Users/chamill/git/forks/ipython/ipython/IPython/core/magics/basic.py:472: DeprecationWarning: `magic(...)` is deprecated since IPython 0.13 (warning added in 8.1), use run_line_magic(magic_name, parameter_s).
    shell.magic('xmode ' + dstore.xmode)

IPython/core/tests/test_magic.py::test_prun_quotes
  /Users/chamill/git/forks/ipython/ipython/IPython/core/tests/test_magic.py:822: DeprecationWarning: `magic(...)` is deprecated since IPython 0.13 (warning added in 8.1), use run_line_magic(magic_name, parameter_s).
    _ip.magic(r"prun -q x = '\t'")

IPython/core/tests/test_magic.py::test_extension
  /Users/chamill/git/forks/ipython/ipython/env/lib/python3.12/site-packages/_pytest/python_api.py:738: DeprecationWarning: `magic(...)` is deprecated since IPython 0.13 (warning added in 8.1), use run_line_magic(magic_name, parameter_s).
    func(*args[1:], **kwargs)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================================================== slowest 10 durations =========================================================
0.12s call     IPython/core/tests/test_magic.py::test_magic_error_status
0.07s call     IPython/core/tests/test_magic.py::test_notebook_export_json
0.05s call     IPython/core/tests/test_magic.py::TestResetErrors::test_reset_redefine
0.05s call     IPython/core/tests/test_magic.py::test_reset_hard
0.04s call     IPython/core/tests/test_magic.py::test_reset_out
0.03s call     IPython/core/tests/test_magic.py::test_script_bg_proc
0.03s call     IPython/core/tests/test_magic.py::test_script_err
0.03s call     IPython/core/tests/test_magic.py::test_script_bg_out
0.03s call     IPython/core/tests/test_magic.py::test_script_out_err
0.03s call     IPython/core/tests/test_magic.py::test_script_bg_err
================================================== 105 passed, 16 warnings in 0.87s ===================================================

I really want to get these changes merged, especially since they're useful and a (in theory) relatively simple addition to this otherwise awesome package. But I admit, the challenge in simply running these tests is seriously dampening the enthusiasm :(

What do you suppose I'm doing wrong??

@Carreau
Copy link
Member

Carreau commented Dec 7, 2023

Don't worry about the failures, they are on Python 3.13-dev, this means that IPython has incompatibility with the next version of Python, it is likely changes in Python internal APIs, and it's either to warn us – core dev – that we need to update the API we use, or to report a bug upstream in CPython.

@cohml
Copy link
Author

cohml commented Dec 7, 2023

Haha, if you are telling me to ignore the failing tests, then ignore the failing tests I will 🤣

In that case, the fix for emacs mode seems relatively straightforward. Thanks for pointing me to _extra_prompt_options. All lines now update regardless of editing mode.

@cohml
Copy link
Author

cohml commented Dec 16, 2023

Paging @Carreau - Let me know if there's any additional work you'd like me to put into this, versus if you think it's good enough to merge as is, in light of your "don't worry about the failures" comment. I'd love to finally get some line numbers into my iPython shell!

@Carreau Carreau changed the title [WIP] Feature/add line numbers to prompt Feature/add line numbers to prompt Dec 17, 2023
@Carreau
Copy link
Member

Carreau commented Dec 17, 2023

Thanks for your patience, I pushed a commit that just reformat a bit to please the linter and will merge a bit later once the PyPy test are passing. It should be in the next release.

@Carreau Carreau added this to the 8.19 milestone Dec 17, 2023
@Carreau Carreau merged commit b5bf8f1 into ipython:main Dec 17, 2023
19 of 20 checks passed
@cohml
Copy link
Author

cohml commented Dec 17, 2023

Glorious! IPython just got even better if that was even possible 😄

Thanks for the help and pleasure doing business with you!

@cohml cohml deleted the feature/add-line-numbers-to-prompt branch December 18, 2023 18:01
@tornaria
Copy link

This PR breaks backward compatibility for prompts other than the one you just patched. In particular, it completely breaks sagemath.

Example 1:

Just run ipython --classic and see it for yourself (just type while True:<ENTER>)

This is because you patched the base class but not the ClassicPrompts subclass which changes continuation_prompt_tokens().

However, patching ClassicPrompts is not enough, because you will break all custom prompts, which is a public documented way to change the prompt (see https://ipython.readthedocs.io/en/stable/config/details.html#custom-prompts)

Example2:

Since sagemath uses custom prompts, it's completely broken. Just run sage and type while True:<ENTER> as above.

According to https://ipython.readthedocs.io/en/stable/config/details.html#custom-prompts you should not call continuation_prompt_tokens() with anything other than the documented interface:

continuation_prompt_tokens(self, cli=None, width=None)

Maybe you can add a flag in the prompt class meaning that continuation_prompt_tokens() accepts the line argument, and only pass it if the flag is present. Also, please document the new behaviour in https://github.com/ipython/ipython/blob/main/docs/source/config/details.rst.

For the time being, it would be nice if this is reverted until it's fixed, and 8.19.1 is released with this revert.

@Carreau @cohml

@krassowski
Copy link
Member

krassowski commented Dec 26, 2023

Maybe you can add a flag in the prompt class meaning continuation_prompt_tokens() accepts the line argument

This could probably be determined by using inspect module.

@Carreau
Copy link
Member

Carreau commented Dec 27, 2023

Yeah, I'll see if I can make it work with inspect, or using something like https://pypi.org/project/backcall/. PR welcome though, and sorry for the breakage.

@cohml
Copy link
Author

cohml commented Dec 27, 2023

sorry for the breakage

Ditto, apologies for the trouble, all.

At first I had attempted to keep my changes backwards compatible using inspect.signature - I was also using the classic prompt before introducing this change. But early comments from a core dev on the issue that spawned this PR suggested that backwards compatibility wasn't required for this, so I just decided to "KISS".

Perhaps in retrospect that was the wrong decision!

@Carreau
Copy link
Member

Carreau commented Dec 27, 2023

Yeah, I though that was unnecessary as I couldn't' find project using it.

I have the fix locally (I also realized some of our docs were wrong since the method also changed in 2017 when prompt toolkit was updated to 2.0,

I'll try to get that in soonish, but I'm travelling and on holidays, so it might take some time to actually be published.

@tornaria
Copy link

At first I had attempted to keep my changes backwards compatible using inspect.signature - I was also using the classic prompt before introducing this change. But early comments from a core dev on the issue that spawned this PR suggested that backwards compatibility wasn't required for this, so I just decided to "KISS".

In the comment by @Carreau it clealy suggests some code and explains: "...that will check that lineno is a parameter and if not don't pass it to not break backward compatibility."

How do you read "backwards compatibility wasn't required for this" from that?

Perhaps in retrospect that was the wrong decision!

As a learning experience, if you had taken the trouble to document your changes, maybe you would have realized this was part of a public api, and try to figure out what's a good way to move the api forward without breaking existing users of the api. In any case, changing an api without changing the documentation is not very friendly.

The net result of this is reinforcing sagemath stupid habit of setting upper bounds on package versions (see: sagemath/sage#36975 (comment)).

IMHO the best way to get out of this mess would be to revert this PR and release 8.19.1 asap. Then figure out a new api for continuation_prompt_tokens(...) that is more robust and forward extensible (and documented!) and implement a way to maintain backwards compatibility with old api for a while. A deprecation warning on the old api is fine, sagemath has 3-4 releases a year and we can easily move to the new api.

Why not just add **kwargs to the interface? This would be as extensible as it gets... Then you can pass lineno in there and other prompts can just ignore it. Moving to the new api is just adding **kwargs to the argument list of prompts.

Maybe changing the name of the method for the new api is easier than using inspect? The base class could have a default implementation that falls back to the previous api. Then the way to signal your prompt class implements the new api is to implement the new method (overriding the base class default one).

@Carreau
Copy link
Member

Carreau commented Dec 27, 2023

In the same thread I said later:

I don't have problem breaking compatibility and always passing lineno ( and softwrap while we are at it). I doubt there are any prompt customisation.

So this is my fault for doubting there was anybody using custom prompt and not doing complete testing. I also merged the PRs after reviews, and I saw that this was backward incompatible, so it's on me, not on @cohml

#14274 will fix it, no need to revert, and yes it would be great to ask users to take **kwargs, but printing a warning would be way to annoying for users.

In general I'm also worried about variability of what is passed when.

Also please don't add upperbound, just add a ipython=...,=!8.19.0 to just exclude this version. I'll also appreciate if you could test nightly on CI, there should be nightly wheels

I'll do a 8.19.1 when I can.

@tornaria
Copy link

Yeah, I though that was unnecessary as I couldn't' find project using it.

Keep in mind sagemath is a big user of ipython since the beginning. In fact I believe ipython + cython (then called pyrex) were the two main reasons @williamstein chose python for SAGE back in 2004/2005.

I have the fix locally (I also realized some of our docs were wrong since the method also changed in 2017 when prompt toolkit was updated to 2.0,

If you mean removing the cli=None argument, that's not completely backwards incompatible since it has a default. You can see in https://github.com/sagemath/sage/blob/develop/src/sage/repl/prompts.py that sagemath dutifully implements the api just as documented in https://github.com/ipython/ipython/blob/main/docs/source/config/details.rst.

I can make a PR to move forward sagemath to the new api once is well defined and documented, but it'd be nice if the old api is supported for some time (say, 6 months should be ok).

@Carreau
Copy link
Member

Carreau commented Dec 27, 2023

If you mean removing the cli=None argument, that's not completely backwards incompatible since it has a default

Well, no not really, as we call the method since 2017 with width as the first positional argument so technically Sage is receiving the equivalent of ...(cli=width).

It just happens to not use the parameters.

I have no issue having a long-term inspect that only passes the arguments defined in the underlying callback signature as long as it is documented why. I tend to dislike doing it for no reasons.

@tornaria
Copy link

If you mean removing the cli=None argument, that's not completely backwards incompatible since it has a default

Well, no not really, as we call the method since 2017 with width as the first positional argument so technically Sage is receiving the equivalent of ...(cli=width).

It just happens to not use the parameters.

Uh... I see..

I have no issue having a long-term inspect that only passes the arguments defined in the underlying callback signature as long as it is documented why. I tend to dislike doing it for no reasons.

Why not copy the prompt_toolkit api, i.e. have a method prompt_continuation(width, line_number, wrap_count) which is passed just like that, with a default implementation that falls back to the old continuation_prompt_tokens(...) ?

@williamstein
Copy link

williamstein commented Dec 27, 2023

Confirmed, plus the python language itself had the biggest overlap with Magma’s language.

@Carreau
Copy link
Member

Carreau commented Dec 27, 2023

Let's stay on task for now, fix the breaking backward compatibility and make a release quickly. I probably won't do a release before Sunday as I am on a connection that is barely enough to browse.

After we can talk about improving things if we wish.

If possible let's talk in #14273 that tracks this regression, and please review #14274

@tornaria
Copy link

Let's stay on task for now, fix the breaking backward compatibility and make a release quickly. I probably won't do a release before Sunday as I am on a connection that is barely enough to browse.

I've already patched our package for 8.19.0 in void linux, so not a big hurry on our side.

I'll try to have sagemath not ban >=8.19 but only 8.19.0.

After we can talk about improving things if we wish.

Sure, again if you let me know about the new api I can make a PR for sagemath to adapt.

If possible let's talk in #14273 that tracks this regression, and please review #14274

Done.

Thanks for the prompt handling of the issue.

@Carreau
Copy link
Member

Carreau commented Jan 8, 2024

I just did a release the should fix the issue and yanked 8.19.

Carreau added a commit that referenced this pull request Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants