Mercurial > hg
view contrib/debugshell.py @ 38727:fcb517ff9562
debug: move extensions debug behind a dedicated flag
Since b86664c81833, we process the `--debug` flag earlier. This is overall
good and useful, but has at least one negative side effect.
Previously the debug message we report when trying to import extensions were
issued before we processed the `--debug` flag. Now they happen after.
Before:
$ ./hg id --debug
21f507b8de2f9c1606e9aeb5ec7d2a6dedb7a4a7 tip
After:
$ ./hg id --debug ☿ (revset-bench)
could not import hgext.evolve (No module named evolve): trying hgext3rd.evolve
could not import hgext.mercurial_keyring (No module named mercurial_keyring): trying hgext3rd.mercurial_keyring
could not import hgext3rd.mercurial_keyring (No module named mercurial_keyring): trying mercurial_keyring
could not import hgext.hggit (No module named hggit): trying hgext3rd.hggit
could not import hgext3rd.hggit (No module named hggit): trying hggit
21f507b8de2f9c1606e9aeb5ec7d2a6dedb7a4a7 tip
(This get worse if --traceback is used).
To work around this, we move this extensions related debug message behind a
new flag 'devel.debug.extensions' and restore the previous output.
I'm not fully happy about using the 'devel' section for a flag that can be
used by legitimate users to debug extensions issues. However, it fits well
next to other `devel.devel.*` options and is mostly used by extensions author
anyway.
We might move it to another, more appropriate section in the future (using
alias).
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Mon, 16 Jul 2018 18:02:30 +0200 |
parents | 46ba2cdda476 |
children | aaad36b88298 |
line wrap: on
line source
# debugshell extension """a python shell with repo, changelog & manifest objects""" from __future__ import absolute_import import code import mercurial import sys from mercurial import ( demandimport, registrar, ) cmdtable = {} command = registrar.command(cmdtable) def pdb(ui, repo, msg, **opts): objects = { 'mercurial': mercurial, 'repo': repo, 'cl': repo.changelog, 'mf': repo.manifestlog, } code.interact(msg, local=objects) def ipdb(ui, repo, msg, **opts): import IPython cl = repo.changelog mf = repo.manifestlog cl, mf # use variables to appease pyflakes IPython.embed() @command('debugshell|dbsh', []) def debugshell(ui, repo, **opts): bannermsg = "loaded repo : %s\n" \ "using source: %s" % (repo.root, mercurial.__path__[0]) pdbmap = { 'pdb' : 'code', 'ipdb' : 'IPython' } debugger = ui.config("ui", "debugger") if not debugger: debugger = 'pdb' # if IPython doesn't exist, fallback to code.interact try: with demandimport.deactivated(): __import__(pdbmap[debugger]) except ImportError: ui.warn(("%s debugger specified but %s module was not found\n") % (debugger, pdbmap[debugger])) debugger = 'pdb' getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts)