From cfee7997fcc6833122dc38d59194525bd2628207 Mon Sep 17 00:00:00 2001 From: Hugo Wang Date: Sun, 11 Dec 2016 19:32:35 +0800 Subject: [PATCH 1/6] update info print of debug level --- xonsh/execer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xonsh/execer.py b/xonsh/execer.py index 61081cc67..19f59744a 100644 --- a/xonsh/execer.py +++ b/xonsh/execer.py @@ -221,7 +221,7 @@ class Execer(object): # anything raise original_error else: - if self.debug_level: + if self.debug_level > 1: msg = ('{0}:{1}:{2}{3} - {4}\n' '{0}:{1}:{2}{3} + {5}') mstr = '' if maxcol is None else ':' + str(maxcol) From 6926a21b9c9a09a61e038d2d66625479b52a4d76 Mon Sep 17 00:00:00 2001 From: Hugo Wang Date: Thu, 15 Dec 2016 22:30:26 +0800 Subject: [PATCH 2/6] updated XONSH_DEBUG debug levels --- xonsh/environ.py | 13 ++++++++----- xonsh/execer.py | 4 ++-- xonsh/foreign_shells.py | 2 +- xonsh/shell.py | 3 ++- xonsh/xontribs.json | 2 +- xontrib/bashisms.py | 2 ++ 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/xonsh/environ.py b/xonsh/environ.py index 5a6087674..6fb8ba677 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -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``"), diff --git a/xonsh/execer.py b/xonsh/execer.py index 19f59744a..f837c375e 100644 --- a/xonsh/execer.py +++ b/xonsh/execer.py @@ -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: diff --git a/xonsh/foreign_shells.py b/xonsh/foreign_shells.py index d2d6d2cf9..760067a54 100644 --- a/xonsh/foreign_shells.py +++ b/xonsh/foreign_shells.py @@ -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']), diff --git a/xonsh/shell.py b/xonsh/shell.py index 26deec218..d60af2149 100644 --- a/xonsh/shell.py +++ b/xonsh/shell.py @@ -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), diff --git a/xonsh/xontribs.json b/xonsh/xontribs.json index 2a60c329a..9596edfb4 100644 --- a/xonsh/xontribs.json +++ b/xonsh/xontribs.json @@ -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", diff --git a/xontrib/bashisms.py b/xontrib/bashisms.py index 0fd4e97e3..06e7c15de 100644 --- a/xontrib/bashisms.py +++ b/xontrib/bashisms.py @@ -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()) From 31bf0a52d27fe06cd1bfa59cc6be9a6f730538a8 Mon Sep 17 00:00:00 2001 From: Hugo Wang Date: Thu, 15 Dec 2016 22:41:06 +0800 Subject: [PATCH 3/6] minor doc update --- xonsh/environ.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xonsh/environ.py b/xonsh/environ.py index 6fb8ba677..39d5e2eb8 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -618,9 +618,9 @@ def DEFAULT_DOCS(): '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. ' + 'basic information like input transformation, command replacement. ' 'With ``3`` or a higher number will make more debugging information ' - 'presented, like PLY debug messages.', + 'presented, like PLY parsing messages.', configurable=False), 'XONSH_DATA_DIR': VarDocs( 'This is the location where xonsh data files are stored, such as ' From b47aabf654b6a759262a865513eb0e4847f16eed Mon Sep 17 00:00:00 2001 From: Hugo Wang Date: Thu, 15 Dec 2016 22:54:45 +0800 Subject: [PATCH 4/6] updated for ut --- xontrib/bashisms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xontrib/bashisms.py b/xontrib/bashisms.py index 06e7c15de..b25b82a52 100644 --- a/xontrib/bashisms.py +++ b/xontrib/bashisms.py @@ -3,6 +3,8 @@ @events.on_precommand def bash_preproc(cmd): - if len(__xonsh_history__) == 0: + if not __xonsh_history__.inps: + if cmd.strip() == '!!': + return '' return cmd return cmd.replace('!!', __xonsh_history__.inps[-1].strip()) From afcd76a5ae25dd819f0a3bbd9d94c074200f0456 Mon Sep 17 00:00:00 2001 From: Hugo Wang Date: Thu, 15 Dec 2016 22:59:07 +0800 Subject: [PATCH 5/6] added a news item --- news/xonsh-debug-level.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 news/xonsh-debug-level.rst diff --git a/news/xonsh-debug-level.rst b/news/xonsh-debug-level.rst new file mode 100644 index 000000000..ef54ae7ea --- /dev/null +++ b/news/xonsh-debug-level.rst @@ -0,0 +1,13 @@ +**Added:** None + +**Changed:** + +* Updated the effectivity of ``$XONSH_DEBUG`` on debug messages. + +**Deprecated:** None + +**Removed:** None + +**Fixed:** None + +**Security:** None From c41a3512e408a2bbb4473f1cdcec3ae925d6623d Mon Sep 17 00:00:00 2001 From: Hugo Wang Date: Fri, 16 Dec 2016 09:00:18 +0800 Subject: [PATCH 6/6] code clean --- xonsh/foreign_shells.py | 2 +- xonsh/shell.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xonsh/foreign_shells.py b/xonsh/foreign_shells.py index 760067a54..20e5a2e71 100644 --- a/xonsh/foreign_shells.py +++ b/xonsh/foreign_shells.py @@ -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', False) > 1: + if builtins.__xonsh_env__.get('XONSH_DEBUG') > 1: print('aliases: ignoring alias {!r} of shell {!r} ' 'which tries to override xonsh alias.' ''.format(alias, shell['shell']), diff --git a/xonsh/shell.py b/xonsh/shell.py index d60af2149..a1c52f6d1 100644 --- a/xonsh/shell.py +++ b/xonsh/shell.py @@ -49,7 +49,7 @@ def fire_precommand(src, show_diff=True): print_exception('Modifcations to source input took more than ' 'the recursion limit number of interations to ' 'converge.') - debug_level = builtins.__xonsh_env__.get('XONSH_DEBUG', 0) + debug_level = builtins.__xonsh_env__.get('XONSH_DEBUG') if show_diff and debug_level > 1 and src != raw: sys.stderr.writelines(difflib.unified_diff( raw.splitlines(keepends=True),