You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
l0nwlf commented on Jun 19, 2010
l0nwlfmannequin
Mannequin
More actions
It seems readline module is not installed on your system.
Quoting Ned Deily's comment from bpo-8365 which will most probably solve your issue:
"bpo-6877 (and subsequent fixes in bpo-8066) allows the Python readline module to be built and linked with the OS X editline (libedit) library rather than with the GNU readline library (which is not included with OS X). However, the libedit included in versions of OS X prior to 10.5 is considered too broken to use here.
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:
./configure MACOSX_DEPLOYMENT_TARGET=10.6 ; make
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)"
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.
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.
zvezdan commented on Jul 9, 2010
zvezdanmannequin
Mannequin
More actions
Does a translation really need to be in Python?
I use .editrc file in my home directory with this content:
We either have to add some translation, or tweak parts of python:
the cmd module needs to learn how to configure libedit when
the readline extension was linked to libedit
the rlcompleter documentation needs to be updated to do the same
And that's just the stdlib. IIRC ipython contains code that uses libedit
style configuration instead of readline when using /usr/bin/python on OSX, and there are probably other.
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__.
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).
This was fixed in #107748, for Python 3.13. From my Mac:
$ PYTHON_BASIC_REPL=1 ./python.exe
Python 3.14.0a0 (heads/main:2c7209a3bdf, Jun 17 2024, 17:10:56) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> i<tab><tab>
id( if import in input( int( is isinstance( issubclass( iter(
>>> import readline
>>> readline.<tab><tab>
readline.add_history( readline.read_history_file(
readline.backend readline.read_init_file(
readline.clear_history() readline.redisplay()
[... several lines omitted ...]
>>> readline.backend
'editline'
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 ./configure --with-readline=readline.
Activity
slcott commentedon Jun 19, 2010
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.
merwok commentedon Jun 19, 2010
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?
l0nwlf commentedon Jun 19, 2010
It seems readline module is not installed on your system.
Quoting Ned Deily's comment from bpo-8365 which will most probably solve your issue:
"bpo-6877 (and subsequent fixes in bpo-8066) allows the Python readline module to be built and linked with the OS X editline (libedit) library rather than with the GNU readline library (which is not included with OS X). However, the libedit included in versions of OS X prior to 10.5 is considered too broken to use here.
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:
(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)"
ronaldoussoren commentedon Jun 22, 2010
scott:
Which OSX version are you using?
Which Python are you using?
Does 'import readline' work?
ronaldoussoren commentedon Jun 22, 2010
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.
ronaldoussoren commentedon Jun 22, 2010
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.
ronaldoussoren commentedon Jun 22, 2010
This (untested) patch should fix the issue for the cmd module:
l0nwlf commentedon Jun 22, 2010
Tested the patch and it works for trunk and python3.2 alpha.
Without adding SDK flag with configure readline module failed to build.
Python build finished, but the necessary bits to build these modules were not found:
_gdbm ossaudiodev readline
spwd
However for cmd module, tab completion and history(up|down arrow) worked fine.
ronaldoussoren commentedon Jun 27, 2010
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.
zvezdan commentedon Jul 9, 2010
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.
ronaldoussoren commentedon Jul 9, 2010
We either have to add some translation, or tweak parts of python:
the cmd module needs to learn how to configure libedit when
the readline extension was linked to libedit
the rlcompleter documentation needs to be updated to do the same
And that's just the stdlib. IIRC ipython contains code that uses libedit
style configuration instead of readline when using /usr/bin/python on OSX, and there are probably other.
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...
ronaldoussoren commentedon Jul 16, 2013
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.
boompig commentedon Jan 17, 2018
I can confirm this behaviour for python 3.6.0 on Mac OS X 10.12.6
ronaldoussoren commentedon Nov 22, 2022
Issue is still present, although command completion does work in an interactive shell (that is, start
cmdloop()from the REPL.Also: site.py contains code that similar to my "cmd.patch", I intend to create a PR based on it.
encukou commentedon Jun 17, 2024
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
./configure --with-readline=readline.