bpo-13631: Fix the order of initialization for readline libedit on macOS. (GH-6915) (GH-6928)

The editline emulation needs to be initialized *after* the name is
defined. This fixes the long open issue.
(cherry picked from commit c2f082e9d1)

Co-authored-by: Zvezdan Petkovic <zpetkovic@acm.org>
This commit is contained in:
Miss Islington (bot) 2018-05-17 00:27:33 -07:00 committed by Ned Deily
parent 9c17cd3214
commit d504108a88
5 changed files with 23 additions and 8 deletions

View file

@ -17,11 +17,18 @@ made using this module affect the behaviour of both the interpreter's
interactive prompt and the prompts offered by the built-in :func:`input` interactive prompt and the prompts offered by the built-in :func:`input`
function. function.
Readline keybindings may be configured via an initialization file, typically
``.inputrc`` in your home directory. See `Readline Init File
<https://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html#SEC9>`_
in the GNU Readline manual for information about the format and
allowable constructs of that file, and the capabilities of the
Readline library in general.
.. note:: .. note::
The underlying Readline library API may be implemented by The underlying Readline library API may be implemented by
the ``libedit`` library instead of GNU readline. the ``libedit`` library instead of GNU readline.
On MacOS X the :mod:`readline` module detects which library is being used On macOS the :mod:`readline` module detects which library is being used
at run time. at run time.
The configuration file for ``libedit`` is different from that The configuration file for ``libedit`` is different from that
@ -29,12 +36,13 @@ function.
you can check for the text "libedit" in :const:`readline.__doc__` you can check for the text "libedit" in :const:`readline.__doc__`
to differentiate between GNU readline and libedit. to differentiate between GNU readline and libedit.
Readline keybindings may be configured via an initialization file, typically If you use *editline*/``libedit`` readline emulation on macOS, the
``.inputrc`` in your home directory. See `Readline Init File initialization file located in your home directory is named
<https://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html#SEC9>`_ ``.editrc``. For example, the following content in ``~/.editrc`` will
in the GNU Readline manual for information about the format and turn ON *vi* keybindings and TAB completion::
allowable constructs of that file, and the capabilities of the
Readline library in general. python:bind -v
python:bind ^I rl_complete
Init file Init file

View file

@ -187,6 +187,8 @@ library/profile,,:lineno,filename:lineno(function)
library/pyexpat,,:elem1,<py:elem1 /> library/pyexpat,,:elem1,<py:elem1 />
library/pyexpat,,:py,"xmlns:py = ""http://www.python.org/ns/"">" library/pyexpat,,:py,"xmlns:py = ""http://www.python.org/ns/"">"
library/random,,:len,new_diff = mean(combined[:len(drug)]) - mean(combined[len(drug):]) library/random,,:len,new_diff = mean(combined[:len(drug)]) - mean(combined[len(drug):])
library/readline,,:bind,"python:bind -v"
library/readline,,:bind,"python:bind ^I rl_complete"
library/smtplib,,:port,method must support that as well as a regular host:port library/smtplib,,:port,method must support that as well as a regular host:port
library/socket,,::,'5aef:2b::8' library/socket,,::,'5aef:2b::8'
library/socket,,:can,"return (can_id, can_dlc, data[:can_dlc])" library/socket,,:can,"return (can_id, can_dlc, data[:can_dlc])"

1 c-api/arg :ref PyArg_ParseTuple(args, "O|O:ref", &object, &callback)
187 library/pyexpat :elem1 <py:elem1 />
188 library/pyexpat :py xmlns:py = "http://www.python.org/ns/">
189 library/random :len new_diff = mean(combined[:len(drug)]) - mean(combined[len(drug):])
190 library/readline :bind python:bind -v
191 library/readline :bind python:bind ^I rl_complete
192 library/smtplib :port method must support that as well as a regular host:port
193 library/socket :: '5aef:2b::8'
194 library/socket :can return (can_id, can_dlc, data[:can_dlc])

View file

@ -1225,6 +1225,7 @@ Gabriel de Perthuis
Tim Peters Tim Peters
Benjamin Peterson Benjamin Peterson
Joe Peterson Joe Peterson
Zvezdan Petkovic
Ulrich Petri Ulrich Petri
Chris Petrilli Chris Petrilli
Roumen Petrov Roumen Petrov

View file

@ -0,0 +1,2 @@
The .editrc file in user's home directory is now processed correctly during
the readline initialization through editline emulation on macOS.

View file

@ -1078,6 +1078,9 @@ setup_readline(readlinestate *mod_state)
Py_FatalError("not enough memory to save locale"); Py_FatalError("not enough memory to save locale");
#endif #endif
/* The name must be defined before initialization */
rl_readline_name = "python";
#ifdef __APPLE__ #ifdef __APPLE__
/* the libedit readline emulation resets key bindings etc /* the libedit readline emulation resets key bindings etc
* when calling rl_initialize. So call it upfront * when calling rl_initialize. So call it upfront
@ -1099,7 +1102,6 @@ setup_readline(readlinestate *mod_state)
using_history(); using_history();
rl_readline_name = "python";
/* Force rebind of TAB to insert-tab */ /* Force rebind of TAB to insert-tab */
rl_bind_key('\t', rl_insert); rl_bind_key('\t', rl_insert);
/* Bind both ESC-TAB and ESC-ESC to the completion function */ /* Bind both ESC-TAB and ESC-ESC to the completion function */