-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
cmd module tab misbehavior #53279
Comments
noticed that cmd module does not perform completion using TAB on a macintosh properly. instead, the TAB key just places several blank spaces and moves the cursor forward. what it should do is retrieve a list of possibilities for completing a command. |
Thanks for your report. Does the readline module work at all? 2.5 is unsupported now; can you test your code with 2.7, the next stable version? |
It seems readline module is not installed on your system. By default, if you do not specify an --with-universal-archs other than "32-bit" to configure or if you do not explicitly set MACOSX_DEPLOYMENT_TARGET to another value, configure defaults to using "10.4" (or earlier) so the building of the readline module is skipped. You can check this: >>> from distutils.sysconfig import get_config_var
>>> get_config_var('MACOSX_DEPLOYMENT_TARGET')
'10.4' (Whether this is the best default is another question.) As it stands, to be able to build the readline module, either: (1) supply the GNU readline library as a local library, or (2) ensure you are building with a deployment target of at least 10.5. For example:
Also note that option (2) is not available for 3.1.x since the changes to support editline/libedit were not ported to it; they are, however, in 2.6.5, 2.7 (trunk), and 3.2 (py3k)" |
scott:
|
Reaction from scot w.r.t. my questions: os x 10.5.8 python 2.5.1 /System/Library/Frameworks/Python.framework/Versions/2.5 came default with system i'm going to try activestate python 2.6 and see if that solves the problem. import readline does work |
Some notes: The system python on OSX 10.5 and 10.6 is linked to libedit, not GNU readline, and doesn't seem to contain patches that convert stdlib usage of readline APIs to the correct way to bind keystrokes to action with libedit. This results in failure to use libedit at all. AFAIK this also affects the generic stdlib when linking libedit, which is supported in 2.6.5, 2.7 and 3.2. Therefore adding more versions. |
This (untested) patch should fix the issue for the cmd module: +++ Lib/cmd.py (working copy)
@@ -112,7 +112,18 @@
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
- readline.parse_and_bind(self.completekey+": complete")
+
+ if 'libedit' in readline.__doc__:
+ # readline linked to BSD libedit
+ if self.completekey == 'tab':
+ key = '^I'
+ else:
+ key = self.completekey
+ readline.parse_and_bind("bind %s rl_complete"%(key,))
+
+ else:
+ # readline linked to the real readline
+ readline.parse_and_bind(self.completekey+": complete")
except ImportError:
pass
try: |
Tested the patch and it works for trunk and python3.2 alpha. Python build finished, but the necessary bits to build these modules were not found: However for cmd module, tab completion and history(up|down arrow) worked fine. |
The attached patch is a workaround for the issue, but isn't someone I'd want to commit without some serious cleanup. As I noted when support for linking with libedit was merged it would be better to add a translation layer that translates GNU readline configuration lines to BSD libedit ones. |
Does a translation really need to be in Python? I use .editrc file in my home directory with this content: python:bind ^I rl_complete and everything works fine. |
We either have to add some translation, or tweak parts of python:
And that's just the stdlib. IIRC ipython contains code that uses libedit IMHO the current behavior is confusing: the module is named readline, but sometimes uses libedit behavior. At least I ensured that the usage of libedit can be detected by introspecting readline.__doc__. A basic translator shouldn't be that hard... |
I no longer particularly like my patch, although something needs to be done. The easiest way forward is likely a (private) helper function in the readline module that can translate simple readline configuration strings to something that libedit understands and use that in the stdlib where readline bindings are replaced (but of course not for reading ~/.inputrc). Comparing the libedit <http://linux.die.net/man/5/editrc\> and readline <http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC9\> configuration languages makes is clear that it is not possible to fully translate a readline configuration in a libedit one, but basic conifguration like setting up key-bindings should be easy enough. |
I can confirm this behaviour for python 3.6.0 on Mac OS X 10.12.6 |
Issue is still present, although command completion does work in an interactive shell (that is, start Also: site.py contains code that similar to my "cmd.patch", I intend to create a PR based on it. |
This was fixed in #107748, for Python 3.13. From my Mac:
It's a new feature, so it's not backported. But, in Python 3.11 tab completion should work if you install readline and build with |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: