ipdb icon indicating copy to clipboard operation
ipdb copied to clipboard

access to magic functions?

Open adamgreenhall opened this issue 11 years ago • 12 comments

Magic functions don't seem to work from the ipdb prompt, although they are visible in the tab completion.

ipdb>  %prun some_function()
*** SyntaxError: invalid syntax (<stdin>, line 1)

adamgreenhall avatar Nov 14 '12 18:11 adamgreenhall

I do not use IPython enough to guess what could cause this syntax error. Any fix welcome though.

gotcha avatar Dec 03 '12 23:12 gotcha

Well, it's nothing related to ipdb, but an IPython issue.

In latest IPython version (0.13.1 or git trunk), some magic function pdef/pdoc/pinfo have already been exposed to IPython debugger interface.

I tried to expose "prun" in IPython according to the following thread, but it is not as easy to handle as other pdef/pdoc/pinfo commands. Still got no luck yet. http://mail.scipy.org/pipermail/ipython-user/2013-January/011965.html

unicell avatar Feb 22 '13 08:02 unicell

I'll close this issue then.

If anyone comes with a fix, feel free to open a new issue referring this one.

gotcha avatar Mar 28 '13 22:03 gotcha

Has no one been able to implement this? :( Makes me quite sad that I can't pprint by default in ipdb.

k-funk avatar Aug 26 '14 02:08 k-funk

http://stackoverflow.com/questions/16184487/use-ipython-magic-functions-in-ipdb-shell

gotcha avatar Jun 04 '15 12:06 gotcha

We can make a hook and dispatch input that startswith % to ipython magics as @gotcha 's link suggests. However this is not ideal - e.g. %cpaste is actually pasting into IPython's shell instead of ipdb session...

@k-funk are there any particular magics that you would like to use?

See: https://github.com/gotcha/ipdb/compare/master...disconnect3d:ipdb_add_magic_research?expand=1

disconnect3d avatar May 15 '17 07:05 disconnect3d

Being able to pretty print is the most important for me, but there are quite a few useful magics that I would use: timeit, pwd, env

k-funk avatar May 18 '17 16:05 k-funk

Hi, %who and %whos don't work in ipdb :

ipdb> %who
*** SyntaxError: invalid syntax
ipdb> %whos
*** SyntaxError: invalid syntax

Is this because of ipython ?

Is there an ipython issue about this ?

sebma avatar Jun 22 '17 17:06 sebma

This feature would add a lot of value to ipdb. Anyone up to champion this feature?

AdrienLemaire avatar May 10 '19 07:05 AdrienLemaire

This would have to be done on IPython side, in IPython.terminal.debugger.TerminalPdb.cmdloop. I'm looking into it, but no promisses.

Another issue with this is that the context of the debugger ≠ context magics operate in. Working around this isn't hard, but there are probably few other things like this that would have to be taken care of.

MrMino avatar Jan 06 '21 06:01 MrMino

FYI IPython on master now runs its own interactive shell on interact, so technically you can just use that to get to the shell and run any given magic command there.

Not every magic makes sense in context of Ipdb - e.g. what would %autocall mean? There's a lot of backend that goes into magics that Ipdb's cmd.Cmd just does not posses, and trying to marry the two seems to result in an unending stream of spaghetti code.

Now that I think of it, it seems to me that some magics could be just ported on a case-by-case basis into Ipdb as debugger commands. It might get simpler if a way of adding "plugin" commands was introduced to Ipdb. That way it would be the case of wrapping magics selectively so that they cooperate with that system.

MrMino avatar Apr 21 '21 01:04 MrMino

@MrMino Yes. It would be great porting %who and %whos for ipdb.

sebma avatar Apr 23 '21 07:04 sebma