Skip to content

Commit

Permalink
python - Handle failure to load readline module
Browse files Browse the repository at this point in the history
Modify pythonrc.py so that if it can't load the readline module it will
at least do other setup.
  • Loading branch information
aschrab committed Mar 12, 2021
1 parent 102f464 commit cf4a144
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions pythonrc.py
@@ -1,27 +1,34 @@
# vim: ft=python
import readline
import rlcompleter
import os
import sys
import atexit

from pprint import pprint as p

# Avoid errors about unused imports
assert rlcompleter
assert p
imports = ['os', 'sys', 'atexit']

# Report non-default imports
print("Imported os, sys, atexit, readline, rlcompleter")

readline.parse_and_bind('tab: complete')
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
import readline
imports.push('readline')
import rlcompleter
imports.push('rlcompleter')
# Avoid errors about unused imports
assert rlcompleter
assert p

readline.parse_and_bind('tab: complete')
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass

atexit.register(readline.write_history_file, histfile)
except Exception:
print("!!!! Failed to setup readline history")

atexit.register(readline.write_history_file, histfile)
# Report non-default imports
print("Imported " + ", ".join(imports))

h = [None]

Expand Down

0 comments on commit cf4a144

Please sign in to comment.