-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
gh-112105: Make completer delims work on libedit #112106
Conversation
Hi @corona10 , I just realized you have spent sometime on libedit when I was reviewing the history of the file. Could you share your thoughts of the PR? Thanks! |
@gaogaotiantian I will take a look at this PR in this weekend :) |
@gaogaotiantian Sorry for the delay, I will take a look at in 2-3 days. |
No worries! |
@@ -576,6 +576,7 @@ readline_set_completer_delims(PyObject *module, PyObject *string) | |||
if (break_chars) { | |||
free(completer_word_break_characters); | |||
completer_word_break_characters = break_chars; | |||
rl_basic_word_break_characters = break_chars; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so it's kinds of implementation detail.
Since we enable the flag for libedit in following way.
Line 5916 in 2e632fa
AH_TEMPLATE([WITH_EDITLINE], [Define to build the readline module against libedit.]) |
What about changing the code for the libedit implementation only?
rl_basic_word_break_characters = break_chars; | |
#ifdef WITH_EDITLINE | |
// Comment why this is needed | |
rl_basic_word_break_characters = break_chars; | |
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the comments in the file:
* This emulation library is not 100% API compatible with the "real" readline
* and cannot be detected at compile-time,
* hence we use a runtime check to detect if the Python readline module is
* linked to libedit.
It seems like we are not able to detect if libedit
is used at compile time. I doubt if the macro protection would actually work in all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do our official binaries build with libedit ever?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we are not able to detect if libedit is used at compile time
I am not sure when the comment was added.
But we can detect editline at build-time from Python 3.10
https://docs.python.org/3/using/configure.html?highlight=with_editline#cmdoption-with-readline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do our official binaries build with libedit ever?
Even if our official build does not use it, we should consider downstream distros :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's actually not what I meant. What I meant is - we could have been using libedit
without WITH_EDITLINE
. So even if we do not define WITH_EDITLINE
, we could still be using libedit
. I just confirmed on my mac that this change will break the test.
The reason I quoted that comment was that I believed such case exists - where we don't know if libedit
is being used at compile time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could have been using libedit without WITH_EDITLINE.
From what I can observe, writing to both variables has no unexpected side effect, because rl_basic_word_break_characters is not used on CPython with GNU deadline.
Got it, then should we consider using both using_libedit_emulation
and WITH_EDITLINE
?
If you think that we don't have to consider side effect from the implementation detail, then we can just add a comment why we do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked that following suggestion pass the test on my macOS.
rl_basic_word_break_characters = break_chars; | |
#ifdef WITH_EDITLINE | |
rl_basic_word_break_characters = break_chars; | |
#else | |
if (using_libedit_emulation) rl_basic_word_break_characters = break_chars; | |
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I did not use your suggestion directly. I do like the brackets for the if statement. I applied the protection to avoid side effects for GNU readline on both cases.
@@ -1267,6 +1268,7 @@ setup_readline(readlinestate *mod_state) | |||
completer_word_break_characters = | |||
strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?"); | |||
/* All nonalphanums except '.' */ | |||
rl_basic_word_break_characters = completer_word_break_characters; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!!
Thanks for the work @gaogaotiantian
Thanks @gaogaotiantian for the PR, and @corona10 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
(cherry picked from commit 2df26d8) Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
GH-112487 is a backport of this pull request to the 3.12 branch. |
(cherry picked from commit 2df26d8) Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
GH-112488 is a backport of this pull request to the 3.11 branch. |
readline.set_completer_delims
has no effect with libedit #112105