Commit Graph

48 Commits

Author SHA1 Message Date
Miss Islington (bot) 148beb6de9
[3.13] gh-121957: Emit audit events for `python -i` and `python -m asyncio` (GH-121958) (GH-122115)
Relatedly, emit the `cpython.run_startup` event from the Python version of
`PYTHONSTARTUP` handling.
(cherry picked from commit dc93d1125f)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-07-22 13:36:57 +02:00
Miss Islington (bot) 3d9692dbf8
[3.13] gh-120678: pyrepl: Include globals from modules passed with `-i` (GH-120904) (#121916)
(cherry picked from commit ac07451116)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-07-17 16:52:46 +02:00
Miss Islington (bot) 4a62fdf35d
[3.13] gh-121295: Fix blocked console after interrupting a long paste (GH-121815) (GH-121826)
(cherry picked from commit 498a94c198)

Co-authored-by: Marta Gómez Macías <mgmacias@google.com>
2024-07-16 08:29:04 +02:00
Miss Islington (bot) 73f77e642a
[3.13] gh-121610: pyrepl - handle extending blocks when multi-statement blocks are pasted (GH-121757) (GH-121825)
console.compile with the "single" param throws an exception when
there are multiple statements, never allowing to adding newlines
to a pasted code block (gh-121610)

This adds a few extra checks to allow extending when in an indented
block, and tests for a few examples.

(cherry picked from commit 7d111dac16)

Co-authored-by: saucoide <32314353+saucoide@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-07-16 08:28:41 +02:00
Miss Islington (bot) 5b718e7fc7
[3.13] gh-121790: Fix interactive console initialization (GH-121793) (GH-121822)
(cherry picked from commit e5c7216f37)

Co-authored-by: Milan Oberkirch <milan.oberkirch@geops.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-07-16 00:49:41 +02:00
Miss Islington (bot) b506de4eb5
[3.13] gh-121245: Refactor site.register_readline() (GH-121659) (GH-121816)
(cherry picked from commit 05d413764c)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-07-15 22:49:18 +02:00
Miss Islington (bot) 308857b82a
[3.13] gh-121746: Bind Alt+Enter to "accept" in the REPL (GH-121754) (GH-121803)
(cherry picked from commit 6522f0e438)

Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
2024-07-15 20:14:50 +02:00
Miss Islington (bot) e28f863bd5
[3.13] gh-121609: Fix pasting of characters containing unicode character joiner (GH-121667) (#121733)
Co-authored-by: Marta Gómez Macías <mgmacias@google.com>
2024-07-14 03:02:46 -06:00
Miss Islington (bot) 62572f10aa
[3.13] gh-121497: Make Pyrepl respect correctly the history with input hook set (GH-121498) (#121703)
gh-121497: Make Pyrepl respect correctly the history with input hook set (GH-121498)
(cherry picked from commit 4e36dd7d87)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2024-07-13 14:28:49 +00:00
Miss Islington (bot) de51ee0c23
[3.13] gh-121499: Fix multi-line history rendering in the REPL (GH-121531) (#121679)
gh-121499: Fix multi-line history rendering in the REPL (GH-121531)
(cherry picked from commit 4b9e10d0ea)

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2024-07-13 15:56:56 +02:00
Miss Islington (bot) 38cfa92880
[3.13] gh-118908: Use __main__ for the default PyREPL namespace (GH-121054) (#121059) 2024-06-26 19:25:38 +00:00
Miss Islington (bot) 51724620e8
[3.13] gh-120417: Remove unused imports in the stdlib (GH-120420) (#120429)
gh-120417: Remove unused imports in the stdlib (GH-120420)
(cherry picked from commit 4c6d4f5cb3)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-06-12 19:27:32 +00:00
Miss Islington (bot) 10821ccf06
[3.13] gh-118908: Fix completions after namespace change in REPL (GH-120370) (#120392)
(cherry picked from commit 02e74c3562)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2024-06-12 08:48:22 +00:00
Miss Islington (bot) 7aafa305d4
[3.13] gh-120221: Deliver real singals on Ctrl-C and Ctrl-Z in the new REPL (GH-120354) (#120368) 2024-06-11 19:46:07 +00:00
Miss Islington (bot) f5289c450a
[3.13] gh-118908: Limit exposed globals from internal imports and definitions on new REPL startup (GH-119547) (#120362) 2024-06-11 18:04:39 +00:00
Miss Islington (bot) 4936575017
[3.13] gh-119517: Fixes for pasting in pyrepl (GH-120253) (#120353)
gh-119517: Fixes for pasting in pyrepl (GH-120253)

* Remove pyrepl's optimization for self-insert

This will be replaced by a less specialized optimization.

* Use line-buffering when pyrepl echoes pastes

Previously echoing was totally suppressed until the entire command had
been pasted and the terminal ended paste mode, but this gives the user
no feedback to indicate that an operation is in progress. Drawing
something to the screen once per line strikes a balance between
perceived responsiveness and performance.

* Remove dead code from pyrepl

`msg_at_bottom` is always true.

* Speed up pyrepl's screen rendering computation

The Reader in pyrepl doesn't hold a complete representation of the
screen area being drawn as persistent state. Instead, it recomputes it,
on each keypress. This is fast enough for a few hundred bytes, but
incredibly slow as the input buffer grows into the kilobytes (likely
because of pasting).

Rather than making some expensive and expansive changes to the repl's
internal representation of the screen, add some caching: remember some
data from one refresh to the next about what was drawn to the screen
and, if we don't find anything that has invalidated the results that
were computed last time around, reuse them. To keep this caching as
simple as possible, all we'll do is look for lines in the buffer that
were above the cursor the last time we were asked to update the screen,
and that are still above the cursor now. We assume that nothing can
affect a line that comes before both the old and new cursor location
without us being informed. Based on this assumption, we can reuse old
lines, which drastically speeds up the overwhelmingly common case where
the user is typing near the end of the buffer.

* Speed up pyrepl prompt drawing

Cache the `can_colorize()` call rather than repeatedly recomputing it.
This call looks up an environment variable, and is called once per
character typed at the REPL. The environment variable lookup shows up as
a hot spot when profiling, and we don't expect this to change while the
REPL is running.

* Speed up pasting multiple lines into the REPL

Previously, we were checking whether the command should be accepted each
time a line break was encountered, but that's not the expected behavior.
In bracketed paste mode, we expect everything pasted to be part of
a single block of code, and encountering a newline shouldn't behave like
a user pressing <Enter> to execute a command. The user should always
have a chance to review the pasted command before running it.

* Use a read buffer for input in pyrepl

Previously we were reading one byte at a time, which causes much slower
IO than necessary. Instead, read in chunks, processing previously read
data before asking for more.

* Optimize finding width of a single character

`wlen` finds the width of a multi-character string by adding up the
width of each character, and then subtracting the width of any escape
sequences. It's often called for single character strings, however,
which can't possibly contain escape sequences. Optimize for that case.

* Optimize disp_str for ASCII characters

Since every ASCII character is known to display as single width, we can
avoid not only the Unicode data lookup in `disp_str` but also the one
hidden in `str_width` for them.

* Speed up cursor movements in long pyrepl commands

When the current pyrepl command buffer contains many lines, scrolling up
becomes slow. We have optimizations in place to reuse lines above the
cursor position from one refresh to the next, but don't currently try to
reuse lines below the cursor position in the same way, so we wind up
with quadratic behavior where all lines of the buffer below the cursor
are recomputed each time the cursor moves up another line.

Optimize this by only computing one screen's worth of lines beyond the
cursor position. Any lines beyond that can't possibly be shown by the
console, and bounding this makes scrolling up have linear time
complexity instead.

---------

(cherry picked from commit 32a0faba43)

Signed-off-by: Matt Wozniski <mwozniski@bloomberg.net>
Co-authored-by: Matt Wozniski <mwozniski@bloomberg.net>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2024-06-11 17:09:28 +00:00
Miss Islington (bot) 4ac0ccf9d3
[3.13] gh-119553: Fix console when pressing Ctrl-C within a multiline block (GH-120075) (#120076)
(cherry picked from commit 69b3e8ea56)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2024-06-04 21:44:33 +00:00
Łukasz Langa eea45ea213
[3.13] gh-119842: Honor PyOS_InputHook in the new REPL (GH-119843) (GH-120066)
(cherry picked from commit d9095194dd)

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Michael Droettboom <mdboom@gmail.com>
2024-06-04 21:26:10 +02:00
Miss Islington (bot) 93b95e91fa
[3.13] gh-119553: Clear reader on Ctrl-C command (GH-119801) (#120062)
(cherry picked from commit 010ea93b2b)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-06-04 18:45:22 +00:00
Miss Islington (bot) 8d74eae4d4
[3.13] gh-120041: Do not use append_to_screen when completions are visible (GH-120042) (#120051)
* gh-120041: Do not use append_to_screen when completions are visible (GH-120042)
(cherry picked from commit 8fc7653766)

* gh-120041: Refactor check for visible completion menu in completing_reader (GH-120055)
(cherry picked from commit bf8e5e53d0)
---------

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2024-06-04 18:10:29 +00:00
Miss Islington (bot) 6b10467fbc
[3.13] gh-118835: pyrepl: Fix prompt length computation for custom prompts containing ANSI escape codes (GH-119942) (#119990)
gh-118835: pyrepl: Fix prompt length computation for custom prompts containing ANSI escape codes (GH-119942)
(cherry picked from commit 2e0aa731ae)

Co-authored-by: Daniel Hollas <daniel.hollas@bristol.ac.uk>
2024-06-03 17:31:26 +00:00
Miss Islington (bot) a5272e63ef
[3.13] gh-118894: Make asyncio REPL use pyrepl (GH-119433) (#119884)
(cherry picked from commit 2237946af0)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-31 17:15:44 -04:00
Miss Islington (bot) d6faac6d1f
[3.13] gh-111201: Support pyrepl on Windows (GH-119559) (GH-119850)
(cherry picked from commit 0d07182821)

Co-authored-by: Dino Viehland <dinoviehland@gmail.com>
Co-authored-by: Anthony Shaw <anthony.p.shaw@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-31 17:18:28 +02:00
Miss Islington (bot) 38bf39cb4b
[3.13] gh-111201: Improve pyrepl auto indentation (GH-119606) (GH-119833)
- auto-indent when editing multi-line block
- ignore comments

(cherry picked from commit dae0375bd9)

Co-authored-by: Arnon Yaari <wiggin15@yahoo.com>
2024-05-31 11:51:53 +02:00
Miss Islington (bot) 8470593a98
[3.13] gh-119548: Add a 'clear' command to the REPL (GH-119549) (#119552)
gh-119548: Add a 'clear' command to the REPL (GH-119549)
(cherry picked from commit e3bac04c37)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2024-05-31 08:35:21 +00:00
Miss Islington (bot) 40a024c983
[3.13] gh-119555: catch SyntaxError from compile() in the InteractiveColoredConsole (GH-119557) (#119709) 2024-05-29 12:04:45 +01:00
Miss Islington (bot) 17d3398486
[3.13] gh-119443: Turn off from __future__ import annotations in REPL (GH-119493) (#119697)
gh-119443: Turn off from __future__ import annotations in REPL (GH-119493)
(cherry picked from commit a8e35e8eba)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-05-29 01:26:19 +00:00
Miss Islington (bot) 58dbb4a4b0
[3.13] gh-111201: Speed up paste mode in the REPL (#119341) (GH-119432) (#119439)
(cherry picked from commit e6572e8f98)

Also includes:

* gh-111201: Use calc_complete_screen after bracketed paste in PyREPL (GH-119432)
(cherry picked from commit 14b063cbf1)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2024-05-23 04:23:40 +00:00
Lysandros Nikolaou 9fa1b4fc46
[3.13] gh-118911: Trailing whitespace in a block shouldn't prevent the user from terminating the code block (GH-119355) (#119404)
(cherry picked from commit 5091c4400c)

Co-authored-by: Aya Elsayed <ayah.ehab11@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-23 00:12:26 -04:00
Miss Islington (bot) dbff1f1077
[3.13] gh-119434: Fix culmitive errors in wrapping as lines proceed (GH-119435) (#119441)
Fix culmitive errors in wrapping as lines proceed
(cherry picked from commit e3bf5381fd)

Co-authored-by: Dino Viehland <dinoviehland@gmail.com>
2024-05-22 23:46:11 -04:00
Lysandros Nikolaou 9435124d4a
[3.13] gh-111201: auto-indentation in _pyrepl (GH-119348) (#119427)
(cherry picked from commit cd516cd1f5)

Co-authored-by: Arnon Yaari <wiggin15@yahoo.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-22 23:14:03 +02:00
Miss Islington (bot) 81440c5ba1
[3.13] Enable some stricter mypy settings on `Lib/_pyrepl` (GH-119077) (#119428)
(cherry picked from commit 0883fd22e6)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-05-22 23:13:47 +02:00
Lysandros Nikolaou e6e4efcc86
[3.13] gh-119357: Increase test coverage for keymap in _pyrepl (GH-119358) (#119414)
(cherry picked from commit 73ab83b27f)

Co-authored-by: Eugene Triguba <eugenetriguba@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-22 23:13:01 +02:00
Miss Islington (bot) cd39da75af
[3.13] Improve `pyrepl` type-annotation coverage (GH-119081) (#119415)
(cherry picked from commit 033f5c87f1)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-05-22 18:38:32 +00:00
Miss Islington (bot) a463cd8e45
[3.13] gh-118893: Evaluate all statements in the new REPL separately (GH-119318) (#119408)
(cherry picked from commit a3e4fec873)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-22 16:22:01 +00:00
Miss Islington (bot) eafd633fac
[3.13] gh-119205: Fix autocompletion bug in new repl (GH-119229) (#119407)
(cherry picked from commit 506b1a3ff6)

Co-authored-by: Koudai Aono <koxudaxi@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-22 16:07:38 +00:00
Miss Islington (bot) aefe2e626e
[3.13] gh-111201: Add append to screen method to avoid recalculation (GH-119274) (#119405)
(cherry picked from commit c886bece3b)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-22 16:03:04 +00:00
Lysandros Nikolaou ac9163637b
[3.13] gh-111201: Remove readline dependency from the PyREPL (GH-119262) (#119403)
(cherry picked from commit 561ff1fa71)
2024-05-22 11:45:11 -04:00
Miss Islington (bot) e992217810
[3.13] gh-118877: Fix AssertionError crash in pyrepl (GH-118936) (#119363)
(cherry picked from commit c0d81b2566)

Co-authored-by: Daniel Hollas <daniel.hollas@bristol.ac.uk>
2024-05-22 01:28:24 +00:00
Miss Islington (bot) 8860f83e4b
[3.13] gh-119035: Add Ctrl+← and Ctrl+→ word-skipping keybindings to new repl (GH-119248) (#119323)
add word-skipping ctrl keybindings to new repl
(cherry picked from commit 0398d93392)

Co-authored-by: Alastair Stanley <alastairstanley@ntlworld.com>
2024-05-21 17:16:06 -04:00
Miss Islington (bot) a52ed7e6d9
[3.13] gh-119185: Fix typo in `_pyrepl.pager`: `tempfilepager` should be `tempfile_pager` (GH-118881) (#119211)
Fix typo in `_pyrepl.pager`: `tempfilepager` should be `tempfile_pager`

The name with no underscore doesn't exist.
(cherry picked from commit 05e1dce76d)

Co-authored-by: Thanos <111999343+Sachaa-Thanasius@users.noreply.github.com>
2024-05-20 15:10:40 +00:00
Pablo Galindo Salgado a94ac56628
gh-111201: Allow pasted code to contain multiple statements in the REPL (#118712)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-07 16:01:49 +00:00
Lysandros Nikolaou e5413ec783
gh-118682: Revert forcing str commands, allow class commands in pyrepl (#118709) 2024-05-07 14:31:56 +00:00
Pablo Galindo Salgado 7d90b8aadb
gh-111201: Allow bracketed paste to work (GH-118700) 2024-05-07 12:54:56 +00:00
Nikita Sobolev ad3d877a12
Remove several unused imports in `_pyrepl` (#118668) 2024-05-07 13:43:18 +01:00
denballakh 040571f258
fix typo in `_pyrepl.pager`: `plainpager` -> `plain_pager` (#118675) 2024-05-06 22:56:28 +00:00
Łukasz Langa 9bf00322ba
gh-118628: Don't display pyrepl warning on Windows (#118665) 2024-05-06 19:35:22 +00:00
Pablo Galindo Salgado f27f8c790a
gh-111201: A new Python REPL (GH-111567)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Marta Gómez Macías <mgmacias@google.com>
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-05-05 21:32:23 +02:00