updated XONSH_DEBUG debug levels

This commit is contained in:
Hugo Wang 2016-12-15 22:30:26 +08:00
parent cfee7997fc
commit 6926a21b9c
6 changed files with 16 additions and 10 deletions

View file

@ -298,7 +298,7 @@ def DEFAULT_VALUES():
'XONSH_COLOR_STYLE': 'default',
'XONSH_CONFIG_DIR': xonsh_config_dir,
'XONSH_DATA_DIR': xonsh_data_dir,
'XONSH_DEBUG': False,
'XONSH_DEBUG': 0,
'XONSH_ENCODING': DEFAULT_ENCODING,
'XONSH_ENCODING_ERRORS': 'surrogateescape',
'XONSH_HISTORY_BACKEND': 'json',
@ -615,10 +615,13 @@ def DEFAULT_DOCS():
'This is the location where xonsh configuration information is stored.',
configurable=False, default="``$XDG_CONFIG_HOME/xonsh``"),
'XONSH_DEBUG': VarDocs(
'Sets the xonsh debugging level. This may be an integer or a boolean, '
'with higher values cooresponding to higher debuging levels and more '
'information presented. Setting this variable prior to stating xonsh '
'will supress amalgamated imports.', configurable=False),
'Sets the xonsh debugging level. This may be an integer or a boolean. '
'Setting this variable prior to stating xonsh to ``1`` or ``True`` '
'will supress amalgamated imports. Setting it to ``2`` will get some '
'basic information like code transformation, command replacement. '
'With ``3`` or a higher number will make more debugging information '
'presented, like PLY debug messages.',
configurable=False),
'XONSH_DATA_DIR': VarDocs(
'This is the location where xonsh data files are stored, such as '
'history.', default="``$XDG_DATA_HOME/xonsh``"),

View file

@ -54,7 +54,7 @@ class Execer(object):
filename = self.filename
if not transform:
return self.parser.parse(input, filename=filename, mode=mode,
debug_level=(self.debug_level > 1))
debug_level=(self.debug_level > 2))
# Parsing actually happens in a couple of phases. The first is a
# shortcut for a context-free parser. Normally, all subprocess
@ -161,7 +161,7 @@ class Execer(object):
tree = self.parser.parse(input,
filename=filename,
mode=mode,
debug_level=(self.debug_level > 1))
debug_level=(self.debug_level > 2))
parsed = True
except IndentationError as e:
if original_error is None:

View file

@ -584,7 +584,7 @@ def load_foreign_aliases(shells=None, config=None, issue_warning=True):
shaliases = {} if shaliases is None else shaliases
for alias in set(shaliases) & set(xonsh_aliases):
del shaliases[alias]
if builtins.__xonsh_env__.get('XONSH_DEBUG'):
if builtins.__xonsh_env__.get('XONSH_DEBUG', False) > 1:
print('aliases: ignoring alias {!r} of shell {!r} '
'which tries to override xonsh alias.'
''.format(alias, shell['shell']),

View file

@ -49,7 +49,8 @@ def fire_precommand(src, show_diff=True):
print_exception('Modifcations to source input took more than '
'the recursion limit number of interations to '
'converge.')
if show_diff and builtins.__xonsh_env__.get('XONSH_DEBUG') and src != raw:
debug_level = builtins.__xonsh_env__.get('XONSH_DEBUG', 0)
if show_diff and debug_level > 1 and src != raw:
sys.stderr.writelines(difflib.unified_diff(
raw.splitlines(keepends=True),
src.splitlines(keepends=True),

View file

@ -21,7 +21,7 @@
"you might find them useful if you have strong muscle memory.\n\n",
"**Warning:** This xontrib may modify user command line input to implement ",
"its behavior. To see the modifications as they are applied (in unified diff",
"format), please set ``$XONSH_DEBUG = True``."]
"format), please set ``$XONSH_DEBUG`` to ``2`` or higher."]
},
{"name": "distributed",
"package": "xonsh",

View file

@ -3,4 +3,6 @@
@events.on_precommand
def bash_preproc(cmd):
if len(__xonsh_history__) == 0:
return cmd
return cmd.replace('!!', __xonsh_history__.inps[-1].strip())