Skip to content
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

PR: Add permanent history to the debugger #10010

Merged
merged 12 commits into from
Aug 23, 2019

Conversation

impact27
Copy link
Contributor

Description of Changes

Small changes to pdb to save the history, so I can access the history of a previous debugging session.

This is not a really nice way of doing thing, but it works. Two (non easy) way of improving this:

  • The history of pdb should be saved at the spyder-kernels level, as is the case with ipython.
    (Well only kind of because the history is duplicated, see PR: Load history from IPython directly #7141 )
  • The history should be saved in a sqlite file, in the same way ipython does. I tried to reuse ipython core functions but I could't get it to work quickly. This allows to save the time the command was executed, and to separate between different sessions.
  • Wrote at least one-line docstrings (for any new functions)
  • Added unit test(s) covering the changes (if testable)
  • Included a screenshot or animation (if affecting the UI, see Licecap)

Issue(s) Resolved

Fixes #

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct:

@pep8speaks
Copy link

pep8speaks commented Aug 13, 2019

Hello @impact27! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 231:80: E501 line too long (80 > 79 characters)

Comment last updated at 2019-08-23 13:52:17 UTC

@impact27 impact27 changed the title Add history file to pdb history PR: Add history file to pdb history Aug 13, 2019
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

@impact27, I left a couple of minor comments, otherwise looks good.

@ccordoba12 ccordoba12 added this to the v4.0beta5 milestone Aug 13, 2019
@ccordoba12 ccordoba12 changed the title PR: Add history file to pdb history PR: Add permanent history to the debugger Aug 13, 2019
@ccordoba12
Copy link
Member

This is not a really nice way of doing thing, but it works

I know this is not the best solution, but it's good enough until we have time to seriously improve our debugger (which is not going to happen for Spyder 4, but probably for version 5).

@impact27
Copy link
Contributor Author

impact27 commented Aug 14, 2019

The only think that could be

This is not a really nice way of doing thing, but it works

I know this is not the best solution, but it's good enough until we have time to seriously improve our debugger (which is not going to happen for Spyder 4, but probably for version 5).

I have been playing with that a bit and there is a problem with multilines inputs. I will try to fix that with sqlite.

@ccordoba12
Copy link
Member

I have been playing with that a bit and there is a problem with multilines inputs. I will try to fix that with sqlite.

You shouldn't waste your time with that because the solution we're thinking to implement doesn't involve enhancing IPdb but creating a debugging kernel.

Besides, I think multiline is really not an option in Pdb because you have to prefix Python code with ! so that Pdb parses it correctly.

@impact27
Copy link
Contributor Author

I used from IPython.core.history import HistoryManager so the history will be correctly saved.

@ccordoba12
Copy link
Member

I used from IPython.core.history import HistoryManager so the history will be correctly saved.

I'm -1 on that and I'd like you to revert that change. That not only makes things more complex than they need to be, but also there's no need of it because you can write multi-line statements in Pdb.

@impact27
Copy link
Contributor Author

Well the complexity is all in IPython.core.history.HistoryManager, so the spyder part is actually simpler. The multiline problem comes when I have:

import numpy as np
np.abs([1,
        2])

If I want to copy-paste the abs in pdb, it will work as is:

Screenshot 2019-08-14 at 15 08 43

But in the old implementation, as a newline separate the statement, I ended up with:

history = [
'import numpy as np', 
'np.abs([1,',
'        2])']

With the new implementation, the newlines are not specific characters, so there is no problem.

Using IPython.core.history.HistoryManager adds the benefits that sessions are correctly handled. It is possible to separate the history of two different session, event if they took place at the same place.

Futhermore, all the tools that are used to manage ipython history can be easily adapted to manage this new pdb history.

I therefore believe that this implementation is more future proof and has less bugs.

@impact27
Copy link
Contributor Author

I mean with a database I can store executed cells, not just lines, and I can attach more informations, such as the session this line was from, the line number, and more. So in the future if we want to add functionalities to the history, the database already exists and we don't need to migrate from a text file.

@ccordoba12
Copy link
Member

ccordoba12 commented Aug 14, 2019

The multiline problem comes when I have

I haven't considered this use case (I don't know how it could arise, besides copy/paste).

I mean with a database I can store executed cells, not just lines

Cells executed with runcell, right?

So in the future if we want to add functionalities to the history, the database already exists and we don't need to migrate from a text file.

Ok, that's a good point too.

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

I left a couple of minor comments, but I'd like to mention two other things:

  1. I think the main changes could be moved to DebuggingWidget, right? I mean, I don't see anything in them that requires the ControlWidget interface now.

  2. A test for this is missing. It can consist on creating a console, entering debug mode and writing a command on it, then opening a new console and verifying that that command was saved correctly in the debugging history.

    That test can replace the contents of current test_browse_history_dbg test, present in test_ipythonconsole.py.

@impact27
Copy link
Contributor Author

Cells executed with runcell, right?

Multiline statment pasted by the user in pdb, but it still needs to be a single statment. otherwise:
*** SyntaxError: multiple statements found while compiling a single statement

@ccordoba12
Copy link
Member

@impact27, this now needs a merge with master.

@impact27
Copy link
Contributor Author

There is a small issue with backward search in pdb that I will have a look at now.

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Thanks @impact27!! Another great addition of yours!

@ccordoba12 ccordoba12 merged commit d672bb5 into spyder-ide:master Aug 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants