-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Add magic function %drun to run code in debugger #3071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Is there an argument for this besides being quicker to type? The name drun isn't particularly self-explanatory. |
If there was not %pdb or %debug, I would use it but I couldn't. So I thought I'd make it consistent with %prun. Another option I had in mind was %with_debugger (or the one without underscore). |
To my mind, a slightly longer, more descriptive name is preferable. Especially with the notebook, we're trending towards better readability, rather than saving every keystroke. But I'm not a big user of |
We've generally been moving away from cryptic abbreviated names (e.g. replacing |
In the notebook I think you can't use debugger as it does not support STDIN. I'd use it mostly in terminal. Though I don't have strong opinion and I am OK with long name. |
We are waiting for @minrk PR: |
@Carreau coooool! So we want to rename it to %with_debugger or another name? An alternative way to add this functionality is to have %exec magic command which is like %run but works for statements. Then we can integrate commands such as %prun, %timeit, %time, %capture etc. into this. This is probably better because you can do thing like "capturing output while profiling". |
That PR is going to be dependent on #3011 (it's my stdin branch, if you want to check it out). |
Ah, I'd missed that it worked on statements, I thought you were just proposing a shortcut for Perhaps |
I was thinking the same thing about extending So if we are extending # old behavior
%debug
# debug a statement:
%debug my_statement()
# debug a cell:
%%debug
def foo():
1/0
foo() That doesn't seem too confusing to me, as it strictly adds functionality and doesn't change anything, right? It also seems fairly clear, as the sentence structure of |
I think overloading
Then I think |
Unfortunately, %profile already exists and does something unrelated. I'm |
It could be my own personal hangup about prun - I wouldn't touch it, and maybe others don't have this association of run == file. |
I remember that I thought |
'exec' is a keyword (Py2) or a builtin function (Py3), so I think we should If we were starting with a blank slate, I'd call the get-the-profile-name On 24 March 2013 23:46, Takafumi Arakaki notifications@github.com wrote:
|
Ah, I forgot that you can omit %, so that's why you want to avoid IPython is about executing code so I think it does not make sense to have better and shorter name for kind of meta management magic function (%profile) than the one about executing code (%profile_code). Also, probably 1.0 is a good timing for changing this. |
I don't have any attachment to the existing |
I would like to get @fperez's opinion about the |
I've been thinking about this quite a bit, and I think it's a good time to rationalize things out in the code execution magics department. Since running code is more or less the heart of ipython, we should do our best to have a clean and consistent api here. I mostly concur with @minrk in the idea that The rationale for what comes below: So here's what I think we should do:
In practice this plan really should be odne in separate PRs, one per topic (timing, profiling, debugging). I just wanted to lay out the plan here for feedback. Once we agree, this PR can focus on debugging and hopefully two more will come for profiling and timing. How does this sound? |
How about using subcommands instead? %run debug |
@jstenar, you mean instead of %debug, %time, %profile? It seems to me that keeping them as separate commands for blocks is not a bad option, since they will be most likely used in the notebook/qtconsole, and that makes them short and readable. We're trying to make Do you see any gains with your idea? |
I believe the discoverability would be better with subcommands. I mean %debug, %time, and %profile are just different ways of %run-ning code. To me it makes more sense since these commands just represent different ways of %running code. I believe using subcommands can simplify the code. By switching to argparse and subcommands you can have a separate function for each subcommand instead of a giant function as it is now. However our argparse decorators would have to be updated to handle subcommands. |
Discoverability could also be handled by improving the corresponding docstrings. For example
I'm personally -1 to putting everything in |
I tend to agree with @bfroehle here, for two reasons:
@jstenar, does that seem reasonable? |
I do not have a strong opinion here. But I think I'm a bit confused on the one hand it sounds like @bfroehle If we go for a design where %profile etc are separate commands that can Also I think @bfroehle's suggestion about the doc strings makes perfect |
To frame this a different way, there are at least three special kinds of execution (timed, profiled, debugged) that people might want for either a block of code in IPython, or code from an external file. What's the most intuitive way to handle that. At present:
Another possibility might be to introduce -f (file) flags to the execution magic commands, so you could do things like:
|
(Sorry, didn't mean to close) |
How about |
I'm -1 on Keep in mind that ps - note that this PR needs a rebase. @tkf, if you can do that and the minor cleanups indicated above, I think we're close to merge point. |
It is easy to add long options, like
Well, I use I am not focusing on naming issue. I agree that |
You don't lose the ability to combine them, since it's perfectly reasonable to 'stack' magics (we do it all the time with %time
%profile
# ... code I think that's fairly clear... |
Current line magic does not work in that way, right?
and
are not equivalent, I suppose.
does not work either. If what you mean is to make one of the above work, that makes sense. I like the approach of stacking cell magics. |
Yes, sorry, that's what I meant. They can all be updated to work as nested cell magics. And btw, if you really want to have a single entry point for running blocks, rather than creating a new magic that needs to be taught, we can simply extend
as a line magic, and %%run [options]
#...
# block of code
#... as a cell one. That would reuse 100% of the I actually think that's the cleanest solution: stackable individual magics for And all of these things should be reusing a few generic non-magic objects/functions, with the magics themselves being very thin syntax layers on top of these components. |
Oh, and btw, this one needs a rebase... |
I thought I'd wait until the discussion is settled, to avoid possibility that we decide to go other direction. I also noticed that individual line magic has advantage over single line magic in other direction: You can avoid parsing options. So, I can go ahead and implement |
I am not sure if the discussion is settled but I guessed this patch will be pulled by 90% so I just rebased it. |
@fperez can you look at this PR to see if all of the comment have been addressed? |
@tkf, I'm sorry for the slow progress, my fault!! I'd like to see a deeper cleanup/refactoring of our execution magics along the lines of the discussion above, but I think this particular PR is already progress in the right direction, and there's no point in holding it up further. Thanks @tkf for the good work! If you're up for digging further into Merging now. |
Extend the `%debug` magic to also run a statement under the control of a debugger, if called with arguments. If called with no arguments after an error has occurred, it continues to work as before.
Extend the `%debug` magic to also run a statement under the control of a debugger, if called with arguments. If called with no arguments after an error has occurred, it continues to work as before.
%drun is pretty much like %prun but instead it starts debugger rather than profiler.
This PR is made on top of #3066. I will rebase it after #3066 is merged if needed.