diff options
Diffstat (limited to 'cmd2')
-rw-r--r-- | cmd2/__init__.py | 1 | ||||
-rw-r--r-- | cmd2/argcomplete_bridge.py | 2 | ||||
-rw-r--r-- | cmd2/argparse_completer.py | 7 | ||||
-rw-r--r-- | cmd2/parsing.py | 6 | ||||
-rw-r--r-- | cmd2/pyscript_bridge.py | 3 | ||||
-rw-r--r-- | cmd2/rl_utils.py | 5 | ||||
-rw-r--r-- | cmd2/transcript.py | 15 |
7 files changed, 21 insertions, 18 deletions
diff --git a/cmd2/__init__.py b/cmd2/__init__.py index 2de297d3..1072a3c7 100644 --- a/cmd2/__init__.py +++ b/cmd2/__init__.py @@ -1,5 +1,6 @@ # # -*- coding: utf-8 -*- +# flake8: noqa F401 """This simply imports certain things for backwards compatibility.""" from pkg_resources import get_distribution, DistributionNotFound diff --git a/cmd2/argcomplete_bridge.py b/cmd2/argcomplete_bridge.py index 51e856ef..885cea31 100644 --- a/cmd2/argcomplete_bridge.py +++ b/cmd2/argcomplete_bridge.py @@ -28,7 +28,6 @@ else: from . import constants from . import utils - def tokens_for_completion(line: str, endidx: int) -> Union[Tuple[List[str], List[str], int, int], Tuple[None, None, None, None]]: """ @@ -254,7 +253,6 @@ else: argcomplete.debug_stream.flush() exit_method(0) - def bash_complete(action, show_hint: bool = True): """Helper function to configure an argparse action to fall back to bash completion. diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py index 77a62b9d..18549e9e 100644 --- a/cmd2/argparse_completer.py +++ b/cmd2/argparse_completer.py @@ -1,4 +1,7 @@ # coding=utf-8 +# flake8: noqa C901 +# NOTE: Ignoreing flake8 cyclomatic complexity in this file because the complexity due to copy-and-paste overrides from +# argparse """ AutoCompleter interprets the argparse.ArgumentParser internals to automatically generate the completion options for each argument. @@ -595,7 +598,7 @@ class AutoCompleter(object): fill_width = int(term_size.columns * .6) - (token_width + 2) for item in completions: entry = '{: <{token_width}}{: <{fill_width}}'.format(item, item.description, - token_width=token_width+2, + token_width=token_width + 2, fill_width=fill_width) completions_with_desc.append(entry) @@ -603,7 +606,7 @@ class AutoCompleter(object): desc_header = action.desc_header except AttributeError: desc_header = 'Description' - header = '\n{: <{token_width}}{}'.format(action.dest.upper(), desc_header, token_width=token_width+2) + header = '\n{: <{token_width}}{}'.format(action.dest.upper(), desc_header, token_width=token_width + 2) self._cmd2_app.completion_header = header self._cmd2_app.display_matches = completions_with_desc diff --git a/cmd2/parsing.py b/cmd2/parsing.py index d5c67ae0..d4f82ac9 100644 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -400,14 +400,14 @@ class StatementParser: if terminator: if terminator == constants.LINE_FEED: - terminator_pos = len(tokens)+1 + terminator_pos = len(tokens) + 1 # everything before the first terminator is the command and the args (command, args) = self._command_and_args(tokens[:terminator_pos]) arg_list = tokens[1:terminator_pos] # we will set the suffix later # remove all the tokens before and including the terminator - tokens = tokens[terminator_pos+1:] + tokens = tokens[terminator_pos + 1:] else: (testcommand, testargs) = self._command_and_args(tokens) if testcommand in self.multiline_commands: @@ -427,7 +427,7 @@ class StatementParser: # find the first pipe if it exists pipe_pos = tokens.index(constants.REDIRECTION_PIPE) # save everything after the first pipe as tokens - pipe_to = tokens[pipe_pos+1:] + pipe_to = tokens[pipe_pos + 1:] for pos, cur_token in enumerate(pipe_to): unquoted_token = utils.strip_quotes(cur_token) diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py index 402dfeac..6a18fc6a 100644 --- a/cmd2/pyscript_bridge.py +++ b/cmd2/pyscript_bridge.py @@ -8,9 +8,8 @@ Released under MIT license, see LICENSE file """ import argparse -import functools import sys -from typing import List, Callable, Optional +from typing import List, Optional from .argparse_completer import _RangeAction, is_potential_flag from .utils import namedtuple_with_defaults, StdSim, quote_string_if_needed diff --git a/cmd2/rl_utils.py b/cmd2/rl_utils.py index 0819232d..fdddca0b 100644 --- a/cmd2/rl_utils.py +++ b/cmd2/rl_utils.py @@ -71,8 +71,9 @@ if 'pyreadline' in sys.modules: # Enable VT100 sequences for stdout and stderr STD_OUT_HANDLE = -11 STD_ERROR_HANDLE = -12 - vt100_support = (enable_win_vt100(readline.rl.console.GetStdHandle(STD_OUT_HANDLE)) and - enable_win_vt100(readline.rl.console.GetStdHandle(STD_ERROR_HANDLE))) + vt100_stdout_support = enable_win_vt100(readline.rl.console.GetStdHandle(STD_OUT_HANDLE)) + vt100_stderr_support = enable_win_vt100(readline.rl.console.GetStdHandle(STD_ERROR_HANDLE)) + vt100_support = vt100_stdout_support and vt100_stderr_support ############################################################################################################ # pyreadline is incomplete in terms of the Python readline API. Add the missing functions we need. diff --git a/cmd2/transcript.py b/cmd2/transcript.py index fe43188f..6a954bce 100644 --- a/cmd2/transcript.py +++ b/cmd2/transcript.py @@ -77,7 +77,8 @@ class Cmd2TestCase(unittest.TestCase): try: line = next(transcript) except StopIteration as exc: - msg = 'Transcript broke off while reading command beginning at line {} with\n{}'.format(line_num, command[0]) + msg = 'Transcript broke off while reading command beginning at line {} with\n{}'.format(line_num, + command[0]) raise StopIteration(msg) from exc line_num += 1 command = ''.join(command) @@ -138,7 +139,7 @@ class Cmd2TestCase(unittest.TestCase): # there is a slash, add everything we have found so far # add stuff before the first slash as plain text regex += re.escape(s[start:first_slash_pos]) - start = first_slash_pos+1 + start = first_slash_pos + 1 # and go find the next one (regex, second_slash_pos, start) = self._escaped_find(regex, s, start, True) if second_slash_pos > 0: @@ -151,7 +152,7 @@ class Cmd2TestCase(unittest.TestCase): else: # No closing slash, we have to add the first slash, # and the rest of the text - regex += re.escape(s[start-1:]) + regex += re.escape(s[start - 1:]) break return regex @@ -178,24 +179,24 @@ class Cmd2TestCase(unittest.TestCase): break else: # check if the slash is preceeded by a backslash - if s[pos-1:pos] == '\\': + if s[pos - 1:pos] == '\\': # it is. if in_regex: # add everything up to the backslash as a # regular expression - regex += s[start:pos-1] + regex += s[start:pos - 1] # skip the backslash, and add the slash regex += s[pos] else: # add everything up to the backslash as escaped # plain text - regex += re.escape(s[start:pos-1]) + regex += re.escape(s[start:pos - 1]) # and then add the slash as escaped # plain text regex += re.escape(s[pos]) # update start to show we have handled everything # before it - start = pos+1 + start = pos + 1 # and continue to look else: # slash is not escaped, this is what we are looking for |