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
Allow the %run magic with '-b' to specify a file. #2782
Conversation
@@ -578,7 +582,7 @@ def run(self, parameter_s='', runner=None, | |||
ns = {'execfile': py3compat.execfile, 'prog_ns': prog_ns} | |||
try: | |||
#save filename so it can be used by methods on the deb object | |||
deb._exec_filename = filename | |||
deb._exec_filename = bp_file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this one be adjusted? I'll just test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I can't produce a situation where _exec_filename
is actually used. Can you? If not, I think we shouldn't change it - it seems more likely that it is supposed to be the name of the top-level file that's being run, rather than the file the breakpoint is in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think you're right. I didn't actually know what it was there for, so
I have no real reason to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The debugger uses it when looking for lines if the code was compiled with the filename <string>
. But I don't know how to create a case where that happens.
Do you want to push another commit to the same branch reversing the change on this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, now I can get it, if I exec a string of code inside the module. I don't think there's a way of being certain about it in that case, but I still think we should leave it as filename
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this should be left as filename
.
Other than the one change that @takluyver and I agree on, this is ready to go. I looked through the |
An alternative approach, which might have been simpler, would have been something more like: bp_cmd = opts.get('b', [1])[0]
if ':' not in bp_cmd:
bp_cmd = filename + ':' + bp_cmd
# ...
deb.do_break(bp_cmd) But I'm not sure if For now I think the proposed patch here is plenty fine. |
The syntax would be: %run -d -b file2.py:30 file1.py to break at line 30 of file2.py when running file1.py. The old syntax %run -d -b 20 file1.py still works the way it used to. Suggested by user gozzilli on StackOverflow (http://stackoverflow.com/questions/14305203/ipython-set-a-breakpoint-in-imported-file/).
OK, I changed |
OK, great. We'd normally want to add a test as well, especially as %run is one of the most delicate bits of the codebase. But I don't see an easy way to write an automated test for this. @bfroehle has already OKed this as well, so I'm going to merge it now. |
Allow the %run magic with '-b' to specify a file.
Allow the %run magic with '-b' to specify a file.
Hello,
Here is a minor tweak to the %run command that some users might find helpful:
The syntax would be:
to break at line 30 of file2.py when running file1.py.
The old syntax
still works the way it used to.
Suggested by user gozzilli on StackOverflow
(http://stackoverflow.com/questions/14305203/ipython-set-a-breakpoint-in-imported-file/).