Mercurial > public > mercurial-scm > hg-stable
comparison contrib/debugshell.py @ 41819:b10bbbe995eb
py3: make contrib/debugshell.py work with Python 3
I changed default mercurial installation of my personal laptop to one installed
with python 3.7. debugshell is one of the extension which I have enabled and it
was failing. This patch makes debugshell works with Python 3.
I found that chg does not work with python 3.
Differential Revision: https://phab.mercurial-scm.org/D6031
author | Pulkit Goyal <pulkit@yandex-team.ru> |
---|---|
date | Thu, 28 Feb 2019 03:48:07 +0530 |
parents | aaad36b88298 |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
41818:b38c7304974f | 41819:b10bbbe995eb |
---|---|
5 import code | 5 import code |
6 import mercurial | 6 import mercurial |
7 import sys | 7 import sys |
8 from mercurial import ( | 8 from mercurial import ( |
9 demandimport, | 9 demandimport, |
10 pycompat, | |
10 registrar, | 11 registrar, |
11 ) | 12 ) |
12 | 13 |
13 cmdtable = {} | 14 cmdtable = {} |
14 command = registrar.command(cmdtable) | 15 command = registrar.command(cmdtable) |
30 mf = repo.manifestlog | 31 mf = repo.manifestlog |
31 cl, mf # use variables to appease pyflakes | 32 cl, mf # use variables to appease pyflakes |
32 | 33 |
33 IPython.embed() | 34 IPython.embed() |
34 | 35 |
35 @command('debugshell|dbsh', []) | 36 @command(b'debugshell|dbsh', []) |
36 def debugshell(ui, repo, **opts): | 37 def debugshell(ui, repo, **opts): |
37 bannermsg = ("loaded repo : %s\n" | 38 bannermsg = ("loaded repo : %s\n" |
38 "using source: %s" % (repo.root, | 39 "using source: %s" % (pycompat.sysstr(repo.root), |
39 mercurial.__path__[0])) | 40 mercurial.__path__[0])) |
40 | 41 |
41 pdbmap = { | 42 pdbmap = { |
42 'pdb' : 'code', | 43 'pdb' : 'code', |
43 'ipdb' : 'IPython' | 44 'ipdb' : 'IPython' |
44 } | 45 } |
45 | 46 |
46 debugger = ui.config("ui", "debugger") | 47 debugger = ui.config(b"ui", b"debugger") |
47 if not debugger: | 48 if not debugger: |
48 debugger = 'pdb' | 49 debugger = 'pdb' |
50 else: | |
51 debugger = pycompat.sysstr(debugger) | |
49 | 52 |
50 # if IPython doesn't exist, fallback to code.interact | 53 # if IPython doesn't exist, fallback to code.interact |
51 try: | 54 try: |
52 with demandimport.deactivated(): | 55 with demandimport.deactivated(): |
53 __import__(pdbmap[debugger]) | 56 __import__(pdbmap[debugger]) |
54 except ImportError: | 57 except ImportError: |
55 ui.warn(("%s debugger specified but %s module was not found\n") | 58 ui.warn((b"%s debugger specified but %s module was not found\n") |
56 % (debugger, pdbmap[debugger])) | 59 % (debugger, pdbmap[debugger])) |
57 debugger = 'pdb' | 60 debugger = b'pdb' |
58 | 61 |
59 getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts) | 62 getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts) |