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

BUG: Switched to new way of registering ipython magics #68

Closed
wants to merge 1 commit into from

Conversation

KristianHolsheimer
Copy link

Hi Robert,

Thanks for the awesome package, it's been a lifesaver on many occasions!

This is a minor change, implementing the new way of registering ipython magics. Namely, get_ipython().define_magic(...) was apparently deprecated. The new way uses get_ipython().register_magic_function(...) instead. I did leave the old one in for backward compatibility.

Cheers,
-Kris

@@ -369,7 +369,11 @@ def magic_lprun(self, parameter_s=''):
def load_ipython_extension(ip):
""" API for IPython to recognize this module as an IPython extension.
"""
ip.define_magic('lprun', magic_lprun)
if hasattr(ip, 'define_magic'):
Copy link

Choose a reason for hiding this comment

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

I got an AttributeError: 'ZMQInteractiveShell' object has no attribute 'define_magic' on this line.

Copy link
Author

@KristianHolsheimer KristianHolsheimer Aug 31, 2016

Choose a reason for hiding this comment

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

Hmmm, are you sure you're on my branch (and reloaded the modules)?

The reason I'm asking is that this error is exactly the reason why I made this pull request.

Copy link
Author

Choose a reason for hiding this comment

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

More specifically, hasattr(ip, 'define_magic') should evaluate to False, so as to avoid the AttributeError you're experiencing.

@MSeifert04
Copy link

This doesn't work for me IPython 5.1, Python 3.5: %lprun -f ....

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

C:\-\lib\site-packages\IPython\core\interactiveshell.py in magic(self, arg_s)
   2156         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2157         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2158         return self.run_line_magic(magic_name, magic_arg_s)
   2159 
   2160     #-------------------------------------------------------------------------

C:\-\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line)
   2077                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2078             with self.builtin_trap:
-> 2079                 result = fn(*args,**kwargs)
   2080             return result
   2081 

C:\-\lib\site-packages\line_profiler.py in magic_lprun(self, parameter_s)
    281     opts_def = Struct(D=[''], T=[''], f=[], m=[])
    282     parameter_s = parameter_s.replace('"', r'\"').replace("'", r"\'")
--> 283     opts, arg_str = self.parse_options(parameter_s, 'rsf:m:D:T:', list_all=True)
    284     opts.merge(opts_def)
    285 

AttributeError: 'str' object has no attribute 'parse_options'

@patricksnape
Copy link

This is not sufficient, the signature to magic functions has changed, #65 is the correct fix.

@caethan
Copy link
Collaborator

caethan commented Oct 20, 2016

Fixed by the 2.0 release.

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.

5 participants