Update for compatibility with IPython 5.0 #65

Merged
merged 8 commits into from Oct 20, 2016

Conversation

Projects
None yet
@caethan
Collaborator

caethan commented Jul 12, 2016

Replaces the depreciated ip.define_magic() method with ip.register_magics() and some modifications to handle the different API required.

Also tested with IPython 4.1.1. I don't know how far back the ip.register_magics() method goes, so I'm not sure how far back it's compatible.

Edit: Apparently the new API was included as far back as 0.13, and the old API was finally removed in 5.0. So removing support for the old API entirely is pretty unlikely to cause problems.

Brett Olsen
Update for compatibility with IPython 5.0
Also tested with IPython 4.1.1.  Replaces the depreciated ip.define_magic() method with ip.register_magics() and some modifications to handle the different API required.

Brett Olsen added some commits Jul 12, 2016

Brett Olsen
Add ipython as a hard dependency
The new magic decorators need ipython imported at a module level
@wholmgren

This comment has been minimized.

Show comment
Hide comment
@wholmgren

wholmgren Jul 12, 2016

Works for me on 5.0.0 -- thanks @caethan!

Works for me on 5.0.0 -- thanks @caethan!

@tguillemot

This comment has been minimized.

Show comment
Hide comment
@tguillemot

tguillemot Jul 16, 2016

Seem's that travis is not happy.

Seem's that travis is not happy.

dev_requirements.txt
@@ -1 +1,2 @@
-Cython
+ipython
+Cython --install-option='--no-cython-compile'

This comment has been minimized.

@tguillemot

tguillemot Jul 16, 2016

Travis don't like you pass the option like this. I don't know how to give it correctly.
I suggest that you let this file as it was before and add pip install ipython in .travis.yml.

@tguillemot

tguillemot Jul 16, 2016

Travis don't like you pass the option like this. I don't know how to give it correctly.
I suggest that you let this file as it was before and add pip install ipython in .travis.yml.

.travis.yml
@@ -5,7 +5,7 @@ python:
- "3.2"
- "2.7"
install:
- - pip install --install-option='--no-cython-compile' -r dev_requirements.txt
+ - pip install -r dev_requirements.txt

This comment has been minimized.

@tguillemot

tguillemot Jul 16, 2016

pip install ipython

@tguillemot

tguillemot Jul 16, 2016

pip install ipython

.travis.yml
@@ -5,7 +5,7 @@ python:
- "3.2"

This comment has been minimized.

@tguillemot

tguillemot Jul 16, 2016

IPython requires Python version 2.7 or 3.3 or above. So you have to remove 3.2 option.

@tguillemot

tguillemot Jul 16, 2016

IPython requires Python version 2.7 or 3.3 or above. So you have to remove 3.2 option.

This comment has been minimized.

@tguillemot

tguillemot Jul 16, 2016

BTW, it could be cool to add python 3.5.

@tguillemot

tguillemot Jul 16, 2016

BTW, it could be cool to add python 3.5.

@tguillemot

This comment has been minimized.

Show comment
Hide comment
@tguillemot

tguillemot Jul 16, 2016

@caethan Thanks for the solution. I've tell you how to change travis to pass the tests.

@caethan Thanks for the solution. I've tell you how to change travis to pass the tests.

@jingkungao

This comment has been minimized.

Show comment
Hide comment
@jingkungao

jingkungao Jul 31, 2016

@caethan Thanks for the solution. This works perfectly for me!

@caethan Thanks for the solution. This works perfectly for me!

@caethan

This comment has been minimized.

Show comment
Hide comment
@caethan

caethan Aug 12, 2016

Collaborator

Fixed the travis build. Thanks for the fixes, @tguillemot !

Collaborator

caethan commented Aug 12, 2016

Fixed the travis build. Thanks for the fixes, @tguillemot !

@danielballan

This comment has been minimized.

Show comment
Hide comment
@danielballan

danielballan Aug 15, 2016

Thanks @caethan. It would be great to see this merged and released on PyPI soon.

Thanks @caethan. It would be great to see this merged and released on PyPI soon.

@cancan101

This comment has been minimized.

Show comment
Hide comment
@cancan101

cancan101 Aug 24, 2016

How does this compare to #68?

How does this compare to #68?

@caethan

This comment has been minimized.

Show comment
Hide comment
@caethan

caethan Aug 30, 2016

Collaborator

@cancan101: Looks like #68 is a better approach - no need to include IPython as a specific dependency there. I'd use that one (assuming it works, haven't tested it myself).

Collaborator

caethan commented Aug 30, 2016

@cancan101: Looks like #68 is a better approach - no need to include IPython as a specific dependency there. I'd use that one (assuming it works, haven't tested it myself).

@esafak

This comment has been minimized.

Show comment
Hide comment
@esafak

esafak Aug 31, 2016

This does not work for me on IPython 5.1 & Jupyter NB 4.2.2:

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/IPython/core/extensions.py in _call_load_ipython_extension(self, mod)
    130     def _call_load_ipython_extension(self, mod):
    131         if hasattr(mod, 'load_ipython_extension'):
--> 132             mod.load_ipython_extension(self.shell)
    133             return True
    134 

/Users/esafak/Library/Python/3.5/lib/python/site-packages/line_profiler.py in load_ipython_extension(ip)
    370 
    371         return return_value
--> 372 
    373 
    374 def load_ipython_extension(ip):

AttributeError: 'ZMQInteractiveShell' object has no attribute 'define_magic'

esafak commented Aug 31, 2016

This does not work for me on IPython 5.1 & Jupyter NB 4.2.2:

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/IPython/core/extensions.py in _call_load_ipython_extension(self, mod)
    130     def _call_load_ipython_extension(self, mod):
    131         if hasattr(mod, 'load_ipython_extension'):
--> 132             mod.load_ipython_extension(self.shell)
    133             return True
    134 

/Users/esafak/Library/Python/3.5/lib/python/site-packages/line_profiler.py in load_ipython_extension(ip)
    370 
    371         return return_value
--> 372 
    373 
    374 def load_ipython_extension(ip):

AttributeError: 'ZMQInteractiveShell' object has no attribute 'define_magic'
@caethan

This comment has been minimized.

Show comment
Hide comment
@caethan

caethan Sep 2, 2016

Collaborator

@esafak Sure looks like you're using the master branch without this bug fix.

Collaborator

caethan commented Sep 2, 2016

@esafak Sure looks like you're using the master branch without this bug fix.

@tguillemot

This comment has been minimized.

Show comment
Hide comment
@tguillemot

tguillemot Sep 2, 2016

@caethan I'm agree with you. #68 is a better solution indeed.

@caethan I'm agree with you. #68 is a better solution indeed.

@patricksnape

This comment has been minimized.

Show comment
Hide comment
@patricksnape

patricksnape Sep 9, 2016

#68 is not a better fix - this is the fix. The way that magic functions are defined has changed and they are no longer passed a reference to self so functions like parse_options don't exist unless the magic function extends the Magics class. Therefore, this is the correct fix.

#68 is not a better fix - this is the fix. The way that magic functions are defined has changed and they are no longer passed a reference to self so functions like parse_options don't exist unless the magic function extends the Magics class. Therefore, this is the correct fix.

@wesm

This comment has been minimized.

Show comment
Hide comment
@wesm

wesm Sep 12, 2016

Throwing in my support for this fix. I ran into this failure when updating the IPython section of my book (where I use line_profiler)

wesm commented Sep 12, 2016

Throwing in my support for this fix. I ran into this failure when updating the IPython section of my book (where I use line_profiler)

@caethan

This comment has been minimized.

Show comment
Hide comment
@caethan

caethan Sep 15, 2016

Collaborator

@patricksnape: Thanks for checking #68!

Collaborator

caethan commented Sep 15, 2016

@patricksnape: Thanks for checking #68!

@alimuldal

This comment has been minimized.

Show comment
Hide comment
@alimuldal

alimuldal Sep 18, 2016

Is there anything preventing this from being merged?

Is there anything preventing this from being merged?

@wesm

This comment has been minimized.

Show comment
Hide comment

wesm commented Sep 29, 2016

@espg

This comment has been minimized.

Show comment
Hide comment
@espg

espg Oct 15, 2016

does not work for me on iPython 5.1 either:

IPython 5.1.0 -- An enhanced Interactive Python.
...
[TerminalIPythonApp] WARNING | Error in loading extension: line_profiler_ext
Check your config files in /Users/grigsbye/.ipython/profile_default
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/IPython/core/shellapp.py", line 246, in init_extensions
self.shell.extension_manager.load_extension(ext)
File "/usr/local/lib/python3.5/site-packages/IPython/core/extensions.py", line 85, in load_extension
if self._call_load_ipython_extension(mod):
File "/usr/local/lib/python3.5/site-packages/IPython/core/extensions.py", line 132, in _call_load_ipython_extension
mod.load_ipython_extension(self.shell)
File "/Users/grigsbye/.ipython/extensions/line_profiler_ext.py", line 4, in load_ipython_extension
ip.define_magic('lprun', line_profiler.magic_lprun)
AttributeError: 'TerminalInteractiveShell' object has no attribute 'define_magic'

espg commented Oct 15, 2016

does not work for me on iPython 5.1 either:

IPython 5.1.0 -- An enhanced Interactive Python.
...
[TerminalIPythonApp] WARNING | Error in loading extension: line_profiler_ext
Check your config files in /Users/grigsbye/.ipython/profile_default
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/IPython/core/shellapp.py", line 246, in init_extensions
self.shell.extension_manager.load_extension(ext)
File "/usr/local/lib/python3.5/site-packages/IPython/core/extensions.py", line 85, in load_extension
if self._call_load_ipython_extension(mod):
File "/usr/local/lib/python3.5/site-packages/IPython/core/extensions.py", line 132, in _call_load_ipython_extension
mod.load_ipython_extension(self.shell)
File "/Users/grigsbye/.ipython/extensions/line_profiler_ext.py", line 4, in load_ipython_extension
ip.define_magic('lprun', line_profiler.magic_lprun)
AttributeError: 'TerminalInteractiveShell' object has no attribute 'define_magic'

@danielballan

This comment has been minimized.

Show comment
Hide comment
@danielballan

danielballan Oct 15, 2016

@espg Have you tried installing the branch from this PR? That error message suggests you have the current version of line_profiler installed, which won't work on 5.0 or greater.

@espg Have you tried installing the branch from this PR? That error message suggests you have the current version of line_profiler installed, which won't work on 5.0 or greater.

@jakirkham

This comment has been minimized.

Show comment
Hide comment
@jakirkham

jakirkham Oct 17, 2016

What needs to be done to get this merged? Anything we can help with?

What needs to be done to get this merged? Anything we can help with?

@espg

This comment has been minimized.

Show comment
Hide comment
@espg

espg Oct 17, 2016

@danielballan I ran:

~ ➤ pip3 install git+https://github.com/rkern/line_profiler.git

Collecting git+https://github.com/rkern/line_profiler.git
Cloning https://github.com/rkern/line_profiler.git to /tmp/pip-is2n9c7m-build
Installing collected packages: line-profiler
Running setup.py install for line-profiler ... done
Successfully installed line-profiler-1.0

to install the branch... running ipython gives the errors in my other post. Note that this is on iPython 5.1.0 and python 3.5.2

espg commented Oct 17, 2016

@danielballan I ran:

~ ➤ pip3 install git+https://github.com/rkern/line_profiler.git

Collecting git+https://github.com/rkern/line_profiler.git
Cloning https://github.com/rkern/line_profiler.git to /tmp/pip-is2n9c7m-build
Installing collected packages: line-profiler
Running setup.py install for line-profiler ... done
Successfully installed line-profiler-1.0

to install the branch... running ipython gives the errors in my other post. Note that this is on iPython 5.1.0 and python 3.5.2

@gforsyth

This comment has been minimized.

Show comment
Hide comment
@gforsyth

gforsyth Oct 17, 2016

@espg
Try the following to install the patched version available in this PR:

pip3 install --upgrade git+https://github.com/caethan/line_profiler

gforsyth commented Oct 17, 2016

@espg
Try the following to install the patched version available in this PR:

pip3 install --upgrade git+https://github.com/caethan/line_profiler
@espg

This comment has been minimized.

Show comment
Hide comment
@espg

espg Oct 17, 2016

@gforsyth no dice:

~ ➤ pip3 install --upgrade git+https://github.com/caethan/line_profiler
Collecting git+https://github.com/caethan/line_profiler
Cloning https://github.com/caethan/line_profiler to /tmp/pip-dkkb048l-build
Installing collected packages: line-profiler
Found existing installation: line-profiler 1.0
Uninstalling line-profiler-1.0:
Successfully uninstalled line-profiler-1.0
Running setup.py install for line-profiler ... done
Successfully installed line-profiler-1.0
~ ➤ ipython
Python 3.5.2 (default, Sep 29 2016, 18:13:17)
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
[TerminalIPythonApp] WARNING | Error in loading extension: line_profiler_ext
Check your config files in /Users/grigsbye/.ipython/profile_default
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/IPython/core/shellapp.py", line 246, in init_extensions
self.shell.extension_manager.load_extension(ext)
File "/usr/local/lib/python3.5/site-packages/IPython/core/extensions.py", line 85, in load_extension
if self._call_load_ipython_extension(mod):
File "/usr/local/lib/python3.5/site-packages/IPython/core/extensions.py", line 132, in _call_load_ipython_extension
mod.load_ipython_extension(self.shell)
File "/Users/grigsbye/.ipython/extensions/line_profiler_ext.py", line 4, in load_ipython_extension
ip.define_magic('lprun', line_profiler.magic_lprun)
AttributeError: 'TerminalInteractiveShell' object has no attribute 'define_magic'

espg commented Oct 17, 2016

@gforsyth no dice:

~ ➤ pip3 install --upgrade git+https://github.com/caethan/line_profiler
Collecting git+https://github.com/caethan/line_profiler
Cloning https://github.com/caethan/line_profiler to /tmp/pip-dkkb048l-build
Installing collected packages: line-profiler
Found existing installation: line-profiler 1.0
Uninstalling line-profiler-1.0:
Successfully uninstalled line-profiler-1.0
Running setup.py install for line-profiler ... done
Successfully installed line-profiler-1.0
~ ➤ ipython
Python 3.5.2 (default, Sep 29 2016, 18:13:17)
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
[TerminalIPythonApp] WARNING | Error in loading extension: line_profiler_ext
Check your config files in /Users/grigsbye/.ipython/profile_default
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/IPython/core/shellapp.py", line 246, in init_extensions
self.shell.extension_manager.load_extension(ext)
File "/usr/local/lib/python3.5/site-packages/IPython/core/extensions.py", line 85, in load_extension
if self._call_load_ipython_extension(mod):
File "/usr/local/lib/python3.5/site-packages/IPython/core/extensions.py", line 132, in _call_load_ipython_extension
mod.load_ipython_extension(self.shell)
File "/Users/grigsbye/.ipython/extensions/line_profiler_ext.py", line 4, in load_ipython_extension
ip.define_magic('lprun', line_profiler.magic_lprun)
AttributeError: 'TerminalInteractiveShell' object has no attribute 'define_magic'

@gforsyth

This comment has been minimized.

Show comment
Hide comment
@gforsyth

gforsyth Oct 17, 2016

Hey @espg -- it looks like pip3 isn't pointing to the python install where ipython lives. I don't want to pollute this thread with a bunch of troubleshooting but if you want to drop into https://tlk.io/line_profiler I'm happy to walk you through figuring it out.

Hey @espg -- it looks like pip3 isn't pointing to the python install where ipython lives. I don't want to pollute this thread with a bunch of troubleshooting but if you want to drop into https://tlk.io/line_profiler I'm happy to walk you through figuring it out.

@danielballan

This comment has been minimized.

Show comment
Hide comment
@danielballan

danielballan Oct 17, 2016

@espg That error message ("no attribute 'define_magic') suggests that your ipython is still not finding the version of the code in this PR, which replaces define_magic with the new IPython magics API. Perhaps your ipython and your pip are in different environments.

I second @jakirkham's offer to help -- I'd be willing to do the release if that helps get this out the door and restore compatibility with IPython stable.

@espg That error message ("no attribute 'define_magic') suggests that your ipython is still not finding the version of the code in this PR, which replaces define_magic with the new IPython magics API. Perhaps your ipython and your pip are in different environments.

I second @jakirkham's offer to help -- I'd be willing to do the release if that helps get this out the door and restore compatibility with IPython stable.

@caethan

This comment has been minimized.

Show comment
Hide comment
@caethan

caethan Oct 17, 2016

Collaborator

Talked with @espg and found the problem: He had a custom extension that tried to load in the magic command using define_magic. Fixed it to use the new method. Apparently scikit-learn suggested this method in some of their documentation, so I should submit a pull request to fix it once this pull request gets merged.

Collaborator

caethan commented Oct 17, 2016

Talked with @espg and found the problem: He had a custom extension that tried to load in the magic command using define_magic. Fixed it to use the new method. Apparently scikit-learn suggested this method in some of their documentation, so I should submit a pull request to fix it once this pull request gets merged.

@mbatchkarov mbatchkarov referenced this pull request in jupyter/notebook Oct 19, 2016

Closed

%load_ext line_profiler raises AttributeError #1844

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Oct 19, 2016

Possibly someone should ask @rkern for access to make new releases - or even maintain a fork, if Robert has gone awol.

Possibly someone should ask @rkern for access to make new releases - or even maintain a fork, if Robert has gone awol.

@caethan

This comment has been minimized.

Show comment
Hide comment
@caethan

caethan Oct 20, 2016

Collaborator

Talked to @rkern offline and he's going to transfer maintenance responsibility over to me, so we should be able to get this released properly before too long.

Collaborator

caethan commented Oct 20, 2016

Talked to @rkern offline and he's going to transfer maintenance responsibility over to me, so we should be able to get this released properly before too long.

@takluyver

This comment has been minimized.

Show comment
Hide comment

Thanks @caethan :-)

@caethan caethan merged commit d3cef04 into rkern:master Oct 20, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@caethan

This comment has been minimized.

Show comment
Hide comment
@caethan

caethan Oct 20, 2016

Collaborator

Merged in here - will announce on this thread once I get maintainer access to PyPi and 2.0 is released there.

Collaborator

caethan commented Oct 20, 2016

Merged in here - will announce on this thread once I get maintainer access to PyPi and 2.0 is released there.

@caethan

This comment has been minimized.

Show comment
Hide comment
@caethan

caethan Oct 20, 2016

Collaborator

2.0 is released on PyPi with this fix. Enjoy and be merry!

Collaborator

caethan commented Oct 20, 2016

2.0 is released on PyPi with this fix. Enjoy and be merry!

@gabereiser

This comment has been minimized.

Show comment
Hide comment
@gabereiser

gabereiser Oct 20, 2016

👍 this has bit me today and ended up here only to find the interwebs haven't caught up with this fix.

👍 this has bit me today and ended up here only to find the interwebs haven't caught up with this fix.

@wesm

This comment has been minimized.

Show comment
Hide comment
@wesm

wesm Oct 20, 2016

thank you!

wesm commented Oct 20, 2016

thank you!

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