8000 gh-121245: a regression test for site.register_readline() by skirpichev · Pull Request #121259 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-121245: a regression test for site.register_readline() #121259

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

Merged
merged 13 commits into from
Jul 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
XXX keep only test
  • Loading branch information
skirpichev committed Jul 3, 2024
commit f625be8d84b13b191215be3f647eacc9d8a089d5
27 changes: 14 additions & 13 deletions Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,34 +509,35 @@ def register_readline():
pass

if readline.get_current_history_length() == 0:
try:
from _pyrepl.main import CAN_USE_PYREPL
except ImportError:
CAN_USE_PYREPL = False
# If no history was loaded, default to .python_history,
# or PYTHON_HISTORY.
# The guard is necessary to avoid doubling history size at
# each interpreter exit when readline was already configured
# through a PYTHONSTARTUP hook, see:
# http://bugs.python.org/issue5845#msg198636
history = gethistoryfile()
if os.getenv("PYTHON_BASIC_REPL") or not CAN_USE_PYREPL:
my_readline = readline
else:
my_readline = _pyrepl.readline
try:
my_readline.read_history_file(history)
if os.getenv("PYTHON_BASIC_REPL"):
readline.read_history_file(history)
else:
_pyrepl.readline.read_history_file(history)
except (OSError,* _pyrepl.unix_console._error):
pass

def write_history():
try:
my_readline.write_history_file(history)
except (FileNotFoundError, PermissionError,
_pyrepl.unix_console.InvalidTerminal):
from _pyrepl.main import CAN_USE_PYREPL
except ImportError:
CAN_USE_PYREPL = False

try:
if os.getenv("PYTHON_BASIC_REPL") or not CAN_USE_PYREPL:
readline.write_history_file(history)
else:
_pyrepl.readline.write_history_file(history)
except (FileNotFoundError, PermissionError):
# home directory does not exist or is not writable
# https://bugs.python.org/issue19891
# or terminal doesn't have the required capability
pass

atexit.register(write_history)
Expand Down
Loading
0