-
Notifications
You must be signed in to change notification settings - Fork 285
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
[RFC] run_config()
: skip interrupt unless explicitly passed config_file
#551
[RFC] run_config()
: skip interrupt unless explicitly passed config_file
#551
Conversation
run_config()
skip interrupt unless explicitly passed config_file
run_config()
: skip interrupt unless explicitly passed config_file
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.
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: #563 ? |
@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...
>>>
@jonathanslenders |
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. |
Note
I made a mistake below - making things noisier, not quieter :).
Thank you for catching the bug in my PR @orhanhenrik, and also to @jonathanslenders for the PR #563 with a quick turnaround and release.
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
Extracts default
config_file
into constant:DEFAULT_CONFIG_FILE
Checks for
config_file
being nullishIf yes (nullish), set
explicit_config_file
toTrue
, then:Set the empty
config_file
toDEFAULT_CONFIG_FILE
.Preserving default behavior
If no (explicit value passed), set
explicit_config_file
toFalse
Check for
explicit_config_file
in condition that runs:Other options
Do nothing, accept current behavior
[RFC]
run_config()
: skip interrupt ifconfig_file
not found #550: New paraminterrupt_if_not_found
(bool)Remove default
config_file
param.Return
None
if noconfig_file
passed.