prompt-toolkit / ptpython

A better Python REPL
BSD 3-Clause "New" or "Revised" License
5.19k stars 277 forks source link

`ptpython.run_config()` / `embed()` "Impossible to read" interrupt with default usage #549

Closed tony closed 11 months ago

tony commented 1 year ago

Problem / Example

Project: django-extensions's ./manage.py shell_plus - runs into this if no config is set:

./manage.py shell_plus
<loading django imports>
Impossible to read '/Users/<username>/.config/ptpython/config.py'

This creates friction when launching ptpython:

Other cases

Comments desiring to suppress "Impossible to read": https://github.com/prompt-toolkit/ptpython/issues/329#issuecomment-707014226

I would propose there are others hitting this issue but it hasn't been articulated correctly yet.

Proposal

"Impossible to read" shouldn't print / interrupt loading when the no config file is found

PRs

2 ideas / approaches:

Relevant code

ptpython.repl.run_config()

ptpython.repl.embed()

Analysis

ptpython.repl.run_config() has a default argument of config_file: str = "~/.config/ptpython/config.py"

However, in most command line applications, no configuration file exists - there's sensible defaults. e.g. python can load without the user having a pythonrc, tmux can load without a ~/.tmux.conf, etc.

The existing behavior means users simply wanting to enter are given an error that's not their fault: config_file was entered by ptpython and downstream users that don't have it in place are interrupted.

tony commented 1 year ago

I can make a PR over the weekend

tony commented 1 year ago

@jonathanslenders

Hi! I'm running into this on cloud-based docker images where it's not easy to have a config file. I'm very happy to use the REPL's defaults.

Do you have strong opinions on run_config() behavior either way? If not, I have two approaches in PRs in the description. They're geared toward making downstream usage frictionless as possible (I think).

Thank you.

tony commented 12 months ago

@jonathanslenders Any thoughts? Maybe the existing behavior you have is as you intend it to be (that's also fine).

P.S. No hurry either. Just seeing if I can get your attention while the PR is fresh in memory and the issue is ongoing on my side.