diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-12-06 01:24:19 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-12-06 01:24:19 -0500 |
commit | c689e74fed45bf1a7b2908defc343d35f31dff71 (patch) | |
tree | 3c1904debb429274d2fac316300a8b75b200a66c | |
parent | 709af49a7f161c98260cc5ddda736987fb0f1f23 (diff) | |
download | cmd2-git-c689e74fed45bf1a7b2908defc343d35f31dff71.tar.gz |
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
58 files changed, 124 insertions, 95 deletions
diff --git a/.travis.yml b/.travis.yml index e536cb34..fda08075 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,8 +46,7 @@ before_script: # stop the build if there are Python syntax errors or undefined names # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide if [[ $TOXENV == py37 ]]; then - flake8 . --count --exclude=./.*,./examples,./tests --select=E901,E999,F821,F822,F823 --show-source --statistics ; - flake8 . --count --exclude=./.* --exit-zero --max-complexity=10 --max-line-length=127 --statistics ; + flake8 . --count --ignore=E252 --max-complexity=31 --max-line-length=127 --show-source --statistics ; fi script: 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 diff --git a/docs/conf.py b/docs/conf.py index 2c75e14e..f22a117d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -19,6 +19,9 @@ documentation root, use os.path.abspath to make it absolute, like shown here. """ import os import sys + +from pkg_resources import get_distribution + # Import for custom theme from Read the Docs import sphinx_rtd_theme @@ -59,7 +62,6 @@ author = 'Catherine Devlin and Todd Leonhardt' # |version| and |release|, also used in various other places throughout the # built documents. # -from pkg_resources import get_distribution # version will look like x.y.z version = get_distribution('cmd2').version # release will look like x.y diff --git a/examples/alias_startup.py b/examples/alias_startup.py index 8a289e79..7c70bcd9 100755 --- a/examples/alias_startup.py +++ b/examples/alias_startup.py @@ -7,6 +7,7 @@ import os import cmd2 + class AliasAndStartup(cmd2.Cmd): """ Example cmd2 application where we create commands that just print the arguments they are called with.""" diff --git a/examples/arg_print.py b/examples/arg_print.py index f2168126..1a103858 100755 --- a/examples/arg_print.py +++ b/examples/arg_print.py @@ -13,6 +13,7 @@ import argparse import cmd2 + class ArgumentAndOptionPrinter(cmd2.Cmd): """ Example cmd2 application where we create commands that just print the arguments they are called with.""" @@ -52,6 +53,7 @@ class ArgumentAndOptionPrinter(cmd2.Cmd): pprint_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay') pprint_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE') pprint_parser.add_argument('-r', '--repeat', type=int, help='output [n] times') + @cmd2.with_argparser_and_unknown_args(pprint_parser) def do_pprint(self, args, unknown): """Print the options and argument list this options command was called with.""" diff --git a/examples/bash_completion.py b/examples/bash_completion.py index 6a5a2a89..b70761e2 100755 --- a/examples/bash_completion.py +++ b/examples/bash_completion.py @@ -60,7 +60,7 @@ except ImportError: pass # Intentionally below the bash completion code to reduce tab completion lag -import cmd2 +import cmd2 # noqa: E402 class DummyApp(cmd2.Cmd): diff --git a/examples/cmd_as_argument.py b/examples/cmd_as_argument.py index eb46eedf..070a34a0 100755 --- a/examples/cmd_as_argument.py +++ b/examples/cmd_as_argument.py @@ -111,4 +111,4 @@ def main(argv=None): if __name__ == '__main__': - sys.exit(main())
\ No newline at end of file + sys.exit(main()) diff --git a/examples/decorator_example.py b/examples/decorator_example.py index 5b8b303b..bd9228db 100755 --- a/examples/decorator_example.py +++ b/examples/decorator_example.py @@ -71,7 +71,6 @@ class CmdLineApp(cmd2.Cmd): """create a html tag""" self.poutput('<{0}>{1}</{0}>'.format(args.tag, ' '.join(args.content))) - @cmd2.with_argument_list def do_tagg(self, arglist): """verion of creating an html tag using arglist instead of argparser""" diff --git a/examples/help_categories.py b/examples/help_categories.py index b4a2c977..50b2c17d 100755 --- a/examples/help_categories.py +++ b/examples/help_categories.py @@ -8,6 +8,7 @@ import argparse import cmd2 + class HelpCategories(cmd2.Cmd): """ Example cmd2 application. """ @@ -81,14 +82,14 @@ class HelpCategories(cmd2.Cmd): # Tag the above command functions under the category Application Management cmd2.categorize((do_list, - do_deploy, - do_start, - do_sessions, - do_redeploy, - do_expire, - do_undeploy, - do_stop, - do_findleakers), CMD_CAT_APP_MGMT) + do_deploy, + do_start, + do_sessions, + do_redeploy, + do_expire, + do_undeploy, + do_stop, + do_findleakers), CMD_CAT_APP_MGMT) def do_resources(self, _): """Resources command""" diff --git a/examples/paged_output.py b/examples/paged_output.py index d1b1b2c2..a0674a62 100755 --- a/examples/paged_output.py +++ b/examples/paged_output.py @@ -21,7 +21,7 @@ class PagedOutput(cmd2.Cmd): with open(filename, 'r') as f: text = f.read() self.ppaged(text, chop=chop) - except FileNotFoundError as ex: + except FileNotFoundError: self.perror('ERROR: file {!r} not found'.format(filename), traceback_war=False) @cmd2.with_argument_list diff --git a/examples/pirate.py b/examples/pirate.py index 096133dc..2da3fcaa 100755 --- a/examples/pirate.py +++ b/examples/pirate.py @@ -51,8 +51,7 @@ class Pirate(cmd2.Cmd): def postcmd(self, stop, line): """Runs right before a command is about to return.""" if self.gold != self.initial_gold: - self.poutput('Now we gots {0} doubloons' - .format(self.gold)) + self.poutput('Now we gots {0} doubloons'.format(self.gold)) if self.gold < 0: self.poutput("Off to debtorrr's prison.") stop = True diff --git a/examples/scripts/arg_printer.py b/examples/scripts/arg_printer.py index 848dcf99..19f6dd3f 100755 --- a/examples/scripts/arg_printer.py +++ b/examples/scripts/arg_printer.py @@ -5,4 +5,4 @@ import sys print("Running Python script {!r} which was called with {} arguments".format(os.path.basename(sys.argv[0]), len(sys.argv) - 1)) for i, arg in enumerate(sys.argv[1:]): - print("arg {}: {!r}".format(i+1, arg)) + print("arg {}: {!r}".format(i + 1, arg)) diff --git a/examples/scripts/conditional.py b/examples/scripts/conditional.py index d7ee5ea2..faac3947 100644 --- a/examples/scripts/conditional.py +++ b/examples/scripts/conditional.py @@ -1,4 +1,5 @@ # coding=utf-8 +# flake8: noqa F821 """ This is a Python script intended to be used with the "python_scripting.py" cmd2 example application. @@ -12,7 +13,6 @@ application instance. import os import sys - if len(sys.argv) > 1: directory = sys.argv[1] print('Using specified directory: {!r}'.format(directory)) diff --git a/examples/scripts/script.py b/examples/scripts/script.py index 3f60c8fb..5195b8cc 100644 --- a/examples/scripts/script.py +++ b/examples/scripts/script.py @@ -4,4 +4,3 @@ Trivial example of a Python script which can be run inside a cmd2 application. """ print("This is a python script running ...") - diff --git a/examples/tab_autocomp_dynamic.py b/examples/tab_autocomp_dynamic.py index af77b204..0c64d020 100755 --- a/examples/tab_autocomp_dynamic.py +++ b/examples/tab_autocomp_dynamic.py @@ -6,8 +6,6 @@ A example usage of AutoCompleter with delayed initialization of the argparse obj Copyright 2018 Eric Lin <anselor@gmail.com> Released under MIT license, see LICENSE file """ -import argparse -import itertools from typing import List import cmd2 @@ -87,18 +85,15 @@ class TabCompleteExample(cmd2.Cmd): # Add the 'movies' parser as a parent of sub-parser video_types_subparsers.add_parser('movies', parents=[vid_movies_parser], add_help=False) - - vid_shows_parser = argparse_completer.ACArgumentParser(prog='shows') vid_shows_parser.set_defaults(func=TabCompleteExample._do_vid_media_shows) vid_shows_commands_subparsers = vid_shows_parser.add_subparsers(title='Commands', dest='command') - vid_shows_list_parser = vid_shows_commands_subparsers.add_parser('list') + vid_shows_commands_subparsers.add_parser('list') video_types_subparsers.add_parser('shows', parents=[vid_shows_parser], add_help=False) - # For mocking a data source for the example commands ratings_types = ['G', 'PG', 'PG-13', 'R', 'NC-17'] show_ratings = ['TV-Y', 'TV-Y7', 'TV-G', 'TV-PG', 'TV-14', 'TV-MA'] @@ -126,10 +121,10 @@ class TabCompleteExample(cmd2.Cmd): 'Alec Guinness', 'Peter Mayhew', 'Anthony Daniels'] }, 'SW_EP1': {'title': 'Star Wars: Episode I - The Phantom Menace', - 'rating': 'PG', - 'director': ['George Lucas'], - 'actor': ['Liam Neeson', 'Ewan McGregor', 'Natalie Portman', 'Jake Lloyd'] - }, + 'rating': 'PG', + 'director': ['George Lucas'], + 'actor': ['Liam Neeson', 'Ewan McGregor', 'Natalie Portman', 'Jake Lloyd'] + }, 'SW_EP02': {'title': 'Star Wars: Episode II - Attack of the Clones', 'rating': 'PG', 'director': ['George Lucas'], @@ -146,21 +141,21 @@ class TabCompleteExample(cmd2.Cmd): } USER_SHOW_LIBRARY = {'SW_REB': ['S01E01', 'S02E02']} SHOW_DATABASE_IDS = ['SW_CW', 'SW_TCW', 'SW_REB'] - SHOW_DATABASE = {'SW_CW': {'title': 'Star Wars: Clone Wars', - 'rating': 'TV-Y7', - 'seasons': {1: ['S01E01', 'S01E02', 'S01E03'], - 2: ['S02E01', 'S02E02', 'S02E03']} - }, - 'SW_TCW': {'title': 'Star Wars: The Clone Wars', - 'rating': 'TV-PG', - 'seasons': {1: ['S01E01', 'S01E02', 'S01E03'], - 2: ['S02E01', 'S02E02', 'S02E03']} - }, - 'SW_REB': {'title': 'Star Wars: Rebels', - 'rating': 'TV-Y7', - 'seasons': {1: ['S01E01', 'S01E02', 'S01E03'], - 2: ['S02E01', 'S02E02', 'S02E03']} - }, + SHOW_DATABASE = {'SW_CW': {'title': 'Star Wars: Clone Wars', + 'rating': 'TV-Y7', + 'seasons': {1: ['S01E01', 'S01E02', 'S01E03'], + 2: ['S02E01', 'S02E02', 'S02E03']} + }, + 'SW_TCW': {'title': 'Star Wars: The Clone Wars', + 'rating': 'TV-PG', + 'seasons': {1: ['S01E01', 'S01E02', 'S01E03'], + 2: ['S02E01', 'S02E02', 'S02E03']} + }, + 'SW_REB': {'title': 'Star Wars: Rebels', + 'rating': 'TV-Y7', + 'seasons': {1: ['S01E01', 'S01E02', 'S01E03'], + 2: ['S02E01', 'S02E02', 'S02E03']} + }, } file_list = \ @@ -187,12 +182,10 @@ class TabCompleteExample(cmd2.Cmd): return completions_with_desc - ################################################################################### # The media command demonstrates a completer with multiple layers of subcommands # - This example demonstrates how to tag a completion attribute on each action, enabling argument # completion without implementing a complete_COMMAND function - def _do_vid_media_movies(self, args) -> None: if not args.command: self.do_help('video movies') diff --git a/examples/tab_autocompletion.py b/examples/tab_autocompletion.py index dad9e90d..1c578c72 100755 --- a/examples/tab_autocompletion.py +++ b/examples/tab_autocompletion.py @@ -59,10 +59,10 @@ class TabCompleteExample(cmd2.Cmd): 'Alec Guinness', 'Peter Mayhew', 'Anthony Daniels'] }, 'SW_EP1': {'title': 'Star Wars: Episode I - The Phantom Menace', - 'rating': 'PG', - 'director': ['George Lucas'], - 'actor': ['Liam Neeson', 'Ewan McGregor', 'Natalie Portman', 'Jake Lloyd'] - }, + 'rating': 'PG', + 'director': ['George Lucas'], + 'actor': ['Liam Neeson', 'Ewan McGregor', 'Natalie Portman', 'Jake Lloyd'] + }, 'SW_EP02': {'title': 'Star Wars: Episode II - Attack of the Clones', 'rating': 'PG', 'director': ['George Lucas'], @@ -79,21 +79,21 @@ class TabCompleteExample(cmd2.Cmd): } USER_SHOW_LIBRARY = {'SW_REB': ['S01E01', 'S02E02']} SHOW_DATABASE_IDS = ['SW_CW', 'SW_TCW', 'SW_REB'] - SHOW_DATABASE = {'SW_CW': {'title': 'Star Wars: Clone Wars', - 'rating': 'TV-Y7', - 'seasons': {1: ['S01E01', 'S01E02', 'S01E03'], - 2: ['S02E01', 'S02E02', 'S02E03']} - }, - 'SW_TCW': {'title': 'Star Wars: The Clone Wars', - 'rating': 'TV-PG', - 'seasons': {1: ['S01E01', 'S01E02', 'S01E03'], - 2: ['S02E01', 'S02E02', 'S02E03']} - }, - 'SW_REB': {'title': 'Star Wars: Rebels', - 'rating': 'TV-Y7', - 'seasons': {1: ['S01E01', 'S01E02', 'S01E03'], - 2: ['S02E01', 'S02E02', 'S02E03']} - }, + SHOW_DATABASE = {'SW_CW': {'title': 'Star Wars: Clone Wars', + 'rating': 'TV-Y7', + 'seasons': {1: ['S01E01', 'S01E02', 'S01E03'], + 2: ['S02E01', 'S02E02', 'S02E03']} + }, + 'SW_TCW': {'title': 'Star Wars: The Clone Wars', + 'rating': 'TV-PG', + 'seasons': {1: ['S01E01', 'S01E02', 'S01E03'], + 2: ['S02E01', 'S02E02', 'S02E03']} + }, + 'SW_REB': {'title': 'Star Wars: Rebels', + 'rating': 'TV-Y7', + 'seasons': {1: ['S01E01', 'S01E02', 'S01E03'], + 2: ['S02E01', 'S02E02', 'S02E03']} + }, } file_list = \ @@ -299,7 +299,8 @@ class TabCompleteExample(cmd2.Cmd): ', '.join(movie['director']), '\n '.join(movie['actor']))) elif args.command == 'add': - print('Adding Movie\n----------------\nTitle: {}\nRating: {}\nDirectors: {}\nActors: {}\n\n'.format(args.title, args.rating, ', '.join(args.director), ', '.join(args.actor))) + print('Adding Movie\n----------------\nTitle: {}\nRating: {}\nDirectors: {}\nActors: {}\n\n' + .format(args.title, args.rating, ', '.join(args.director), ', '.join(args.actor))) def _do_media_shows(self, args) -> None: if not args.command: @@ -367,7 +368,6 @@ class TabCompleteExample(cmd2.Cmd): # No subcommand was provided, so call help self.do_help('media') - # This completer is implemented using a single dictionary to look up completion lists for all layers of # subcommands. For each argument, AutoCompleter will search for completion values from the provided # arg_choices dict. This requires careful naming of argparse arguments so that there are no unintentional diff --git a/examples/table_display.py b/examples/table_display.py index 7541e548..04415afd 100755 --- a/examples/table_display.py +++ b/examples/table_display.py @@ -52,11 +52,11 @@ EXAMPLE_ITERABLE_DATA = [['Shanghai (上海)', 'Shanghai', 'China', 'Asia', 2418 ['Guangzho (广州市)', 'Guangdong', 'China', 'Asia', 13081000, 1347.81], ['Mumbai (मुंबई)', 'Maharashtra', 'India', 'Asia', 12442373, 465.78], ['Istanbul (İstanbuld)', 'Istanbul', 'Turkey', 'Eurasia', 12661000, 620.29], - ] + ] # Calculate population density for row in EXAMPLE_ITERABLE_DATA: - row.append(row[-2]/row[-1]) + row.append(row[-2] / row[-1]) # Column headers plus optional formatting info for each column @@ -69,7 +69,7 @@ COLUMNS = [tf.Column('City', width=11, header_halign=tf.ColumnAlignment.AlignCen cell_halign=tf.ColumnAlignment.AlignRight, formatter=two_dec), tf.Column('Pop. Density (/km²)', width=12, header_halign=tf.ColumnAlignment.AlignCenter, cell_halign=tf.ColumnAlignment.AlignRight, formatter=no_dec), - ] + ] # ######## Table data formatted as an iterable of python objects ######### @@ -119,7 +119,7 @@ OBJ_COLS = [tf.Column('City', attrib='city', header_halign=tf.ColumnAlignment.Al cell_halign=tf.ColumnAlignment.AlignRight, formatter=two_dec), tf.Column('Pop. Density (/km²)', width=12, header_halign=tf.ColumnAlignment.AlignCenter, cell_halign=tf.ColumnAlignment.AlignRight, obj_formatter=pop_density), - ] + ] EXTREMELY_HIGH_POULATION_DENSITY = 25000 @@ -63,7 +63,7 @@ Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: Implementation :: CPython Topic :: Software Development :: Libraries :: Python Modules -""".splitlines()))) +""".splitlines()))) # noqa: E128 SETUP_REQUIRES = ['setuptools_scm'] @@ -83,7 +83,7 @@ EXTRAS_REQUIRE = { 'dev': ["mock ; python_version<'3.6'", # for python 3.5 and earlier we need the third party mock module 'pytest', 'codecov', 'pytest-cov', 'pytest-mock', 'tox', 'pylint', 'sphinx', 'sphinx-rtd-theme', 'sphinx-autobuild', 'invoke', 'twine>=1.11', - ] + ] } setup( @@ -1,5 +1,6 @@ # # coding=utf-8 +# flake8: noqa E302 """Development related tasks to be run with 'invoke'. Make sure you satisfy the following Python module requirements if you are trying to publish a release to PyPI: diff --git a/tests/__init__.py b/tests/__init__.py index 2aeb9ddf..037f3866 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1,3 @@ # # -*- coding: utf-8 -*- # - diff --git a/tests/conftest.py b/tests/conftest.py index ac6a1896..223389b9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,7 +5,6 @@ Cmd2 unit/functional testing Copyright 2016 Federico Ceratto <federico.ceratto@gmail.com> Released under MIT license, see LICENSE file """ -import sys from typing import Optional from unittest import mock @@ -31,7 +30,7 @@ BASE_HELP = """Documented commands (type help <topic>): ======================================== alias help load py quit shell edit history macro pyscript set shortcuts -""" +""" # noqa: W291 BASE_HELP_VERBOSE = """ Documented commands (type help <topic>): @@ -108,6 +107,7 @@ quiet: False # Don't print nonessential feedback timing: False # Report execution times """ + def normalize(block): """ Normalize a block of text to perform comparison. diff --git a/tests/pyscript/bar1.py b/tests/pyscript/bar1.py index 521e2c29..0f2b1e5e 100644 --- a/tests/pyscript/bar1.py +++ b/tests/pyscript/bar1.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.bar('11', '22') diff --git a/tests/pyscript/custom_echo.py b/tests/pyscript/custom_echo.py index 14040e4c..3a79133a 100644 --- a/tests/pyscript/custom_echo.py +++ b/tests/pyscript/custom_echo.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 custom.cmd_echo = True custom.echo('blah!') diff --git a/tests/pyscript/foo1.py b/tests/pyscript/foo1.py index d9345354..443282a5 100644 --- a/tests/pyscript/foo1.py +++ b/tests/pyscript/foo1.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.foo('aaa', 'bbb', counter=3, trueval=True, constval=True) diff --git a/tests/pyscript/foo2.py b/tests/pyscript/foo2.py index d3600a60..9aa37105 100644 --- a/tests/pyscript/foo2.py +++ b/tests/pyscript/foo2.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.foo('11', '22', '33', '44', counter=3, trueval=True, constval=True) diff --git a/tests/pyscript/foo3.py b/tests/pyscript/foo3.py index fc0e084a..e4384076 100644 --- a/tests/pyscript/foo3.py +++ b/tests/pyscript/foo3.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.foo('11', '22', '33', '44', '55', '66', counter=3, trueval=False, constval=False) diff --git a/tests/pyscript/foo4.py b/tests/pyscript/foo4.py index e4b7d01c..a601ccd8 100644 --- a/tests/pyscript/foo4.py +++ b/tests/pyscript/foo4.py @@ -1,3 +1,4 @@ +# flake8: noqa F821 app.cmd_echo = True result = app.foo('aaa', 'bbb', counter=3) out_text = 'Fail' diff --git a/tests/pyscript/help.py b/tests/pyscript/help.py index 664c0488..3f24246d 100644 --- a/tests/pyscript/help.py +++ b/tests/pyscript/help.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.help() diff --git a/tests/pyscript/help_media.py b/tests/pyscript/help_media.py index d8d97c42..38c4a2f8 100644 --- a/tests/pyscript/help_media.py +++ b/tests/pyscript/help_media.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.help('media') diff --git a/tests/pyscript/media_movies_add1.py b/tests/pyscript/media_movies_add1.py index 7249c0ef..b5045a39 100644 --- a/tests/pyscript/media_movies_add1.py +++ b/tests/pyscript/media_movies_add1.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.media.movies.add('My Movie', 'PG-13', director=('George Lucas', 'J. J. Abrams')) diff --git a/tests/pyscript/media_movies_add2.py b/tests/pyscript/media_movies_add2.py index 681095d7..91dbbc6b 100644 --- a/tests/pyscript/media_movies_add2.py +++ b/tests/pyscript/media_movies_add2.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.media.movies.add('My Movie', 'PG-13', actor=('Mark Hamill'), director=('George Lucas', 'J. J. Abrams')) diff --git a/tests/pyscript/media_movies_list1.py b/tests/pyscript/media_movies_list1.py index edbc2021..505d1f91 100644 --- a/tests/pyscript/media_movies_list1.py +++ b/tests/pyscript/media_movies_list1.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.media.movies.list() diff --git a/tests/pyscript/media_movies_list2.py b/tests/pyscript/media_movies_list2.py index 5ad01b7b..69e0d3c5 100644 --- a/tests/pyscript/media_movies_list2.py +++ b/tests/pyscript/media_movies_list2.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.media().movies().list() diff --git a/tests/pyscript/media_movies_list3.py b/tests/pyscript/media_movies_list3.py index bdbdfceb..c4f0cc1e 100644 --- a/tests/pyscript/media_movies_list3.py +++ b/tests/pyscript/media_movies_list3.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app('media movies list') diff --git a/tests/pyscript/media_movies_list4.py b/tests/pyscript/media_movies_list4.py index 5f7bdaa9..29e98fe7 100644 --- a/tests/pyscript/media_movies_list4.py +++ b/tests/pyscript/media_movies_list4.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.media.movies.list(actor='Mark Hamill') diff --git a/tests/pyscript/media_movies_list5.py b/tests/pyscript/media_movies_list5.py index fa4efa5b..1c249ebf 100644 --- a/tests/pyscript/media_movies_list5.py +++ b/tests/pyscript/media_movies_list5.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.media.movies.list(actor=('Mark Hamill', 'Carrie Fisher')) diff --git a/tests/pyscript/media_movies_list6.py b/tests/pyscript/media_movies_list6.py index ef1851cd..c16ae6c5 100644 --- a/tests/pyscript/media_movies_list6.py +++ b/tests/pyscript/media_movies_list6.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.media.movies.list(rating='PG') diff --git a/tests/pyscript/media_movies_list7.py b/tests/pyscript/media_movies_list7.py index 7c827b7f..d4ca7dca 100644 --- a/tests/pyscript/media_movies_list7.py +++ b/tests/pyscript/media_movies_list7.py @@ -1,2 +1,3 @@ +# flake8: noqa F821 app.cmd_echo = True app.media.movies.list(rating=('PG', 'PG-13')) diff --git a/tests/pyscript/pyscript_dir1.py b/tests/pyscript/pyscript_dir1.py index 14a70a31..81814d70 100644 --- a/tests/pyscript/pyscript_dir1.py +++ b/tests/pyscript/pyscript_dir1.py @@ -1,3 +1,4 @@ +# flake8: noqa F821 out = dir(app) out.sort() print(out) diff --git a/tests/pyscript/pyscript_dir2.py b/tests/pyscript/pyscript_dir2.py index 28c61c8e..ebbbf712 100644 --- a/tests/pyscript/pyscript_dir2.py +++ b/tests/pyscript/pyscript_dir2.py @@ -1,3 +1,4 @@ +# flake8: noqa F821 out = dir(app.media) out.sort() print(out) diff --git a/tests/scripts/recursive.py b/tests/scripts/recursive.py index 4c29d317..3359d31e 100644 --- a/tests/scripts/recursive.py +++ b/tests/scripts/recursive.py @@ -1,5 +1,6 @@ #!/usr/bin/env python # coding=utf-8 +# flake8: noqa F821 """ Example demonstrating that running a Python script recursively inside another Python script isn't allowed """ diff --git a/tests/test_acargparse.py b/tests/test_acargparse.py index b6abc444..64612737 100644 --- a/tests/test_acargparse.py +++ b/tests/test_acargparse.py @@ -1,3 +1,4 @@ +# flake8: noqa E302 """ Unit/functional testing for argparse customizations in cmd2 diff --git a/tests/test_argparse.py b/tests/test_argparse.py index f1078e73..29f0d232 100644 --- a/tests/test_argparse.py +++ b/tests/test_argparse.py @@ -1,4 +1,5 @@ # coding=utf-8 +# flake8: noqa E302 """ Cmd2 testing for argument parsing """ diff --git a/tests/test_autocompletion.py b/tests/test_autocompletion.py index 7285af5c..2b9e0458 100644 --- a/tests/test_autocompletion.py +++ b/tests/test_autocompletion.py @@ -1,4 +1,5 @@ # coding=utf-8 +# flake8: noqa E302 """ Unit/functional testing for argparse completer in cmd2 diff --git a/tests/test_bashcompletion.py b/tests/test_bashcompletion.py index 47fcdb34..c7201e4b 100644 --- a/tests/test_bashcompletion.py +++ b/tests/test_bashcompletion.py @@ -1,4 +1,5 @@ # coding=utf-8 +# flake8: noqa E302 """ Unit/functional testing for argparse completer in cmd2 diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 59c6bb60..b10322f1 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -1,4 +1,5 @@ # coding=utf-8 +# flake8: noqa E302 """ Cmd2 unit/functional testing diff --git a/tests/test_completion.py b/tests/test_completion.py index dffb03ec..2a418cd6 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -1,4 +1,5 @@ # coding=utf-8 +# flake8: noqa E302 """ Unit/functional testing for readline tab-completion functions in the cmd2.py module. diff --git a/tests/test_parsing.py b/tests/test_parsing.py index ba72edd6..78adf880 100644 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -1,4 +1,5 @@ # coding=utf-8 +# flake8: noqa E302 """ Test the parsing logic in parsing.py diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 81dd7683..1f95017c 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1,4 +1,5 @@ # coding=utf-8 +# flake8: noqa E302 """ Test plugin infrastructure and hooks. diff --git a/tests/test_pyscript.py b/tests/test_pyscript.py index ce5e267d..692a498b 100644 --- a/tests/test_pyscript.py +++ b/tests/test_pyscript.py @@ -1,4 +1,5 @@ # coding=utf-8 +# flake8: noqa E302 """ Unit/functional testing for argparse completer in cmd2 diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 58ae16b4..6f1c4be0 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -1,4 +1,5 @@ # coding=utf-8 +# flake8: noqa E302 """ Cmd2 functional testing based on transcript diff --git a/tests/test_utils.py b/tests/test_utils.py index 35524bdf..2f727aaf 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,5 @@ # coding=utf-8 +# flake8: noqa E302 """ Unit testing for cmd2/utils.py module. |