Skip to content
This repository was archived by the owner on Jun 9, 2020. It is now read-only.

Conversation

@caethan
Copy link
Collaborator

@caethan 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.

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 2 commits July 12, 2016 10:40
The new magic decorators need ipython imported at a module level
@wholmgren
Copy link

Works for me on 5.0.0 -- thanks @caethan!

@tguillemot
Copy link

Seem's that travis is not happy.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

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

@jingkungao
Copy link

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

@caethan
Copy link
Collaborator Author

caethan commented Aug 12, 2016

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

@danielballan
Copy link

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

@cancan101
Copy link

How does this compare to #68?

@caethan
Copy link
Collaborator Author

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
Copy link

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
Copy link
Collaborator Author

caethan commented Sep 2, 2016

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

@tguillemot
Copy link

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

@patricksnape
Copy link

#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
Copy link

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
Copy link
Collaborator Author

caethan commented Sep 15, 2016

@patricksnape: Thanks for checking #68!

@alimuldal
Copy link

Is there anything preventing this from being merged?

@wesm
Copy link

wesm commented Sep 29, 2016

@rkern?

@espg
Copy link

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
Copy link

@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
Copy link

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

@espg
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

@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
Copy link
Collaborator Author

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.

@takluyver
Copy link

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

@caethan
Copy link
Collaborator Author

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
Copy link

Thanks @caethan :-)

@caethan caethan merged commit d3cef04 into rkern:master Oct 20, 2016
@caethan
Copy link
Collaborator Author

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
Copy link
Collaborator Author

caethan commented Oct 20, 2016

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

@gabereiser
Copy link

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

@wesm
Copy link

wesm commented Oct 20, 2016

thank you!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.