Skip to content
Myr

apply reorder-python-imports

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent c781282 · Browse files · 37 files+254 added−188 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

37 files+254 added−188 removed

  • tests:+27 added−21 removed
  • other:+227 added−167 removed

37 files+254 added−188 removed

modified:examples/aliases/aliases.py+3 added-2 removed
1import os23import click45try:5 import ConfigParser as configparser6except ImportError:6 import configparser7except ImportError:8 import ConfigParser as configparser91011class Config(object):12 """The config in this example only holds aliases."""
124 unmodified lines
modified:examples/bashcompletion/bashcompletion.py+2 added-1 removed
1import click1import os23import click456@click.group()7def cli():8 pass9
37 unmodified lines
modified:examples/complex/complex/commands/cmd_init.py+2 added-1 removed
1import click1from complex.cli import pass_environment23import click456@click.command('init', short_help='Initializes a repo.')7@click.argument('path', required=False, type=click.Path(resolve_path=True))8@pass_environment9def cli(ctx, path):
5 unmodified lines
modified:examples/complex/complex/commands/cmd_status.py+2 added-1 removed
1import click1from complex.cli import pass_environment23import click456@click.command('status', short_help='Shows file changes.')7@pass_environment8def cli(ctx):9 """Shows file changes in the current working directory."""
2 unmodified lines
modified:examples/complex/complex/cli.py+1 added
1import os2import sys34import click567CONTEXT_SETTINGS = dict(auto_envvar_prefix='COMPLEX')
59 unmodified lines
modified:examples/imagepipe/imagepipe.py+6 added-2 removed
1import click1from functools import update_wrapper3from PIL import Image, ImageFilter, ImageEnhance23from PIL import Image4from PIL import ImageEnhance5from PIL import ImageFilter67import click8910@click.group(chain=True)11def cli():12 """This script processes a bunch of images through pillow in a unix13 pipe. One commands feeds into the next.
257 unmodified lines
modified:examples/repo/repo.py+1 added-1 removed
1import os2import sys2import posixpath3import sys45import click67
144 unmodified lines
modified:examples/termui/termui.py+4 added-8 removed
1# coding: utf-82import click2import math4import time3import random4import time57try:8 range_type = xrange9except NameError:10 range_type = range6import click789@click.group()10def cli():
12 unmodified lines
23@cli.command()24def pager():25 """Demonstrates using the pager."""26 lines = []31 for x in range_type(200):27 for x in range(200):28 lines.append('%s. Hello World!' % click.style(str(x), fg='green'))29 click.echo_via_pager('\n'.join(lines))3031
1 unmodified line
33@click.option('--count', default=8000, type=click.IntRange(1, 100000),34 help='The number of items to process.')35def progress(count):36 """Demonstrates the progress bar."""41 items = range_type(count)37 items = range(count)3839 def process_slowly(item):40 time.sleep(0.002 * random.random())41
111 unmodified lines
modified:examples/validation/validation.py+1 added
1import click23try:4 from urllib import parse as urlparse5except ImportError:6 import urlparse
39 unmodified lines
modified:src/click/__init__.py+65 added-77 removed
1# -*- coding: utf-8 -*-1"""2Click is a simple Python module inspired by the stdlib optparse to make3writing command line scripts fun. Unlike other modules, it's based4around a simple API that does not come with too much magic and is5composable.6"""89# Core classes10from .core import Context, BaseCommand, Command, MultiCommand, Group, \11 CommandCollection, Parameter, Option, Argument1213# Globals7from .core import Argument8from .core import BaseCommand9from .core import Command10from .core import CommandCollection11from .core import Context12from .core import Group13from .core import MultiCommand14from .core import Option15from .core import Parameter16from .decorators import argument17from .decorators import command18from .decorators import confirmation_option19from .decorators import group20from .decorators import help_option21from .decorators import make_pass_decorator22from .decorators import option23from .decorators import pass_context24from .decorators import pass_obj25from .decorators import password_option26from .decorators import version_option27from .exceptions import Abort28from .exceptions import BadArgumentUsage29from .exceptions import BadOptionUsage30from .exceptions import BadParameter31from .exceptions import ClickException32from .exceptions import FileError33from .exceptions import MissingParameter34from .exceptions import NoSuchOption35from .exceptions import UsageError36from .formatting import HelpFormatter37from .formatting import wrap_text38from .globals import get_current_context1516# Decorators17from .decorators import pass_context, pass_obj, make_pass_decorator, \18 command, group, argument, option, confirmation_option, \19 password_option, version_option, help_option2021# Types22from .types import ParamType, File, Path, Choice, IntRange, Tuple, \23 DateTime, STRING, INT, FLOAT, BOOL, UUID, UNPROCESSED, FloatRange2425# Utilities26from .utils import echo, get_binary_stream, get_text_stream, open_file, \27 format_filename, get_app_dir, get_os_args2829# Terminal functions30from .termui import prompt, confirm, get_terminal_size, echo_via_pager, \31 progressbar, clear, style, unstyle, secho, edit, launch, getchar, \32 pause3334# Exceptions35from .exceptions import ClickException, UsageError, BadParameter, \36 FileError, Abort, NoSuchOption, BadOptionUsage, BadArgumentUsage, \37 MissingParameter3839# Formatting40from .formatting import HelpFormatter, wrap_text4142# Parsing39from .parser import OptionParser40from .termui import clear41from .termui import confirm42from .termui import echo_via_pager43from .termui import edit44from .termui import get_terminal_size45from .termui import getchar46from .termui import launch47from .termui import pause48from .termui import progressbar49from .termui import prompt50from .termui import secho51from .termui import style52from .termui import unstyle53from .types import BOOL54from .types import Choice55from .types import DateTime56from .types import File57from .types import FLOAT58from .types import FloatRange59from .types import INT60from .types import IntRange61from .types import ParamType62from .types import Path63from .types import STRING64from .types import Tuple65from .types import UNPROCESSED66from .types import UUID67from .utils import echo68from .utils import format_filename69from .utils import get_app_dir70from .utils import get_binary_stream71from .utils import get_os_args72from .utils import get_text_stream73from .utils import open_file744546__all__ = [47 # Core classes48 'Context', 'BaseCommand', 'Command', 'MultiCommand', 'Group',49 'CommandCollection', 'Parameter', 'Option', 'Argument',5051 # Globals52 'get_current_context',5354 # Decorators55 'pass_context', 'pass_obj', 'make_pass_decorator', 'command', 'group',56 'argument', 'option', 'confirmation_option', 'password_option',57 'version_option', 'help_option',5859 # Types60 'ParamType', 'File', 'Path', 'Choice', 'IntRange', 'Tuple',61 'DateTime', 'STRING', 'INT', 'FLOAT', 'BOOL', 'UUID', 'UNPROCESSED',62 'FloatRange',6364 # Utilities65 'echo', 'get_binary_stream', 'get_text_stream', 'open_file',66 'format_filename', 'get_app_dir', 'get_os_args',6768 # Terminal functions69 'prompt', 'confirm', 'get_terminal_size', 'echo_via_pager',70 'progressbar', 'clear', 'style', 'unstyle', 'secho', 'edit', 'launch',71 'getchar', 'pause',7273 # Exceptions74 'ClickException', 'UsageError', 'BadParameter', 'FileError',75 'Abort', 'NoSuchOption', 'BadOptionUsage', 'BadArgumentUsage',76 'MissingParameter',7778 # Formatting79 'HelpFormatter', 'wrap_text',8081 # Parsing82 'OptionParser',83]848575# Controls if click should emit the warning about the use of unicode76# literals.77disable_unicode_literals_warning = False789079__version__ = '7.1.dev'
modified:src/click/_bashcomplete.py+4 added-2 removed
1import copy2import os3import re45from .utils import echo5from .core import Argument6from .core import MultiCommand7from .core import Option8from .parser import split_arg_string7from .core import MultiCommand, Option, Argument9from .types import Choice10from .utils import echo1112try:13 from collections import abc14except ImportError:
322 unmodified lines
modified:src/click/_compat.py+2 added-3 removed
1import re1import codecs2import io3import os4import re5import sys5import codecs6from weakref import WeakKeyDictionary788PY2 = sys.version_info[0] == 29CYGWIN = sys.platform.startswith('cygwin')10MSYS2 = sys.platform.startswith('win') and ('GCC' in sys.version)11# Determine local App Engine environment, per Google's own suggestion
762 unmodified lines
modified:src/click/_termui_impl.py+15 added-8 removed
2 unmodified lines
3This module contains implementations for the termui module. To keep the4import time of Click down, some infrequently used functionality is5placed in this module and only imported as needed.6"""77import contextlib8import math9import os10import sys11import time11import math12import contextlib13from ._compat import _default_text_stdout, range_type, isatty, \14 open_stream, shlex_quote, strip_ansi, term_len, get_best_encoding, WIN, \15 int_types, CYGWIN16from .utils import echo1213from ._compat import _default_text_stdout14from ._compat import CYGWIN15from ._compat import get_best_encoding16from ._compat import int_types17from ._compat import isatty18from ._compat import open_stream19from ._compat import range_type20from ._compat import shlex_quote21from ._compat import strip_ansi22from ._compat import term_len23from ._compat import WIN24from .exceptions import ClickException25from .utils import echo261927if os.name == 'nt':28 BEFORE_BAR = '\r'29 AFTER_BAR = '\n'30else:
609 unmodified lines
modified:src/click/_unicodefun.py+1 added-2 removed
1import codecs2import os3import sys3import codecs45from ._compat import PY2677# If someone wants to vendor click, we want to ensure the8# correct package is discovered. Ideally we could use a9# relative import here but unfortunately Python does not10# support that.
114 unmodified lines
modified:src/click/_winconsole.py+24 added-8 removed
5 unmodified lines
6# There are some general differences in regards to how this works7# compared to the original patches as we do not need to patch8# the entire interpreter but just work in our little world of9# echo and prmopt.1010import ctypes11import io12import os13import sys14import zlib14import time16import ctypes15import zlib16from ctypes import byref17from ctypes import c_char18from ctypes import c_char_p19from ctypes import c_int20from ctypes import c_ssize_t21from ctypes import c_ulong22from ctypes import c_void_p23from ctypes import POINTER24from ctypes import py_object25from ctypes import windll26from ctypes import WinError27from ctypes import WINFUNCTYPE28from ctypes.wintypes import DWORD29from ctypes.wintypes import HANDLE30from ctypes.wintypes import LPCWSTR31from ctypes.wintypes import LPWSTR3233import msvcrt18from ._compat import _NonClosingTextIOWrapper, text_type, PY219from ctypes import byref, POINTER, c_int, c_char, c_char_p, \20 c_void_p, py_object, c_ssize_t, c_ulong, windll, WINFUNCTYPE, \21 WinError3435from ._compat import _NonClosingTextIOWrapper36from ._compat import PY237from ._compat import text_type3839try:40 from ctypes import pythonapi41 PyObject_GetBuffer = pythonapi.PyObject_GetBuffer42 PyBuffer_Release = pythonapi.PyBuffer_Release43except ImportError:44 pythonapi = None28from ctypes.wintypes import DWORD, LPWSTR, LPCWSTR, HANDLE454647c_ssize_p = POINTER(c_ssize_t)48
298 unmodified lines
modified:src/click/core.py+30 added-15 removed
1 unmodified line
2import inspect3import os4import sys5from contextlib import contextmanager6from itertools import repeat6from functools import update_wrapper7from itertools import repeat89from .types import convert_type, IntRange, BOOL10from .utils import PacifyFlushWrapper, make_str, make_default_short_help, \11 echo, get_os_args12from .exceptions import ClickException, UsageError, BadParameter, Abort, \13 MissingParameter, Exit14from .termui import prompt, confirm, style15from .formatting import HelpFormatter, join_options16from .parser import OptionParser, split_opt17from .globals import push_context, pop_context9from ._compat import isidentifier10from ._compat import iteritems11from ._compat import PY212from ._compat import string_types13from ._unicodefun import _check_for_unicode_literals14from ._unicodefun import _verify_python3_env15from .exceptions import Abort16from .exceptions import BadParameter17from .exceptions import ClickException18from .exceptions import Exit19from .exceptions import MissingParameter20from .exceptions import UsageError21from .formatting import HelpFormatter22from .formatting import join_options23from .globals import pop_context24from .globals import push_context25from .parser import OptionParser26from .parser import split_opt27from .termui import confirm28from .termui import prompt29from .termui import style30from .types import BOOL31from .types import convert_type32from .types import IntRange33from .utils import echo34from .utils import get_os_args35from .utils import make_default_short_help36from .utils import make_str37from .utils import PacifyFlushWrapper3819from ._compat import PY2, isidentifier, iteritems, string_types20from ._unicodefun import _check_for_unicode_literals, _verify_python3_env212239_missing = object()402541SUBCOMMAND_METAVAR = 'COMMAND [ARGS]...'42SUBCOMMANDS_METAVAR = 'COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]...'4344DEPRECATED_HELP_NOTICE = ' (DEPRECATED)'
1872 unmodified lines
modified:src/click/decorators.py+2 added-3 removed
1import sys1import inspect32import sys3from functools import update_wrapper45from ._compat import iteritems6from ._unicodefun import _check_for_unicode_literals8from .utils import echo7from .globals import get_current_context8from .utils import echo91011def pass_context(f):12 """Marks a callback as wanting to receive the current context
298 unmodified lines
modified:src/click/exceptions.py+3 added-1 removed
1from ._compat import PY2, filename_to_ui, get_text_stderr1from ._compat import filename_to_ui2from ._compat import get_text_stderr3from ._compat import PY24from .utils import echo567def _join_param_hints(param_hint):
243 unmodified lines
modified:src/click/formatting.py+3 added-3 removed
1from contextlib import contextmanager2from .termui import get_terminal_size3from .parser import split_opt23from ._compat import term_len4from .parser import split_opt5from .termui import get_terminal_size667# Can force a width. This is used by the test system8FORCED_WIDTH = None910
252 unmodified lines
modified:src/click/globals.py-1 removed
1from threading import local233_local = local()456def get_current_context(silent=False):
41 unmodified lines
modified:src/click/parser.py+5 added-3 removed
16 unmodified lines
1718Copyright 2001-2006 Gregory P. Ward. All rights reserved.19Copyright 2002-2006 Python Software Foundation. All rights reserved.20"""2121import re22from collections import deque24from .exceptions import UsageError, NoSuchOption, BadOptionUsage, \25 BadArgumentUsage2324from .exceptions import BadArgumentUsage25from .exceptions import BadOptionUsage26from .exceptions import NoSuchOption27from .exceptions import UsageError282930def _unpack_args(args, nargs_spec):31 """Given an iterable of arguments and an iterable of nargs specifications,32 it returns a tuple with all the unpacked arguments at the first index33 and all remaining arguments as the second.
399 unmodified lines
modified:src/click/termui.py+17 added-9 removed
1import inspect2import io3import itertools4import os3import sys5import struct5import inspect6import itertools6import sys78from ._compat import raw_input, text_type, string_types, \9 isatty, strip_ansi, get_winterm_size, DEFAULT_COLUMNS, WIN10from .utils import echo11from .exceptions import Abort, UsageError12from .types import convert_type, Choice, Path8from ._compat import DEFAULT_COLUMNS9from ._compat import get_winterm_size10from ._compat import isatty11from ._compat import raw_input12from ._compat import string_types13from ._compat import strip_ansi14from ._compat import text_type15from ._compat import WIN16from .exceptions import Abort17from .exceptions import UsageError18from .globals import resolve_color_default19from .types import Choice20from .types import convert_type21from .types import Path22from .utils import echo23from .utils import LazyFile241625# The prompt functions to use. The doc tools currently override these26# functions to customize how they work.27visible_prompt_func = raw_input28
601 unmodified lines
modified:src/click/testing.py+6 added-5 removed
1import contextlib2import os2import sys3import shlex4import shutil5import sys6import tempfile5import contextlib6import shlex78from ._compat import iteritems, PY2, string_types8from ._compat import iteritems9from ._compat import PY210from ._compat import string_types111012# If someone wants to vendor click, we want to ensure the13# correct package is discovered. Ideally we could use a14# relative import here but unfortunately Python does not15# support that.
363 unmodified lines
modified:src/click/types.py+9 added-3 removed
1import os2import stat3from datetime import datetime45from ._compat import open_stream, text_type, filename_to_ui, \6 get_filesystem_encoding, get_streerror, _get_argv_encoding, PY25from ._compat import _get_argv_encoding6from ._compat import filename_to_ui7from ._compat import get_filesystem_encoding8from ._compat import get_streerror9from ._compat import open_stream10from ._compat import PY211from ._compat import text_type12from .exceptions import BadParameter8from .utils import safecall, LazyFile13from .utils import LazyFile14from .utils import safecall151617class ParamType(object):18 """Helper for converting values through types. The following is
667 unmodified lines
modified:src/click/utils.py+19 added-8 removed
1import os2import sys34from ._compat import _default_text_stderr5from ._compat import _default_text_stdout6from ._compat import auto_wrap_for_ansi7from ._compat import binary_streams8from ._compat import filename_to_ui9from ._compat import get_filesystem_encoding10from ._compat import get_streerror11from ._compat import is_bytes12from ._compat import open_stream13from ._compat import PY214from ._compat import should_strip_ansi15from ._compat import string_types16from ._compat import strip_ansi17from ._compat import text_streams18from ._compat import text_type19from ._compat import WIN20from .globals import resolve_color_default216from ._compat import text_type, open_stream, get_filesystem_encoding, \7 get_streerror, string_types, PY2, binary_streams, text_streams, \8 filename_to_ui, auto_wrap_for_ansi, strip_ansi, should_strip_ansi, \9 _default_text_stdout, _default_text_stderr, is_bytes, WIN1022if not PY2:23 from ._compat import _find_binary_writer24elif WIN:14 from ._winconsole import _get_windows_argv, \15 _hash_py_argv, _initial_argv_hash25 from ._winconsole import _get_windows_argv26 from ._winconsole import _hash_py_argv27 from ._winconsole import _initial_argv_hash281729echo_native_types = string_types + (bytes, bytearray)303132def _posixify(name):
419 unmodified lines
modified:tests/conftest.py+2 added-2 removed
1from click.testing import CliRunner21import pytest23from click.testing import CliRunner456@pytest.fixture(scope='function')7def runner(request):8 return CliRunner()
modified:tests/test_arguments.py+5 added-2 removed
1# -*- coding: utf-8 -*-2import sys34import pytest56import click4import sys5from click._compat import PY2, text_type7from click._compat import PY28from click._compat import text_type91011def test_nargs_star(runner):12 @click.command()
319 unmodified lines
modified:tests/test_bashcomplete.py-1 removed
1# -*- coding: utf-8 -*-22import pytest34import click5from click._bashcomplete import get_choices
430 unmodified lines
modified:tests/test_basic.py+1 added
1# -*- coding: utf-8 -*-2import os3import uuid45import click678def test_basic_functionality(runner):
547 unmodified lines
modified:tests/test_chain.py+3 added-1 removed
1import sys2import click23import pytest45import click678def debug():9 click.echo('%s=%s' % (10 sys._getframe(1).f_code.co_name,11 '|'.join(click.get_current_context().args),
243 unmodified lines
modified:tests/test_commands.py-1 removed
1# -*- coding: utf-8 -*-2import re34import click5import pytest567def test_other_command_invoke(runner):8 @click.command()
284 unmodified lines
modified:tests/test_compat.py+4 added-2 removed
1import click1import pytest3from click._compat import should_strip_ansi, WIN23import click4from click._compat import should_strip_ansi5from click._compat import WIN678def test_legacy_callbacks(runner):9 def legacy_callback(ctx, value):10 return value.upper()11
34 unmodified lines
modified:tests/test_imports.py+1 added-1 removed
1import sys1import json2import subprocess3import sys45from click._compat import WIN67
48 unmodified lines
modified:tests/test_options.py+3 added-2 removed
1# -*- coding: utf-8 -*-2import re2import os4import click3import re45import pytest67import click8from click._compat import text_type91011def test_prefixes(runner):
546 unmodified lines
modified:tests/test_termui.py+2 added-3 removed
1# -*- coding: utf-8 -*-2import pytest34import click2import time34import pytest56import click._termui_impl7from click._compat import WIN89
303 unmodified lines
modified:tests/test_testing.py+3 added-3 removed
1import os2import sys34import pytest5import click56import click7from click._compat import PY28from click._compat import WIN9from click.testing import CliRunner109from click._compat import PY2, WIN1011# Use the most reasonable io that users would use for the python version.12if PY2:13 from cStringIO import StringIO as ReasonableBytesIO14else:
287 unmodified lines
modified:tests/test_utils.py+3 added-3 removed
2 unmodified lines
3import sys45import pytest67import click8import click.utils7import click._termui_impl8import click.utils10from click._compat import WIN, PY29from click._compat import PY210from click._compat import WIN111213def test_echo(runner):14 with runner.isolation() as outstreams:
385 unmodified lines