Skip to content

Conversation

@shanechin
Copy link

Currently ptipython loads extension modules, but does not execute lines from the config file.

For example, I was trying to initialize the autoreload app from ipython,
c.InteractiveShellApp.extensions = ['autoreload']
c.InteractiveShellApp.exec_lines = ['%autoreload 2']
c.InteractiveShellApp.exec_lines.append('print("Warning: disable autoreload in ipython_config.py to improve performance.")')

The first line worked, while the other two were ignored.

This allows ipython configuration to support use cases mentioned in:
#36
#65

I'm sure there are a lot more cases where the ptipython interface is slightly different from the ipython one, but I'm not sure what the plan for convergence is, so for now I tried to follow around the same pattern as initialize_extensions.

Currently ptipython loads extension modules, but does not execute lines from the config file.
@jonathanslenders
Copy link
Member

Hi @sac2171,

Sorry for the late reply. Can you have a look at whether this still applies when using together with IPython 5.0. If it still works correctly in that case, I will merge it.

@joaqo
Copy link

joaqo commented Jun 20, 2017

Are there plans to integrate this? Its currently the only thing preventing me from switching to ptpython.

@shanechin
Copy link
Author

I can take another look at this soon-ish, not sure if it is still relevant.

@afrieder
Copy link

I can confirm this change still works with IPython 6.1.0 is and still a useful change.

@taylorlee
Copy link

This works for me with python 3.5.2 and IPython 6.2.1

Full config:

$ python3 --version
Python 3.5.2

$ ipython --version
6.2.1

$ pip freeze | grep pt.*python
ptipython==1.0.0
ptpython==0.41

$ cat .ipython/profile_default/ipython_config.py 
c = get_config()

c.InteractiveShellApp.extensions = ['autoreload']
c.InteractiveShellApp.exec_lines = ['%autoreload 2']
c.InteractiveShellApp.exec_lines.append('print("Warning: disable autoreload in ipython_config.py to improve performance.")')

$ ptipython
Warning: disable autoreload in ipython_config.py to improve performance.
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: %autoreload #already pre-loaded

In [2]:

@actionless
Copy link

exec_lines thing still working only after applying this patch

@danihodovic
Copy link

danihodovic commented Jul 19, 2019

Could we merge this? Autoreloads on startup only work if this is added.

cat ~/.ipython/profile_default/ipython_config.py
c.InteractiveShellApp.extensions = ['autoreload']
c.InteractiveShellApp.exec_lines = [
    '%autoreload 2',
    'print("Hello from IPython")',
]

as outlined here django-extensions/django-extensions#1240 (comment)

@actionless
Copy link

@jonathanslenders any movement on merging this?

@rachmadaniHaryono
Copy link

i create pr here shanechin#1 so this pr can be easily merged into upstream

i notice there is some inconsistency with single and double quote character but i keep that to minimalize change from original pr

@actionless
Copy link

@rachmadaniHaryono just use ipython or smth else -- nobody gives an f here

@azmeuk
Copy link

azmeuk commented Nov 25, 2022

I can confirm this still functioning with ipython 8.6.0

@jonathanslenders The patch is pretty simple and would unlock a really useful feature. Any chance you might have some time to spend reviewing this soon? 🙏

jonathanslenders added a commit that referenced this pull request Nov 25, 2022
@jonathanslenders
Copy link
Member

Just merged it here: 8bbdc53

I'll push a new release to PyPI, @azmeuk can you test this?

@ALL: Sorry it took almost 6 years! (Too many open issues to take care of...)

@azmeuk
Copy link

azmeuk commented Nov 25, 2022

Just tested. It works like a charm 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants