Closed tony closed 11 months ago
Thanks!
@jonathanslenders Long time no see! Hope all is well.
I just tested this fix in the newest release, and it doesn't work. It is actually more noisy since it prints a traceback as well.
Traceback (most recent call last):
File "/Users/orhan/Documents/Hyre/django-backend/app/.venv/lib/python3.11/site-packages/ptpython/repl.py", line 445, in run_config
with open(config_file, "rb") as f:
^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/Users/orhan/.config/ptpython/config.py'
Press ENTER to continue...
There needs to be a return if the file doesn't exist, instead of trying to open the file.
@orhanhenrik : I'm not using Django, so can't test right now, but looking at the code, I think the following patch could work:
--- a/ptpython/repl.py
+++ b/ptpython/repl.py
@@ -433,9 +433,10 @@ def run_config(repl: PythonInput, config_file: str | None = None) -> None:
input("\nPress ENTER to continue...")
# Check whether this file exists.
- if not os.path.exists(config_file) and explicit_config_file:
- print("Impossible to read %r" % config_file)
- enter_to_continue()
+ if not os.path.exists(config_file):
+ if explicit_config_file:
+ print("Impossible to read %r" % config_file)
+ enter_to_continue()
return
# Run the config file in an empty namespace.
Would you be able to try that? @tony : Can you check as well? I can push a new release later today if this is all it takes.
Can you check this PR: https://github.com/prompt-toolkit/ptpython/pull/563 ?
I just tested this fix in the newest release, and it doesn't work. It is actually more noisy since it prints a traceback as well.
@orhanhenrik Oh no, that's not intended. Thank you for reporting this back!
Recreated with django-extensions 3.2.4dev0 and ptpython 3.0.24:
Traceback (most recent call last):
File ".../ptpython/ptpython/repl.py", line 445, in run_config
with open(config_file, "rb") as f:
^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '~/.config/ptpython/config.py'
Press ENTER to continue...
>>>
Would you be able to try that? @tony : Can you check as well? I can push a new release later today if this is all it takes.
@jonathanslenders fix-config-file-does-not-exist
/ https://github.com/prompt-toolkit/ptpython/pull/563 works! Buttery smooth!
Thank you for testing! The release will be for tomorrow.
Let's see how this goes!
Thanks! Looks like that fixes the issue 🙌
3.0.25 is published to PyPI.
Resolves #549
Problem
Downstream packages (e.g. django-extension's
shell_plus
) useptpython.repl.run_config()
to use the system's optional ptpython config files. The result is users can be surprised byrun_config()
interrupting the terminal for a config file they didn't explicitly request: ptpython had the default.Current behavior
run_config()
specifies a default configuration file, which may or may not exist on systems.ptpython.repl.embed()
runs flawlessly ifrun_config()
returns an empty value.What this change does
config_file
into constant:DEFAULT_CONFIG_FILE
Checks for
config_file
being nullishIf yes (nullish), set
explicit_config_file
toTrue
, then:config_file
toDEFAULT_CONFIG_FILE
.Preserving default behavior
explicit_config_file
toFalse
Check for
explicit_config_file
in condition that runs:Other options
550: New param
interrupt_if_not_found
(bool)Remove default
config_file
param._Return
None
if noconfig_file
passed._