Skip to content

Commit

Permalink
Add in isort changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tleonhardt committed Feb 1, 2021
1 parent 43be550 commit 9cb49fb
Show file tree
Hide file tree
Showing 57 changed files with 441 additions and 145 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
12 changes: 9 additions & 3 deletions cmd2/ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"""
import functools
import re
from enum import Enum
from enum import (
Enum,
)
from typing import (
IO,
Any,
Expand All @@ -19,7 +21,9 @@
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)
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions cmd2/argparse_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import inspect
import numbers
import shutil
from collections import deque
from collections import (
deque,
)
from typing import (
Dict,
List,
Expand All @@ -32,7 +34,9 @@
CompletionItem,
generate_range_error,
)
from .command_definition import CommandSet
from .command_definition import (
CommandSet,
)
from .table_creator import (
Column,
SimpleTable,
Expand Down
4 changes: 3 additions & 1 deletion cmd2/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
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:
Expand Down
60 changes: 46 additions & 14 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@
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,
Expand Down Expand Up @@ -69,7 +75,9 @@
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,
Expand Down Expand Up @@ -118,7 +126,10 @@
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()
Expand All @@ -133,7 +144,10 @@

# 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
Expand All @@ -142,7 +156,9 @@
ipython_available = True
try:
# noinspection PyUnresolvedReferences,PyPackageRequirements
from IPython import embed
from IPython import (
embed,
)
except ImportError: # pragma: no cover
ipython_available = False

Expand Down Expand Up @@ -1976,7 +1992,9 @@ def _complete_argparse_command(
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)
Expand Down Expand Up @@ -3283,7 +3301,9 @@ def complete_help_subcommands(
# 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)
Expand Down Expand Up @@ -3322,7 +3342,9 @@ def do_help(self, args: argparse.Namespace) -> None:

# 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
Expand Down Expand Up @@ -3573,7 +3595,9 @@ def complete_set_value(
completer_method=settable.completer_method,
)

from .argparse_completer import ArgparseCompleter
from .argparse_completer import (
ArgparseCompleter,
)

completer = ArgparseCompleter(settable_parser, self)

Expand Down Expand Up @@ -3861,7 +3885,9 @@ def py_quit():
"""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
Expand Down Expand Up @@ -4016,7 +4042,9 @@ def do_ipy(self, _: argparse.Namespace) -> Optional[bool]:
: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):
Expand Down Expand Up @@ -4559,8 +4587,12 @@ def _run_transcript_tests(self, transcript_paths: List[str]) -> None:
"""
import time
import unittest

import cmd2
from .transcript import Cmd2TestCase

from .transcript import (
Cmd2TestCase,
)

class TestMyAppCase(Cmd2TestCase):
cmdapp = self
Expand Down
17 changes: 13 additions & 4 deletions cmd2/command_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
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
Expand Down Expand Up @@ -47,9 +51,14 @@ def decorate_class(cls: Type[CommandSet]):
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
Expand Down
25 changes: 19 additions & 6 deletions cmd2/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@
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
Expand All @@ -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
Expand All @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions cmd2/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@

import attr

from . import utils
from .parsing import Statement
from . import (
utils,
)
from .parsing import (
Statement,
)


@attr.s(frozen=True)
Expand Down
4 changes: 3 additions & 1 deletion cmd2/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
constants,
utils,
)
from .exceptions import Cmd2ShlexError
from .exceptions import (
Cmd2ShlexError,
)


def shlex_split(str_to_split: str) -> List[str]:
Expand Down
4 changes: 3 additions & 1 deletion cmd2/py_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
redirect_stderr,
redirect_stdout,
)
from typing import Optional
from typing import (
Optional,
)

from .utils import (
StdSim,
Expand Down
13 changes: 10 additions & 3 deletions cmd2/rl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -40,9 +42,14 @@ class RlType(Enum):
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
Expand Down
Loading

0 comments on commit 9cb49fb

Please sign in to comment.