sloria / konch

Configures your Python shell.
https://konch.readthedocs.io/
MIT License
406 stars 18 forks source link

Read ptpython default configuration on initialization #51

Closed pycadelic closed 5 years ago

pycadelic commented 5 years ago

Without this small change, ptpython, when launched with konch, will load with default settings rather than reading ~/.ptpython/config.py.

I've tested it and it works as expected with flask-konch, which of course uses konch itself. In other words, "flask konch" now correctly loads ptpython with the settings in config.py, whereas before this change, it loaded ptpython with default settings.

pycadelic commented 5 years ago

Hey,

Thanks for feedback. Bear in mind I'm just getting started with all this python stuff!

It seems that configure() is conditionally defined in ptpython's entry_points/run_ptpython.py, so I don't see how it's possible to make use of that function.

Instead I thought about checking if config.py exists and adapting the configure= introducted in the original pull request based on that.

I moved my config.py out of the way and it seems to work ok now without having to press enter to continue past the warning.

˜

sloria commented 5 years ago

Ah, I see. To clarify: I meant that you could define the same sort of configure function that ptpython does. Something like

def configure(repl):
    config_path = os.path.expanduser("~/.ptpython/config.py")
    if os.path.exists(path):
        run_config(repl, path)

embed(globals=self.context, vi_mode=self.ptpy_vi_mode, configure=configure)
pycadelic commented 5 years ago

How about this way? Just to reuse what was already done. Interesting, that flake8 thing. I'll dig into it, good tip!

pycadelic commented 5 years ago

I agree that the other version is cleaner and has less duplication.

Give me a few days, and I'll get back to you about it!

sloria commented 5 years ago

@pycadelic I went ahead and made the minor adjustment in #56 . Thanks again for working on this!