Skip to content

Commit c689e74

Browse files
committed
Fix flake8 issues
This commit contains a very large number of trivial changes in order to fix flake8 errors and warnings. Predominantly these are whitespace changes. Additionally, the build for Python 3.7 on TravisCI has been tweaked to fail if there are any flake8 errors using the following commandline: * flake8 . --count --ignore=E252 --max-complexity=31 --max-line-length=127 --show-source --statistics NOTE: In the future the max cyclomatic complexity should be lowered, but some improvements need to be made first. One flake8 error is being ignored entirely: * E252 missing whitespace around parameter equals * ignored because it doesn't correctly deal with default argument values after a type hint A few flake8 errors are being selectively ignored in certain files: * C901 fuction is too complex * ignored in argparse_completer.py because the complex code is an override of argparse complexity * E302 expected 2 blank lines after ... * ignored in all unit test files for convenience * F401 module imported but unused * ignored in cmd2/__init__.py because imports are for convenience of cmd2 developers and backwards compatibility * F821 undefined name * ignored in cmd2 script files which are intended to run only within cmd2 applications via pyscript where "app" and "cmd" are defined
1 parent 709af49 commit c689e74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+124
-95
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ before_script:
4646
# stop the build if there are Python syntax errors or undefined names
4747
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
4848
if [[ $TOXENV == py37 ]]; then
49-
flake8 . --count --exclude=./.*,./examples,./tests --select=E901,E999,F821,F822,F823 --show-source --statistics ;
50-
flake8 . --count --exclude=./.* --exit-zero --max-complexity=10 --max-line-length=127 --statistics ;
49+
flake8 . --count --ignore=E252 --max-complexity=31 --max-line-length=127 --show-source --statistics ;
5150
fi
5251

5352
script:

cmd2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
22
# -*- coding: utf-8 -*-
3+
# flake8: noqa F401
34
"""This simply imports certain things for backwards compatibility."""
45

56
from pkg_resources import get_distribution, DistributionNotFound

cmd2/argcomplete_bridge.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from . import constants
2929
from . import utils
3030

31-
3231
def tokens_for_completion(line: str, endidx: int) -> Union[Tuple[List[str], List[str], int, int],
3332
Tuple[None, None, None, None]]:
3433
"""
@@ -254,7 +253,6 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
254253
argcomplete.debug_stream.flush()
255254
exit_method(0)
256255

257-
258256
def bash_complete(action, show_hint: bool = True):
259257
"""Helper function to configure an argparse action to fall back to bash completion.
260258

cmd2/argparse_completer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# coding=utf-8
2+
# flake8: noqa C901
3+
# NOTE: Ignoreing flake8 cyclomatic complexity in this file because the complexity due to copy-and-paste overrides from
4+
# argparse
25
"""
36
AutoCompleter interprets the argparse.ArgumentParser internals to automatically
47
generate the completion options for each argument.
@@ -595,15 +598,15 @@ def _format_completions(self, action, completions: List[Union[str, CompletionIte
595598
fill_width = int(term_size.columns * .6) - (token_width + 2)
596599
for item in completions:
597600
entry = '{: <{token_width}}{: <{fill_width}}'.format(item, item.description,
598-
token_width=token_width+2,
601+
token_width=token_width + 2,
599602
fill_width=fill_width)
600603
completions_with_desc.append(entry)
601604

602605
try:
603606
desc_header = action.desc_header
604607
except AttributeError:
605608
desc_header = 'Description'
606-
header = '\n{: <{token_width}}{}'.format(action.dest.upper(), desc_header, token_width=token_width+2)
609+
header = '\n{: <{token_width}}{}'.format(action.dest.upper(), desc_header, token_width=token_width + 2)
607610

608611
self._cmd2_app.completion_header = header
609612
self._cmd2_app.display_matches = completions_with_desc

cmd2/parsing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,14 @@ def parse(self, line: str) -> Statement:
400400

401401
if terminator:
402402
if terminator == constants.LINE_FEED:
403-
terminator_pos = len(tokens)+1
403+
terminator_pos = len(tokens) + 1
404404

405405
# everything before the first terminator is the command and the args
406406
(command, args) = self._command_and_args(tokens[:terminator_pos])
407407
arg_list = tokens[1:terminator_pos]
408408
# we will set the suffix later
409409
# remove all the tokens before and including the terminator
410-
tokens = tokens[terminator_pos+1:]
410+
tokens = tokens[terminator_pos + 1:]
411411
else:
412412
(testcommand, testargs) = self._command_and_args(tokens)
413413
if testcommand in self.multiline_commands:
@@ -427,7 +427,7 @@ def parse(self, line: str) -> Statement:
427427
# find the first pipe if it exists
428428
pipe_pos = tokens.index(constants.REDIRECTION_PIPE)
429429
# save everything after the first pipe as tokens
430-
pipe_to = tokens[pipe_pos+1:]
430+
pipe_to = tokens[pipe_pos + 1:]
431431

432432
for pos, cur_token in enumerate(pipe_to):
433433
unquoted_token = utils.strip_quotes(cur_token)

cmd2/pyscript_bridge.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
"""
99

1010
import argparse
11-
import functools
1211
import sys
13-
from typing import List, Callable, Optional
12+
from typing import List, Optional
1413

1514
from .argparse_completer import _RangeAction, is_potential_flag
1615
from .utils import namedtuple_with_defaults, StdSim, quote_string_if_needed

cmd2/rl_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ def enable_win_vt100(handle: HANDLE) -> bool:
7171
# Enable VT100 sequences for stdout and stderr
7272
STD_OUT_HANDLE = -11
7373
STD_ERROR_HANDLE = -12
74-
vt100_support = (enable_win_vt100(readline.rl.console.GetStdHandle(STD_OUT_HANDLE)) and
75-
enable_win_vt100(readline.rl.console.GetStdHandle(STD_ERROR_HANDLE)))
74+
vt100_stdout_support = enable_win_vt100(readline.rl.console.GetStdHandle(STD_OUT_HANDLE))
75+
vt100_stderr_support = enable_win_vt100(readline.rl.console.GetStdHandle(STD_ERROR_HANDLE))
76+
vt100_support = vt100_stdout_support and vt100_stderr_support
7677

7778
############################################################################################################
7879
# pyreadline is incomplete in terms of the Python readline API. Add the missing functions we need.

cmd2/transcript.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def _test_transcript(self, fname: str, transcript):
7777
try:
7878
line = next(transcript)
7979
except StopIteration as exc:
80-
msg = 'Transcript broke off while reading command beginning at line {} with\n{}'.format(line_num, command[0])
80+
msg = 'Transcript broke off while reading command beginning at line {} with\n{}'.format(line_num,
81+
command[0])
8182
raise StopIteration(msg) from exc
8283
line_num += 1
8384
command = ''.join(command)
@@ -138,7 +139,7 @@ def _transform_transcript_expected(self, s: str) -> str:
138139
# there is a slash, add everything we have found so far
139140
# add stuff before the first slash as plain text
140141
regex += re.escape(s[start:first_slash_pos])
141-
start = first_slash_pos+1
142+
start = first_slash_pos + 1
142143
# and go find the next one
143144
(regex, second_slash_pos, start) = self._escaped_find(regex, s, start, True)
144145
if second_slash_pos > 0:
@@ -151,7 +152,7 @@ def _transform_transcript_expected(self, s: str) -> str:
151152
else:
152153
# No closing slash, we have to add the first slash,
153154
# and the rest of the text
154-
regex += re.escape(s[start-1:])
155+
regex += re.escape(s[start - 1:])
155156
break
156157
return regex
157158

@@ -178,24 +179,24 @@ def _escaped_find(regex: str, s: str, start: int, in_regex: bool) -> Tuple[str,
178179
break
179180
else:
180181
# check if the slash is preceeded by a backslash
181-
if s[pos-1:pos] == '\\':
182+
if s[pos - 1:pos] == '\\':
182183
# it is.
183184
if in_regex:
184185
# add everything up to the backslash as a
185186
# regular expression
186-
regex += s[start:pos-1]
187+
regex += s[start:pos - 1]
187188
# skip the backslash, and add the slash
188189
regex += s[pos]
189190
else:
190191
# add everything up to the backslash as escaped
191192
# plain text
192-
regex += re.escape(s[start:pos-1])
193+
regex += re.escape(s[start:pos - 1])
193194
# and then add the slash as escaped
194195
# plain text
195196
regex += re.escape(s[pos])
196197
# update start to show we have handled everything
197198
# before it
198-
start = pos+1
199+
start = pos + 1
199200
# and continue to look
200201
else:
201202
# slash is not escaped, this is what we are looking for

docs/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"""
2020
import os
2121
import sys
22+
23+
from pkg_resources import get_distribution
24+
2225
# Import for custom theme from Read the Docs
2326
import sphinx_rtd_theme
2427

@@ -59,7 +62,6 @@
5962
# |version| and |release|, also used in various other places throughout the
6063
# built documents.
6164
#
62-
from pkg_resources import get_distribution
6365
# version will look like x.y.z
6466
version = get_distribution('cmd2').version
6567
# release will look like x.y

examples/alias_startup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import cmd2
99

10+
1011
class AliasAndStartup(cmd2.Cmd):
1112
""" Example cmd2 application where we create commands that just print the arguments they are called with."""
1213

0 commit comments

Comments
 (0)