-
-
Notifications
You must be signed in to change notification settings - Fork 611
fix: repl tab completion #3114
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
base: main
Are you sure you want to change the base?
fix: repl tab completion #3114
Conversation
I think #3104 needs to merged into this so that the |
6ee1b0f
to
e3dbb91
Compare
e3dbb91
to
991fbab
Compare
I believe I've gotten that merge done. I'm surprised by the CI failures. They make it look like the merge wasn't successful, but the content of the commit the tests used looks correct to me. |
I noticed that the CI error messages for bazel-contrib#3114 are not useful. This patch aims to help with that by printing the output of the REPL code. If there's an exception during startup for example, then the test log will now contain the stack trace.
I noticed that the CI error messages for #3114 are not useful. This patch aims to help with that by printing the output of the REPL code. If there's an exception during startup for example, then the test log will now contain the stack trace. --------- Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
I'm seeing more clear error messages now. It seems the |
The readline module is not avialable on all platforms.
python/bin/repl_stub.py
Outdated
if "readline" in globals(): | ||
# Set up tab completion. | ||
completer = DynamicCompleter(console_locals) | ||
readline.set_completer(completer.complete) | ||
|
||
# TODO(jpwoodbu): Use readline.backend instead of readline.__doc__ once we can depend on having | ||
# Python >=3.13. | ||
if "libedit" in readline.__doc__: # type: ignore | ||
readline.parse_and_bind("bind ^I rl_complete") | ||
elif "GNU readline" in readline.__doc__: # type: ignore | ||
readline.parse_and_bind("tab: complete") | ||
else: | ||
print("Could not enable tab completion!") | ||
|
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.
Could you print Could not enable tab completion
on windows as well?
Maybe structuring the code like:
try
import readline
import rlcompleter
class DynamicCompleter
...
completer = DynamicCompleter(console_locals)
readline.set_completer(completer.complete)
if ...
else:
print(...)
except ImportError:
print(...)
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.
Done. It's a lot of code inside a try block. Do you have any concerns about maintainability?
This adds tab completion to the default stub when using the REPL feature.