author | Matt Mackall <mpm@selenic.com> |
Wed, 02 Mar 2016 12:46:54 -0600 | |
changeset 28314 | 918b64c91e6c |
parent 27721 | e4b512bb6386 |
child 28476 | e28dc6de38e7 |
permissions | -rw-r--r-- |
11633 | 1 |
# debugshell extension |
2 |
"""a python shell with repo, changelog & manifest objects""" |
|
3 |
||
19773
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
4 |
import sys |
11633 | 5 |
import mercurial |
6 |
import code |
|
27721
e4b512bb6386
debugshell: disable demand importer when importing debugger
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21243
diff
changeset
|
7 |
from mercurial import ( |
e4b512bb6386
debugshell: disable demand importer when importing debugger
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21243
diff
changeset
|
8 |
cmdutil, |
e4b512bb6386
debugshell: disable demand importer when importing debugger
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21243
diff
changeset
|
9 |
demandimport, |
e4b512bb6386
debugshell: disable demand importer when importing debugger
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21243
diff
changeset
|
10 |
) |
21243
8b5c039f2b4f
debugshell: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
19794
diff
changeset
|
11 |
|
8b5c039f2b4f
debugshell: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
19794
diff
changeset
|
12 |
cmdtable = {} |
8b5c039f2b4f
debugshell: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
19794
diff
changeset
|
13 |
command = cmdutil.command(cmdtable) |
11633 | 14 |
|
19771
3bc675361206
debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents:
11633
diff
changeset
|
15 |
def pdb(ui, repo, msg, **opts): |
11633 | 16 |
objects = { |
17 |
'mercurial': mercurial, |
|
18 |
'repo': repo, |
|
19 |
'cl': repo.changelog, |
|
20 |
'mf': repo.manifest, |
|
21 |
} |
|
19771
3bc675361206
debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents:
11633
diff
changeset
|
22 |
|
3bc675361206
debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents:
11633
diff
changeset
|
23 |
code.interact(msg, local=objects) |
3bc675361206
debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents:
11633
diff
changeset
|
24 |
|
19772
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
25 |
def ipdb(ui, repo, msg, **opts): |
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
26 |
import IPython |
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
27 |
|
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
28 |
cl = repo.changelog |
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
29 |
mf = repo.manifest |
19794
cccc44304b2c
debugshell: appease pyflakes
Matt Mackall <mpm@selenic.com>
parents:
19773
diff
changeset
|
30 |
cl, mf # use variables to appease pyflakes |
19772
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
31 |
|
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
32 |
IPython.embed() |
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
33 |
|
21243
8b5c039f2b4f
debugshell: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
19794
diff
changeset
|
34 |
@command('debugshell|dbsh', []) |
19771
3bc675361206
debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents:
11633
diff
changeset
|
35 |
def debugshell(ui, repo, **opts): |
11633 | 36 |
bannermsg = "loaded repo : %s\n" \ |
37 |
"using source: %s" % (repo.root, |
|
38 |
mercurial.__path__[0]) |
|
19771
3bc675361206
debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents:
11633
diff
changeset
|
39 |
|
19773
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
40 |
pdbmap = { |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
41 |
'pdb' : 'code', |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
42 |
'ipdb' : 'IPython' |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
43 |
} |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
44 |
|
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
45 |
debugger = ui.config("ui", "debugger") |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
46 |
if not debugger: |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
47 |
debugger = 'pdb' |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
48 |
|
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
49 |
# if IPython doesn't exist, fallback to code.interact |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
50 |
try: |
27721
e4b512bb6386
debugshell: disable demand importer when importing debugger
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21243
diff
changeset
|
51 |
with demandimport.deactivated(): |
e4b512bb6386
debugshell: disable demand importer when importing debugger
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21243
diff
changeset
|
52 |
__import__(pdbmap[debugger]) |
19773
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
53 |
except ImportError: |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
54 |
ui.warn("%s debugger specified but %s module was not found\n" |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
55 |
% (debugger, pdbmap[debugger])) |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
56 |
debugger = 'pdb' |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
57 |
|
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
58 |
getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts) |