diff options
57 files changed, 441 insertions, 145 deletions
diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 14a4f3a0..617cbf0a 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -25,4 +25,6 @@ jobs: - name: Install python prerequisites run: pip install -U --user pip setuptools setuptools-scm black - name: Black - run: python -m black --check --diff -l 127 --skip-string-normalization . + run: python -m black --check --diff . + - name: isort + run: python -m isort --check-only . diff --git a/cmd2/ansi.py b/cmd2/ansi.py index 1299c8ce..59e25483 100644 --- a/cmd2/ansi.py +++ b/cmd2/ansi.py @@ -5,7 +5,9 @@ setting the window title, and asynchronous alerts. """ import functools import re -from enum import Enum +from enum import ( + Enum, +) from typing import ( IO, Any, @@ -19,7 +21,9 @@ from colorama import ( Fore, Style, ) -from wcwidth import wcswidth +from wcwidth import ( + wcswidth, +) # On Windows, filter ANSI escape codes out of text sent to stdout/stderr, and replace them with equivalent Win32 calls colorama.init(strip=False) @@ -319,7 +323,9 @@ def async_alert_str(*, terminal_columns: int, prompt: str, line: str, cursor_off :param alert_msg: the message to display to the user :return: the correct string so that the alert message appears to the user to be printed above the current line. """ - from colorama import Cursor + from colorama import ( + Cursor, + ) # Split the prompt lines since it can contain newline characters. prompt_lines = prompt.splitlines() diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py index 49b917b5..88cd2938 100644 --- a/cmd2/argparse_completer.py +++ b/cmd2/argparse_completer.py @@ -10,7 +10,9 @@ import argparse import inspect import numbers import shutil -from collections import deque +from collections import ( + deque, +) from typing import ( Dict, List, @@ -32,7 +34,9 @@ from .argparse_custom import ( CompletionItem, generate_range_error, ) -from .command_definition import CommandSet +from .command_definition import ( + CommandSet, +) from .table_creator import ( Column, SimpleTable, diff --git a/cmd2/clipboard.py b/cmd2/clipboard.py index f4d2885b..03931724 100644 --- a/cmd2/clipboard.py +++ b/cmd2/clipboard.py @@ -5,7 +5,9 @@ This module provides basic ability to copy from and paste to the clipboard/paste import pyperclip # noinspection PyProtectedMember -from pyperclip import PyperclipException +from pyperclip import ( + PyperclipException, +) # Can we access the clipboard? Should always be true on Windows and Mac, but only sometimes on Linux try: diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index bbb12ef3..a08c5d42 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -38,9 +38,15 @@ import pydoc import re import sys import threading -from code import InteractiveConsole -from collections import namedtuple -from contextlib import redirect_stdout +from code import ( + InteractiveConsole, +) +from collections import ( + namedtuple, +) +from contextlib import ( + redirect_stdout, +) from typing import ( Any, Callable, @@ -69,7 +75,9 @@ from .clipboard import ( get_paste_buffer, write_to_paste_buffer, ) -from .command_definition import CommandSet +from .command_definition import ( + CommandSet, +) from .constants import ( CLASS_ATTR_DEFAULT_HELP_CATEGORY, COMMAND_FUNC_PREFIX, @@ -118,7 +126,10 @@ from .utils import ( if rl_type == RlType.NONE: # pragma: no cover sys.stderr.write(ansi.style_warning(rl_warning)) else: - from .rl_utils import rl_force_redisplay, readline + from .rl_utils import ( + readline, + rl_force_redisplay, + ) # Used by rlcompleter in Python console loaded by py command orig_rl_delims = readline.get_completer_delims() @@ -133,7 +144,10 @@ else: # Get the readline lib so we can make changes to it import ctypes - from .rl_utils import readline_lib + + from .rl_utils import ( + readline_lib, + ) rl_basic_quote_characters = ctypes.c_char_p.in_dll(readline_lib, "rl_basic_quote_characters") orig_rl_basic_quotes = ctypes.cast(rl_basic_quote_characters, ctypes.c_void_p).value @@ -142,7 +156,9 @@ else: ipython_available = True try: # noinspection PyUnresolvedReferences,PyPackageRequirements - from IPython import embed + from IPython import ( + embed, + ) except ImportError: # pragma: no cover ipython_available = False @@ -1976,7 +1992,9 @@ class Cmd(cmd.Cmd): cmd_set: Optional[CommandSet] = None ) -> List[str]: """Completion function for argparse commands""" - from .argparse_completer import ArgparseCompleter + from .argparse_completer import ( + ArgparseCompleter, + ) completer = ArgparseCompleter(argparser, self) tokens, raw_tokens = self.tokens_for_completion(line, begidx, endidx) @@ -3283,7 +3301,9 @@ class Cmd(cmd.Cmd): # Combine the command and its subcommand tokens for the ArgparseCompleter tokens = [command] + arg_tokens['subcommands'] - from .argparse_completer import ArgparseCompleter + from .argparse_completer import ( + ArgparseCompleter, + ) completer = ArgparseCompleter(argparser, self) return completer.complete_subcommand_help(tokens, text, line, begidx, endidx) @@ -3322,7 +3342,9 @@ class Cmd(cmd.Cmd): # If the command function uses argparse, then use argparse's help if func is not None and argparser is not None: - from .argparse_completer import ArgparseCompleter + from .argparse_completer import ( + ArgparseCompleter, + ) completer = ArgparseCompleter(argparser, self) tokens = [args.command] + args.subcommands @@ -3573,7 +3595,9 @@ class Cmd(cmd.Cmd): completer_method=settable.completer_method, ) - from .argparse_completer import ArgparseCompleter + from .argparse_completer import ( + ArgparseCompleter, + ) completer = ArgparseCompleter(settable_parser, self) @@ -3861,7 +3885,9 @@ class Cmd(cmd.Cmd): """Function callable from the interactive Python console to exit that environment""" raise EmbeddedConsoleExit - from .py_bridge import PyBridge + from .py_bridge import ( + PyBridge, + ) py_bridge = PyBridge(self) saved_sys_path = None @@ -4016,7 +4042,9 @@ class Cmd(cmd.Cmd): :return: True if running of commands should stop """ - from .py_bridge import PyBridge + from .py_bridge import ( + PyBridge, + ) # noinspection PyUnusedLocal def load_ipy(cmd2_app: Cmd, py_bridge: PyBridge): @@ -4559,8 +4587,12 @@ class Cmd(cmd.Cmd): """ import time import unittest + import cmd2 - from .transcript import Cmd2TestCase + + from .transcript import ( + Cmd2TestCase, + ) class TestMyAppCase(Cmd2TestCase): cmdapp = self diff --git a/cmd2/command_definition.py b/cmd2/command_definition.py index d30a8c32..e319d7f3 100644 --- a/cmd2/command_definition.py +++ b/cmd2/command_definition.py @@ -11,11 +11,15 @@ from .constants import ( CLASS_ATTR_DEFAULT_HELP_CATEGORY, COMMAND_FUNC_PREFIX, ) -from .exceptions import CommandSetRegistrationError +from .exceptions import ( + CommandSetRegistrationError, +) # Allows IDEs to resolve types without impacting imports at runtime, breaking circular dependency issues try: # pragma: no cover - from typing import TYPE_CHECKING + from typing import ( + TYPE_CHECKING, + ) if TYPE_CHECKING: import cmd2 @@ -47,9 +51,14 @@ def with_default_category(category: str, *, heritable: bool = True): if heritable: setattr(cls, CLASS_ATTR_DEFAULT_HELP_CATEGORY, category) - from .constants import CMD_ATTR_HELP_CATEGORY import inspect - from .decorators import with_category + + from .constants import ( + CMD_ATTR_HELP_CATEGORY, + ) + from .decorators import ( + with_category, + ) # get members of the class that meet the following criteria: # 1. Must be a function diff --git a/cmd2/decorators.py b/cmd2/decorators.py index a5fae5c5..d85db300 100644 --- a/cmd2/decorators.py +++ b/cmd2/decorators.py @@ -13,10 +13,18 @@ from typing import ( Union, ) -from . import constants -from .argparse_custom import Cmd2AttributeWrapper -from .exceptions import Cmd2ArgparseError -from .parsing import Statement +from . import ( + constants, +) +from .argparse_custom import ( + Cmd2AttributeWrapper, +) +from .exceptions import ( + Cmd2ArgparseError, +) +from .parsing import ( + Statement, +) if TYPE_CHECKING: # pragma: no cover import cmd2 @@ -40,7 +48,9 @@ def with_category(category: str) -> Callable: """ def cat_decorator(func): - from .utils import categorize + from .utils import ( + categorize, + ) categorize(func, category) return func @@ -63,7 +73,10 @@ def _parse_positionals(args: Tuple) -> Tuple[Union['cmd2.Cmd', 'cmd2.CommandSet' :return: The cmd2.Cmd reference and the command line statement """ for pos, arg in enumerate(args): - from cmd2 import Cmd, CommandSet + from cmd2 import ( + Cmd, + CommandSet, + ) if (isinstance(arg, Cmd) or isinstance(arg, CommandSet)) and len(args) > pos: if isinstance(arg, CommandSet): diff --git a/cmd2/history.py b/cmd2/history.py index eacf1231..bc6c32ce 100644 --- a/cmd2/history.py +++ b/cmd2/history.py @@ -11,8 +11,12 @@ from typing import ( import attr -from . import utils -from .parsing import Statement +from . import ( + utils, +) +from .parsing import ( + Statement, +) @attr.s(frozen=True) diff --git a/cmd2/parsing.py b/cmd2/parsing.py index 348cc6a0..3dff2689 100755 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -19,7 +19,9 @@ from . import ( constants, utils, ) -from .exceptions import Cmd2ShlexError +from .exceptions import ( + Cmd2ShlexError, +) def shlex_split(str_to_split: str) -> List[str]: diff --git a/cmd2/py_bridge.py b/cmd2/py_bridge.py index 6f2160c6..fd9b55fb 100644 --- a/cmd2/py_bridge.py +++ b/cmd2/py_bridge.py @@ -9,7 +9,9 @@ from contextlib import ( redirect_stderr, redirect_stdout, ) -from typing import Optional +from typing import ( + Optional, +) from .utils import ( StdSim, diff --git a/cmd2/rl_utils.py b/cmd2/rl_utils.py index 44ce11ae..e56e338c 100644 --- a/cmd2/rl_utils.py +++ b/cmd2/rl_utils.py @@ -3,7 +3,9 @@ Imports the proper readline for the platform and provides utility functions for it """ import sys -from enum import Enum +from enum import ( + Enum, +) # Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit) try: @@ -40,9 +42,14 @@ _rl_warn_reason = '' if 'pyreadline' in sys.modules or 'pyreadline3' in sys.modules: rl_type = RlType.PYREADLINE - from ctypes import byref - from ctypes.wintypes import DWORD, HANDLE import atexit + from ctypes import ( + byref, + ) + from ctypes.wintypes import ( + DWORD, + HANDLE, + ) # Check if we are running in a terminal if sys.stdout.isatty(): # pragma: no cover diff --git a/cmd2/table_creator.py b/cmd2/table_creator.py index f5bf4a1b..3a3892b8 100644 --- a/cmd2/table_creator.py +++ b/cmd2/table_creator.py @@ -8,8 +8,12 @@ There are already implemented and ready-to-use examples of this below TableCreat import copy import functools import io -from collections import deque -from enum import Enum +from collections import ( + deque, +) +from enum import ( + Enum, +) from typing import ( Any, Optional, @@ -18,7 +22,9 @@ from typing import ( Union, ) -from wcwidth import wcwidth +from wcwidth import ( + wcwidth, +) from . import ( ansi, @@ -28,7 +34,9 @@ from . import ( # This is needed for compatibility with early versions of Python 3.5 prior to 3.5.4 try: - from typing import Deque + from typing import ( + Deque, + ) except ImportError: # pragma: no cover import typing diff --git a/cmd2/transcript.py b/cmd2/transcript.py index f45ac73d..68fb7be0 100644 --- a/cmd2/transcript.py +++ b/cmd2/transcript.py @@ -11,7 +11,9 @@ class is used in cmd2.py::run_transcript_tests() """ import re import unittest -from typing import Tuple +from typing import ( + Tuple, +) from . import ( ansi, diff --git a/cmd2/utils.py b/cmd2/utils.py index 53c2e131..7e5f5af5 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -13,7 +13,9 @@ import subprocess import sys import threading import unicodedata -from enum import Enum +from enum import ( + Enum, +) from typing import ( IO, Any, @@ -27,7 +29,9 @@ from typing import ( Union, ) -from . import constants +from . import ( + constants, +) def is_quoted(arg: str) -> bool: @@ -784,7 +788,9 @@ def align_text( import io import shutil - from . import ansi + from . import ( + ansi, + ) if width is None: width = shutil.get_terminal_size().columns @@ -983,7 +989,10 @@ def truncate_line(line: str, max_width: int, *, tab_width: int = 4) -> str: :raises: ValueError if max_width is less than 1 """ import io - from . import ansi + + from . import ( + ansi, + ) # Handle tabs line = line.replace('\t', ' ' * tab_width) @@ -1046,7 +1055,9 @@ def get_styles_in_text(text: str) -> Dict[int, str]: :param text: text to search for style sequences """ - from . import ansi + from . import ( + ansi, + ) start = 0 styles = collections.OrderedDict() diff --git a/examples/async_printing.py b/examples/async_printing.py index 641ff84f..74c4f41f 100755 --- a/examples/async_printing.py +++ b/examples/async_printing.py @@ -7,7 +7,9 @@ and changes the window title import random import threading import time -from typing import List +from typing import ( + List, +) import cmd2 from cmd2 import ( diff --git a/examples/basic_completion.py b/examples/basic_completion.py index aab7d3d1..febe58a3 100755 --- a/examples/basic_completion.py +++ b/examples/basic_completion.py @@ -13,7 +13,9 @@ familiar with argparse. The recommended approach for tab completing positional t argparse-based completion. For an example integrating tab completion with argparse, see argparse_completion.py """ import functools -from typing import List +from typing import ( + List, +) import cmd2 diff --git a/examples/colors.py b/examples/colors.py index 60a75a53..abfb8955 100755 --- a/examples/colors.py +++ b/examples/colors.py @@ -24,7 +24,9 @@ Always regardless of the output destination """ import argparse -from typing import Any +from typing import ( + Any, +) from colorama import ( Back, @@ -33,7 +35,9 @@ from colorama import ( ) import cmd2 -from cmd2 import ansi +from cmd2 import ( + ansi, +) class CmdLineApp(cmd2.Cmd): diff --git a/examples/decorator_example.py b/examples/decorator_example.py index c20a6d4a..09193926 100755 --- a/examples/decorator_example.py +++ b/examples/decorator_example.py @@ -11,7 +11,9 @@ all the commands in the transcript against decorator_example.py, verifying that the output produced matches the transcript. """ import argparse -from typing import List +from typing import ( + List, +) import cmd2 diff --git a/examples/exit_code.py b/examples/exit_code.py index 9f940f69..80cef62f 100755 --- a/examples/exit_code.py +++ b/examples/exit_code.py @@ -2,7 +2,9 @@ # coding=utf-8 """A simple example demonstrating the following how to emit a non-zero exit code in your cmd2 application. """ -from typing import List +from typing import ( + List, +) import cmd2 diff --git a/examples/hello_cmd2.py b/examples/hello_cmd2.py index 19d369da..e94ad2a5 100755 --- a/examples/hello_cmd2.py +++ b/examples/hello_cmd2.py @@ -3,13 +3,14 @@ """ This is intended to be a completely bare-bones cmd2 application suitable for rapid testing and debugging. """ -from cmd2 import cmd2 +from cmd2 import ( + cmd2, +) if __name__ == '__main__': import sys # If run as the main application, simply start a bare-bones cmd2 application with only built-in functionality. - # Set "use_ipython" to True to include the ipy command if IPython is installed, which supports advanced interactive # debugging of your application via introspection on self. app = cmd2.Cmd(use_ipython=True, persistent_history_file='cmd2_history.dat') diff --git a/examples/help_categories.py b/examples/help_categories.py index 16860ec2..d9a7cce2 100755 --- a/examples/help_categories.py +++ b/examples/help_categories.py @@ -8,7 +8,9 @@ It also demonstrates the effects of decorator order when it comes to argparse er import functools import cmd2 -from cmd2 import COMMAND_NAME +from cmd2 import ( + COMMAND_NAME, +) def my_decorator(f): diff --git a/examples/hooks.py b/examples/hooks.py index 55b43e5d..e83c77fb 100755 --- a/examples/hooks.py +++ b/examples/hooks.py @@ -10,7 +10,9 @@ follow a command without any intervening whitespace. """ import re -from typing import List +from typing import ( + List, +) import cmd2 diff --git a/examples/modular_commands/commandset_basic.py b/examples/modular_commands/commandset_basic.py index c3ab41f2..226703b8 100644 --- a/examples/modular_commands/commandset_basic.py +++ b/examples/modular_commands/commandset_basic.py @@ -2,7 +2,9 @@ """ A simple example demonstrating a loadable command set """ -from typing import List +from typing import ( + List, +) from cmd2 import ( Cmd, @@ -11,7 +13,9 @@ from cmd2 import ( with_category, with_default_category, ) -from cmd2.utils import CompletionError +from cmd2.utils import ( + CompletionError, +) @with_default_category('Basic Completion') diff --git a/examples/modular_commands/commandset_complex.py b/examples/modular_commands/commandset_complex.py index 03bc2507..a9c39e55 100644 --- a/examples/modular_commands/commandset_complex.py +++ b/examples/modular_commands/commandset_complex.py @@ -5,10 +5,14 @@ Test CommandSet """ import argparse -from typing import List +from typing import ( + List, +) import cmd2 -from cmd2 import utils +from cmd2 import ( + utils, +) @cmd2.with_default_category('Fruits') diff --git a/examples/modular_commands_main.py b/examples/modular_commands_main.py index ae1c64f7..16b0a798 100644 --- a/examples/modular_commands_main.py +++ b/examples/modular_commands_main.py @@ -12,6 +12,16 @@ from typing import ( Optional, ) +from modular_commands.commandset_basic import ( # noqa: F401 + BasicCompletionCommandSet, +) +from modular_commands.commandset_complex import ( # noqa: F401 + CommandSetA, +) +from modular_commands.commandset_custominit import ( # noqa: F401 + CustomInitCommandSet, +) + from cmd2 import ( Cmd, Cmd2ArgumentParser, @@ -23,9 +33,6 @@ from cmd2.utils import ( CompletionError, basic_complete, ) -from modular_commands.commandset_basic import BasicCompletionCommandSet # noqa: F401 -from modular_commands.commandset_complex import CommandSetA # noqa: F401 -from modular_commands.commandset_custominit import CustomInitCommandSet # noqa: F401 # Data source for argparse.choices food_item_strs = ['Pizza', 'Ham', 'Ham Sandwich', 'Potato'] diff --git a/examples/override_parser.py b/examples/override_parser.py index d7d45b82..f615e6e0 100755 --- a/examples/override_parser.py +++ b/examples/override_parser.py @@ -13,7 +13,9 @@ import argparse # Next import stuff from cmd2. It will import your module just before the cmd2.Cmd class file is imported # and therefore override the parser class it uses on its commands. -from cmd2 import cmd2 +from cmd2 import ( + cmd2, +) argparse.cmd2_parser_module = 'examples.custom_parser' diff --git a/examples/paged_output.py b/examples/paged_output.py index 1c323c61..796f47a8 100755 --- a/examples/paged_output.py +++ b/examples/paged_output.py @@ -3,7 +3,9 @@ """A simple example demonstrating the using paged output via the ppaged() method. """ import os -from typing import List +from typing import ( + List, +) import cmd2 diff --git a/examples/pirate.py b/examples/pirate.py index 52e96de2..7b92b6f0 100755 --- a/examples/pirate.py +++ b/examples/pirate.py @@ -10,7 +10,9 @@ import argparse import cmd2 import cmd2.ansi -from cmd2.constants import MULTILINE_TERMINATOR +from cmd2.constants import ( + MULTILINE_TERMINATOR, +) class Pirate(cmd2.Cmd): diff --git a/examples/plumbum_colors.py b/examples/plumbum_colors.py index 2be7f156..a7cb7e88 100755 --- a/examples/plumbum_colors.py +++ b/examples/plumbum_colors.py @@ -27,13 +27,16 @@ WARNING: This example requires the plumbum package, which isn't normally require """ import argparse -import cmd2 -from cmd2 import ansi from plumbum.colors import ( bg, fg, ) +import cmd2 +from cmd2 import ( + ansi, +) + class FgColors(ansi.ColorBase): black = fg.Black diff --git a/examples/python_scripting.py b/examples/python_scripting.py index 3aa61467..bb43095e 100755 --- a/examples/python_scripting.py +++ b/examples/python_scripting.py @@ -24,7 +24,9 @@ import argparse import os import cmd2 -from cmd2 import ansi +from cmd2 import ( + ansi, +) class CmdLineApp(cmd2.Cmd): diff --git a/examples/table_creation.py b/examples/table_creation.py index bd955580..ff72311a 100755 --- a/examples/table_creation.py +++ b/examples/table_creation.py @@ -8,7 +8,9 @@ from typing import ( List, ) -from cmd2 import ansi +from cmd2 import ( + ansi, +) from cmd2.table_creator import ( AlternatingTable, BorderedTable, diff --git a/plugins/ext_test/cmd2_ext_test/__init__.py b/plugins/ext_test/cmd2_ext_test/__init__.py index 2cc38807..f246e822 100644 --- a/plugins/ext_test/cmd2_ext_test/__init__.py +++ b/plugins/ext_test/cmd2_ext_test/__init__.py @@ -17,6 +17,8 @@ except importlib_metadata.PackageNotFoundError: # pragma: no cover # package is not installed __version__ = 'unknown' -from .cmd2_ext_test import ExternalTestMixin +from .cmd2_ext_test import ( + ExternalTestMixin, +) __all__ = ['ExternalTestMixin'] diff --git a/plugins/ext_test/examples/example.py b/plugins/ext_test/examples/example.py index 3bfdf7e7..7dbb6677 100644 --- a/plugins/ext_test/examples/example.py +++ b/plugins/ext_test/examples/example.py @@ -1,9 +1,10 @@ # # coding=utf-8 # import cmd2 +import cmd2_ext_test + import cmd2 import cmd2.py_bridge -import cmd2_ext_test class Example(cmd2.Cmd): diff --git a/plugins/ext_test/tests/test_ext_test.py b/plugins/ext_test/tests/test_ext_test.py index 39783158..037157f1 100644 --- a/plugins/ext_test/tests/test_ext_test.py +++ b/plugins/ext_test/tests/test_ext_test.py @@ -1,9 +1,9 @@ # # coding=utf-8 +import cmd2_ext_test import pytest -import cmd2_ext_test from cmd2 import ( CommandResult, cmd2, diff --git a/plugins/tasks.py b/plugins/tasks.py index eed69c73..a22eb310 100644 --- a/plugins/tasks.py +++ b/plugins/tasks.py @@ -10,8 +10,12 @@ Make sure you satisfy the following Python module requirements if you are trying """ import invoke -from plugins.ext_test import tasks as ext_test_tasks -from plugins.template import tasks as template_tasks +from plugins.ext_test import ( + tasks as ext_test_tasks, +) +from plugins.template import ( + tasks as template_tasks, +) # create namespaces namespace = invoke.Collection( diff --git a/plugins/template/examples/example.py b/plugins/template/examples/example.py index 49a3df01..b071b5f8 100644 --- a/plugins/template/examples/example.py +++ b/plugins/template/examples/example.py @@ -1,9 +1,10 @@ # # coding=utf-8 -import cmd2 import cmd2_myplugin +import cmd2 + class Example(cmd2_myplugin.MyPlugin, cmd2.Cmd): """An class to show how to use a plugin""" diff --git a/plugins/template/tests/test_myplugin.py b/plugins/template/tests/test_myplugin.py index 8d29b3b1..06ca2567 100644 --- a/plugins/template/tests/test_myplugin.py +++ b/plugins/template/tests/test_myplugin.py @@ -2,7 +2,10 @@ # coding=utf-8 import cmd2_myplugin -from cmd2 import cmd2 + +from cmd2 import ( + cmd2, +) ###### # @@ -25,7 +25,7 @@ exclude = htmlcov [isort] -line_length = 127 +line_length = 1 skip = cmd2/__init__.py,.git,__pycache,.tox,.nox,.venv,.eggs,.idea,.vscode,build,dist.htmlcov profile = black multi_line_output = 3 @@ -5,7 +5,9 @@ Setuptools setup file, used to install or test 'cmd2' """ import codecs -from setuptools import setup +from setuptools import ( + setup, +) DESCRIPTION = "cmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python" @@ -16,7 +16,9 @@ import sys import invoke -from plugins import tasks as plugin_tasks +from plugins import ( + tasks as plugin_tasks, +) TASK_ROOT = pathlib.Path(__file__).resolve().parent TASK_ROOT_STR = str(TASK_ROOT) diff --git a/tests/conftest.py b/tests/conftest.py index 835739a7..5ed185a3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,12 +12,18 @@ from typing import ( Optional, Union, ) -from unittest import mock +from unittest import ( + mock, +) -from pytest import fixture +from pytest import ( + fixture, +) import cmd2 -from cmd2.utils import StdSim +from cmd2.utils import ( + StdSim, +) # Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit) try: diff --git a/tests/test_ansi.py b/tests/test_ansi.py index fd36e9e3..7ebda497 100644 --- a/tests/test_ansi.py +++ b/tests/test_ansi.py @@ -144,7 +144,10 @@ def test_cast_color_as_str(): def test_color_str_building(): - from cmd2.ansi import fg, bg + from cmd2.ansi import ( + bg, + fg, + ) assert fg.blue + "hello" == fg.blue.value + "hello" assert bg.blue + "hello" == bg.blue.value + "hello" diff --git a/tests/test_argparse.py b/tests/test_argparse.py index 72f28abb..131182fd 100644 --- a/tests/test_argparse.py +++ b/tests/test_argparse.py @@ -4,13 +4,17 @@ Cmd2 testing for argument parsing """ import argparse -from typing import Optional +from typing import ( + Optional, +) import pytest import cmd2 -from .conftest import run_cmd +from .conftest import ( + run_cmd, +) # Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit) try: @@ -425,8 +429,13 @@ def test_subcmd_decorator(subcommand_app): def test_unittest_mock(): - from unittest import mock - from cmd2 import CommandSetRegistrationError + from unittest import ( + mock, + ) + + from cmd2 import ( + CommandSetRegistrationError, + ) with mock.patch.object(ArgparseApp, 'namespace_provider'): with pytest.raises(CommandSetRegistrationError): @@ -443,7 +452,9 @@ def test_unittest_mock(): def test_pytest_mock_invalid(mocker): - from cmd2 import CommandSetRegistrationError + from cmd2 import ( + CommandSetRegistrationError, + ) mocker.patch.object(ArgparseApp, 'namespace_provider') with pytest.raises(CommandSetRegistrationError): diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py index 95bb6398..eda27154 100644 --- a/tests/test_argparse_completer.py +++ b/tests/test_argparse_completer.py @@ -5,7 +5,9 @@ Unit/functional testing for argparse completer in cmd2 """ import argparse import numbers -from typing import List +from typing import ( + List, +) import pytest @@ -664,7 +666,9 @@ def test_autocomp_positional_completers(ac_app, pos, text, completions): def test_autocomp_blank_token(ac_app): """Force a blank token to make sure ArgparseCompleter consumes them like argparse does""" - from cmd2.argparse_completer import ArgparseCompleter + from cmd2.argparse_completer import ( + ArgparseCompleter, + ) blank = '' @@ -883,7 +887,9 @@ def test_completion_items_arg_header(ac_app): def test_completion_items_descriptive_header(ac_app): - from cmd2.argparse_completer import DEFAULT_DESCRIPTIVE_HEADER + from cmd2.argparse_completer import ( + DEFAULT_DESCRIPTIVE_HEADER, + ) # This argument provided a descriptive header text = '' @@ -1045,7 +1051,9 @@ def test_complete_mutex_group(ac_app, command_and_args, text, output_contains, f def test_single_prefix_char(): - from cmd2.argparse_completer import _single_prefix_char + from cmd2.argparse_completer import ( + _single_prefix_char, + ) parser = Cmd2ArgumentParser(prefix_chars='-+') @@ -1062,7 +1070,9 @@ def test_single_prefix_char(): def test_looks_like_flag(): - from cmd2.argparse_completer import _looks_like_flag + from cmd2.argparse_completer import ( + _looks_like_flag, + ) parser = Cmd2ArgumentParser() @@ -1080,7 +1090,9 @@ def test_looks_like_flag(): def test_complete_command_no_tokens(ac_app): - from cmd2.argparse_completer import ArgparseCompleter + from cmd2.argparse_completer import ( + ArgparseCompleter, + ) parser = Cmd2ArgumentParser() ac = ArgparseCompleter(parser, ac_app) @@ -1090,7 +1102,9 @@ def test_complete_command_no_tokens(ac_app): def test_complete_command_help_no_tokens(ac_app): - from cmd2.argparse_completer import ArgparseCompleter + from cmd2.argparse_completer import ( + ArgparseCompleter, + ) parser = Cmd2ArgumentParser() ac = ArgparseCompleter(parser, ac_app) diff --git a/tests/test_argparse_custom.py b/tests/test_argparse_custom.py index 86521f61..dd227355 100644 --- a/tests/test_argparse_custom.py +++ b/tests/test_argparse_custom.py @@ -11,9 +11,13 @@ from cmd2 import ( Cmd2ArgumentParser, constants, ) -from cmd2.argparse_custom import generate_range_error +from cmd2.argparse_custom import ( + generate_range_error, +) -from .conftest import run_cmd +from .conftest import ( + run_cmd, +) class ApCustomTestApp(cmd2.Cmd): @@ -264,7 +268,10 @@ def test_apcustom_required_options(): def test_override_parser(): import importlib - from cmd2 import DEFAULT_ARGUMENT_PARSER + + from cmd2 import ( + DEFAULT_ARGUMENT_PARSER, + ) # The standard parser is Cmd2ArgumentParser assert DEFAULT_ARGUMENT_PARSER == Cmd2ArgumentParser @@ -272,10 +279,14 @@ def test_override_parser(): # Set our parser module and force a reload of cmd2 so it loads the module argparse.cmd2_parser_module = 'examples.custom_parser' importlib.reload(cmd2) - from cmd2 import DEFAULT_ARGUMENT_PARSER + from cmd2 import ( + DEFAULT_ARGUMENT_PARSER, + ) # Verify DEFAULT_ARGUMENT_PARSER is now our CustomParser - from examples.custom_parser import CustomParser + from examples.custom_parser import ( + CustomParser, + ) assert DEFAULT_ARGUMENT_PARSER == CustomParser diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index ca88cf99..759ec7d4 100755 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -9,7 +9,9 @@ import io import os import sys import tempfile -from code import InteractiveConsole +from code import ( + InteractiveConsole, +) import pytest @@ -40,7 +42,9 @@ from .conftest import ( try: import mock except ImportError: - from unittest import mock + from unittest import ( + mock, + ) def CreateOutsimApp(): @@ -1018,14 +1022,18 @@ def test_default_to_shell(base_app, monkeypatch): def test_ansi_prompt_not_esacped(base_app): - from cmd2.rl_utils import rl_make_safe_prompt + from cmd2.rl_utils import ( + rl_make_safe_prompt, + ) prompt = '(Cmd) ' assert rl_make_safe_prompt(prompt) == prompt def test_ansi_prompt_escaped(): - from cmd2.rl_utils import rl_make_safe_prompt + from cmd2.rl_utils import ( + rl_make_safe_prompt, + ) app = cmd2.Cmd() color = 'cyan' @@ -2072,7 +2080,9 @@ def test_multiple_macros(base_app): def test_nonexistent_macro(base_app): - from cmd2.parsing import StatementParser + from cmd2.parsing import ( + StatementParser, + ) exception = None diff --git a/tests/test_completion.py b/tests/test_completion.py index ea0ae092..4dcf5575 100755 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -20,8 +20,12 @@ import sys import pytest import cmd2 -from cmd2 import utils -from examples.subcommands import SubcommandsExample +from cmd2 import ( + utils, +) +from examples.subcommands import ( + SubcommandsExample, +) from .conftest import ( complete_tester, diff --git a/tests/test_history.py b/tests/test_history.py index ec05fb19..98ae00b7 100755 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -12,7 +12,9 @@ import cmd2 # Python 3.5 had some regressions in the unitest.mock module, so use # 3rd party mock if available -from cmd2.parsing import StatementParser +from cmd2.parsing import ( + StatementParser, +) from .conftest import ( HELP_HISTORY, @@ -23,14 +25,18 @@ from .conftest import ( try: import mock except ImportError: - from unittest import mock + from unittest import ( + mock, + ) # # readline tests # def test_readline_remove_history_item(base_app): - from cmd2.rl_utils import readline + from cmd2.rl_utils import ( + readline, + ) assert readline.get_current_history_length() == 0 readline.add_history('this is a test') @@ -44,8 +50,13 @@ def test_readline_remove_history_item(base_app): # @pytest.fixture def hist(): - from cmd2.parsing import Statement - from cmd2.cmd2 import History, HistoryItem + from cmd2.cmd2 import ( + History, + HistoryItem, + ) + from cmd2.parsing import ( + Statement, + ) h = History( [ @@ -60,8 +71,13 @@ def hist(): @pytest.fixture def persisted_hist(): - from cmd2.parsing import Statement - from cmd2.cmd2 import History, HistoryItem + from cmd2.cmd2 import ( + History, + HistoryItem, + ) + from cmd2.parsing import ( + Statement, + ) h = History( [ @@ -281,8 +297,12 @@ def test_history_max_length(hist): # @pytest.fixture def histitem(): - from cmd2.parsing import Statement - from cmd2.history import HistoryItem + from cmd2.history import ( + HistoryItem, + ) + from cmd2.parsing import ( + Statement, + ) statement = Statement( 'history', @@ -296,7 +316,9 @@ def histitem(): @pytest.fixture def parser(): - from cmd2.parsing import StatementParser + from cmd2.parsing import ( + StatementParser, + ) parser = StatementParser( terminators=[';', '&'], @@ -314,7 +336,9 @@ def parser(): def test_multiline_histitem(parser): - from cmd2.history import History + from cmd2.history import ( + History, + ) line = 'multiline foo\nbar\n\n' statement = parser.parse(line) @@ -328,7 +352,9 @@ def test_multiline_histitem(parser): def test_multiline_histitem_verbose(parser): - from cmd2.history import History + from cmd2.history import ( + History, + ) line = 'multiline foo\nbar\n\n' statement = parser.parse(line) @@ -343,8 +369,12 @@ def test_multiline_histitem_verbose(parser): def test_history_item_instantiate(): - from cmd2.parsing import Statement - from cmd2.history import HistoryItem + from cmd2.history import ( + HistoryItem, + ) + from cmd2.parsing import ( + Statement, + ) statement = Statement( 'history', @@ -822,7 +852,9 @@ def test_history_populates_readline(hist_file): # readline only adds a single entry for multiple sequential identical commands # so we check to make sure that cmd2 populated the readline history # using the same rules - from cmd2.rl_utils import readline + from cmd2.rl_utils import ( + readline, + ) assert readline.get_current_history_length() == 3 assert readline.get_history_item(1) == 'help' diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 291b0f55..9776dace 100755 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -997,7 +997,9 @@ def test_is_valid_command_valid(parser): def test_macro_normal_arg_pattern(): # This pattern matches digits surrounded by exactly 1 brace on a side and 1 or more braces on the opposite side - from cmd2.parsing import MacroArg + from cmd2.parsing import ( + MacroArg, + ) pattern = MacroArg.macro_normal_arg_pattern @@ -1049,7 +1051,9 @@ def test_macro_normal_arg_pattern(): def test_macro_escaped_arg_pattern(): # This pattern matches digits surrounded by 2 or more braces on both sides - from cmd2.parsing import MacroArg + from cmd2.parsing import ( + MacroArg, + ) pattern = MacroArg.macro_escaped_arg_pattern diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 831b4cef..cd1d9ab9 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -20,7 +20,9 @@ from cmd2 import ( try: import mock except ImportError: - from unittest import mock + from unittest import ( + mock, + ) class Plugin: diff --git a/tests/test_run_pyscript.py b/tests/test_run_pyscript.py index f474684a..2d74a5f0 100644 --- a/tests/test_run_pyscript.py +++ b/tests/test_run_pyscript.py @@ -22,7 +22,9 @@ from .conftest import ( try: import mock except ImportError: - from unittest import mock + from unittest import ( + mock, + ) HOOK_OUTPUT = "TEST_OUTPUT" diff --git a/tests/test_table_creator.py b/tests/test_table_creator.py index f8a63578..64db0dd7 100644 --- a/tests/test_table_creator.py +++ b/tests/test_table_creator.py @@ -5,7 +5,9 @@ Unit testing for cmd2/table_creator.py module """ import pytest -from cmd2 import ansi +from cmd2 import ( + ansi, +) from cmd2.table_creator import ( AlternatingTable, BorderedTable, diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 5f532bd3..48c6a792 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -9,12 +9,16 @@ import random import re import sys import tempfile -from unittest import mock +from unittest import ( + mock, +) import pytest import cmd2 -from cmd2 import transcript +from cmd2 import ( + transcript, +) from cmd2.utils import ( Settable, StdSim, diff --git a/tests/test_utils.py b/tests/test_utils.py index 81d184bf..c14c2f07 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -11,12 +11,16 @@ import time import pytest import cmd2.utils as cu -from cmd2.constants import HORIZONTAL_ELLIPSIS +from cmd2.constants import ( + HORIZONTAL_ELLIPSIS, +) try: import mock except ImportError: - from unittest import mock + from unittest import ( + mock, + ) HELLO_WORLD = 'Hello, world!' @@ -388,7 +392,9 @@ def test_truncate_line_tabs(): def test_truncate_with_style(): - from cmd2 import ansi + from cmd2 import ( + ansi, + ) before_style = ansi.fg.blue + ansi.UNDERLINE_ENABLE after_style = ansi.fg.reset + ansi.UNDERLINE_DISABLE @@ -421,7 +427,9 @@ def test_align_text_fill_char_is_tab(): def test_align_text_with_style(): - from cmd2 import ansi + from cmd2 import ( + ansi, + ) # Single line with only left fill text = ansi.style('line1', fg=ansi.fg.bright_blue) @@ -539,7 +547,10 @@ def test_align_text_has_unprintable(): def test_align_text_term_width(): import shutil - from cmd2 import ansi + + from cmd2 import ( + ansi, + ) text = 'foo' fill_char = ' ' diff --git a/tests_isolated/test_commandset/conftest.py b/tests_isolated/test_commandset/conftest.py index 85bd8504..dbf54b04 100644 --- a/tests_isolated/test_commandset/conftest.py +++ b/tests_isolated/test_commandset/conftest.py @@ -12,13 +12,21 @@ from typing import ( Optional, Union, ) -from unittest import mock +from unittest import ( + mock, +) -from pytest import fixture +from cmd2_ext_test import ( + ExternalTestMixin, +) +from pytest import ( + fixture, +) import cmd2 -from cmd2.utils import StdSim -from cmd2_ext_test import ExternalTestMixin +from cmd2.utils import ( + StdSim, +) # Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit) try: diff --git a/tests_isolated/test_commandset/test_categories.py b/tests_isolated/test_commandset/test_categories.py index 1dbd6725..71f1db8e 100644 --- a/tests_isolated/test_commandset/test_categories.py +++ b/tests_isolated/test_commandset/test_categories.py @@ -3,7 +3,9 @@ """ Simple example demonstrating basic CommandSet usage. """ -from typing import Any +from typing import ( + Any, +) import cmd2 from cmd2 import ( diff --git a/tests_isolated/test_commandset/test_commandset.py b/tests_isolated/test_commandset/test_commandset.py index 1fc97c2e..9fd124e3 100644 --- a/tests_isolated/test_commandset/test_commandset.py +++ b/tests_isolated/test_commandset/test_commandset.py @@ -5,13 +5,19 @@ Test CommandSet """ import argparse -from typing import List +from typing import ( + List, +) import pytest import cmd2 -from cmd2 import utils -from cmd2.exceptions import CommandSetRegistrationError +from cmd2 import ( + utils, +) +from cmd2.exceptions import ( + CommandSetRegistrationError, +) from .conftest import ( WithCommandSets, |