rkern / line_profiler

(OLD REPO) Line-by-line profiling for Python - Current repo ->
https://github.com/pyutils/line_profiler
Other
3.6k stars 254 forks source link

Update for compatibility with IPython 5.0 #65

Closed caethan closed 7 years ago

caethan commented 8 years ago

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.

wholmgren commented 8 years ago

Works for me on 5.0.0 -- thanks @caethan!

tguillemot commented 8 years ago

Seem's that travis is not happy.

tguillemot commented 8 years ago

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

jingkungao commented 8 years ago

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

caethan commented 8 years ago

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

danielballan commented 8 years ago

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

cancan101 commented 8 years ago

How does this compare to #68?

caethan commented 8 years ago

@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 commented 8 years ago

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 commented 8 years ago

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

tguillemot commented 8 years ago

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

patricksnape commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

@patricksnape: Thanks for checking #68!

alimuldal commented 8 years ago

Is there anything preventing this from being merged?

wesm commented 7 years ago

@rkern?

espg commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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

espg commented 7 years ago

@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 commented 7 years ago

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

pip3 install --upgrade git+https://github.com/caethan/line_profiler
espg commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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

caethan commented 7 years ago

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 commented 7 years ago

Thanks @caethan :-)

caethan commented 7 years ago

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

caethan commented 7 years ago

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

gabereiser commented 7 years ago

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

wesm commented 7 years ago

thank you!