From d25e67874ffc745a3a65a6776c1b9aa401dca076 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Mon, 4 Sep 2023 08:01:04 -0500 Subject: [PATCH] Only interrupt run_config() for explicitly passed config_file --- ptpython/repl.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ptpython/repl.py b/ptpython/repl.py index 3a74c3c..ce92c66 100644 --- a/ptpython/repl.py +++ b/ptpython/repl.py @@ -630,23 +630,28 @@ def enable_deprecation_warnings() -> None: warnings.filterwarnings("default", category=DeprecationWarning, module="__main__") -def run_config( - repl: PythonInput, config_file: str = "~/.config/ptpython/config.py" -) -> None: +DEFAULT_CONFIG_FILE = "~/.config/ptpython/config.py" + + +def run_config(repl: PythonInput, config_file: str | None = None) -> None: """ Execute REPL config file. :param repl: `PythonInput` instance. :param config_file: Path of the configuration file. """ + explicit_config_file = config_file is not None + # Expand tildes. - config_file = os.path.expanduser(config_file) + config_file = os.path.expanduser( + config_file if config_file is not None else DEFAULT_CONFIG_FILE + ) def enter_to_continue() -> None: input("\nPress ENTER to continue...") # Check whether this file exists. - if not os.path.exists(config_file): + if not os.path.exists(config_file) and explicit_config_file: print("Impossible to read %r" % config_file) enter_to_continue() return