Changeset 6046

Show
Ignore:
Timestamp:
12/13/12 14:42:32 (6 years ago)
Author:
leonwlaw
Message:

Fix for seash tab-complete not working on OSX Python 2.7. (#1136)
The shared object file included with OSX Python 2.7 is not compatible with our tab-completion module. Therefore, we need this version for it to work correctly. It breaks on linux though, which is why it is initially readline.so.mac. We only rename it if we are running on OSX, and we rename it back the instant the import is done.

Location:
seattle/trunk/seash
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • seattle/trunk/seash/seash.py

    r5512 r6046  
    5555from repyportability import * 
    5656 
     57# We need to expose the readline object file to OSX because the default object 
     58# file for Python 2.7 on OSX is not compatible with our tab completion module. 
     59import os 
     60import sys 
     61 
     62# Only rename if we're running on OSX 
     63rename_readline_so_file = sys.platform == 'darwin' 
     64HIDDEN_READLINE_SO_FN = 'readline.so.mac' 
     65EXPOSED_READLINE_SO_FN = 'readline.so' 
     66 
     67# Make sure we don't overwrite an existing readline.so if it exists. 
     68# We need to do this because os.rename() doesn't raise any errors 
     69# if the destination file already exists. 
     70if (rename_readline_so_file and  
     71    EXPOSED_READLINE_SO_FN not in os.listdir('.')): 
     72  try: 
     73    os.rename(HIDDEN_READLINE_SO_FN, EXPOSED_READLINE_SO_FN) 
     74  except OSError: 
     75    # There was a problem reading readline.so.mac 
     76    rename_readline_so_file = False 
    5777 
    5878tabcompletion = True 
     
    6080  # Even we can import the readline module successfully, we still disable tab 
    6181  # completion in Windows, in response to Ticket #891. 
    62   import os 
    6382  if os.name == 'nt': 
    6483    raise ImportError 
     
    7190  tabcompletion = False 
    7291   
     92# Don't hide mac readline.so if we didn't expose it 
     93if rename_readline_so_file: 
     94  os.rename(EXPOSED_READLINE_SO_FN, HIDDEN_READLINE_SO_FN) 
    7395 
    7496# Needed for parsing user commands and executing command functions 
     
    88110import os.path    # fix path names when doing upload, loadkeys, etc. 
    89111 
    90 import sys 
    91112 
    92113