Mercurial > public > mercurial-scm > hg
comparison contrib/debugshell.py @ 27721:e4b512bb6386
debugshell: disable demand importer when importing debugger
For reasons I can't explain (but likely have something to do with a
combination of __import__ inferring default values for arguments and
the demand importer mechanism further assuming defaults), the demand
importer isn't playing well with IPython. Without this patch, we get
a failure "ValueError: Attempted relative import in non-package" when
attempting to import "IPython." The stack has numerous demandimport
calls on it and adding "IPython" to the exclude list in demandimport
isn't enough to make the problem go away, which means the issue is
likely somewhere in the bowells of IPython. It's easier to just disable
the demand importer when importing the debugger.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 11 Jan 2016 18:16:38 -0800 |
parents | 8b5c039f2b4f |
children | e28dc6de38e7 |
comparison
equal
deleted
inserted
replaced
27720:89f49813526c | 27721:e4b512bb6386 |
---|---|
2 """a python shell with repo, changelog & manifest objects""" | 2 """a python shell with repo, changelog & manifest objects""" |
3 | 3 |
4 import sys | 4 import sys |
5 import mercurial | 5 import mercurial |
6 import code | 6 import code |
7 from mercurial import cmdutil | 7 from mercurial import ( |
8 cmdutil, | |
9 demandimport, | |
10 ) | |
8 | 11 |
9 cmdtable = {} | 12 cmdtable = {} |
10 command = cmdutil.command(cmdtable) | 13 command = cmdutil.command(cmdtable) |
11 | 14 |
12 def pdb(ui, repo, msg, **opts): | 15 def pdb(ui, repo, msg, **opts): |
43 if not debugger: | 46 if not debugger: |
44 debugger = 'pdb' | 47 debugger = 'pdb' |
45 | 48 |
46 # if IPython doesn't exist, fallback to code.interact | 49 # if IPython doesn't exist, fallback to code.interact |
47 try: | 50 try: |
48 __import__(pdbmap[debugger]) | 51 with demandimport.deactivated(): |
52 __import__(pdbmap[debugger]) | |
49 except ImportError: | 53 except ImportError: |
50 ui.warn("%s debugger specified but %s module was not found\n" | 54 ui.warn("%s debugger specified but %s module was not found\n" |
51 % (debugger, pdbmap[debugger])) | 55 % (debugger, pdbmap[debugger])) |
52 debugger = 'pdb' | 56 debugger = 'pdb' |
53 | 57 |