diff options
| author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2021-01-31 23:24:47 -0500 |
|---|---|---|
| committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2021-01-31 23:24:47 -0500 |
| commit | 9cb49fb2a3b980f97d5fb27ea37c6dfeee3b9ec4 (patch) | |
| tree | 6d03d9b69ca6472211deb512ab80469f7b7d4802 /cmd2 | |
| parent | 43be550b235f88007c4c1792a7caff38c5ba271f (diff) | |
| download | cmd2-git-9cb49fb2a3b980f97d5fb27ea37c6dfeee3b9ec4.tar.gz | |
Add in isort changes
Diffstat (limited to 'cmd2')
| -rw-r--r-- | cmd2/ansi.py | 12 | ||||
| -rw-r--r-- | cmd2/argparse_completer.py | 8 | ||||
| -rw-r--r-- | cmd2/clipboard.py | 4 | ||||
| -rw-r--r-- | cmd2/cmd2.py | 60 | ||||
| -rw-r--r-- | cmd2/command_definition.py | 17 | ||||
| -rw-r--r-- | cmd2/decorators.py | 25 | ||||
| -rw-r--r-- | cmd2/history.py | 8 | ||||
| -rwxr-xr-x | cmd2/parsing.py | 4 | ||||
| -rw-r--r-- | cmd2/py_bridge.py | 4 | ||||
| -rw-r--r-- | cmd2/rl_utils.py | 13 | ||||
| -rw-r--r-- | cmd2/table_creator.py | 16 | ||||
| -rw-r--r-- | cmd2/transcript.py | 4 | ||||
| -rw-r--r-- | cmd2/utils.py | 21 |
13 files changed, 149 insertions, 47 deletions
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() |
