diff options
| author | David Lord <davidism@gmail.com> | 2020-03-06 14:38:03 -0800 |
|---|---|---|
| committer | David Lord <davidism@gmail.com> | 2020-03-06 14:38:03 -0800 |
| commit | 5f75f9ec38ccf2ddac4e6b92cc07fec6d9b1b7e0 (patch) | |
| tree | aa8b7c6a539db2615e659ae81fa42af7527a78ea /src/click | |
| parent | 93ba3ba112d2f8ba7bdd8b231e510f74dd0b037e (diff) | |
| download | click-5f75f9ec38ccf2ddac4e6b92cc07fec6d9b1b7e0.tar.gz | |
apply flake8
Diffstat (limited to 'src/click')
| -rw-r--r-- | src/click/_bashcomplete.py | 42 | ||||
| -rw-r--r-- | src/click/_compat.py | 1 | ||||
| -rw-r--r-- | src/click/core.py | 18 | ||||
| -rw-r--r-- | src/click/decorators.py | 12 | ||||
| -rw-r--r-- | src/click/exceptions.py | 2 | ||||
| -rw-r--r-- | src/click/globals.py | 2 | ||||
| -rw-r--r-- | src/click/termui.py | 2 | ||||
| -rw-r--r-- | src/click/testing.py | 2 | ||||
| -rw-r--r-- | src/click/types.py | 8 | ||||
| -rw-r--r-- | src/click/utils.py | 2 |
10 files changed, 51 insertions, 40 deletions
diff --git a/src/click/_bashcomplete.py b/src/click/_bashcomplete.py index bbd45a0..815eb02 100644 --- a/src/click/_bashcomplete.py +++ b/src/click/_bashcomplete.py @@ -30,7 +30,8 @@ COMPLETION_SCRIPT_BASH = """ local COMPLETION_OPTIONS="" local BASH_VERSION_ARR=(${BASH_VERSION//./ }) # Only BASH version 4.4 and later have the nosort option. - if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then + if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] \ +&& [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then COMPLETION_OPTIONS="-o nosort" fi @@ -75,9 +76,12 @@ COMPLETION_SCRIPT_ZSH = """ compdef %(complete_func)s %(script_names)s """ -COMPLETION_SCRIPT_FISH = """ -complete --no-files --command %(script_names)s --arguments "(env %(autocomplete_var)s=complete_fish COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) %(script_names)s)" -""" +COMPLETION_SCRIPT_FISH = ( + "complete --no-files --command %(script_names)s --arguments" + ' "(env %(autocomplete_var)s=complete_fish' + " COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t)" + ' %(script_names)s)"' +) _completion_scripts = { "bash": COMPLETION_SCRIPT_BASH, @@ -102,8 +106,9 @@ def get_completion_script(prog_name, complete_var, shell): def resolve_ctx(cli, prog_name, args): - """ - Parse into a hierarchy of contexts. Contexts are connected through the parent variable. + """Parse into a hierarchy of contexts. Contexts are connected + through the parent variable. + :param cli: command definition :param prog_name: the program that is running :param args: full list of args @@ -146,7 +151,8 @@ def resolve_ctx(cli, prog_name, args): def start_of_option(param_str): """ :param param_str: param_str to check - :return: whether or not this is the start of an option declaration (i.e. starts "-" or "--") + :return: whether or not this is the start of an option declaration + (i.e. starts "-" or "--") """ return param_str and param_str[:1] == "-" @@ -155,9 +161,10 @@ def is_incomplete_option(all_args, cmd_param): """ :param all_args: the full original list of args supplied :param cmd_param: the current command paramter - :return: whether or not the last option declaration (i.e. starts "-" or "--") is incomplete and - corresponds to this cmd_param. In other words whether this cmd_param option can still accept - values + :return: whether or not the last option declaration (i.e. starts + "-" or "--") is incomplete and corresponds to this cmd_param. In + other words whether this cmd_param option can still accept + values """ if not isinstance(cmd_param, Option): return False @@ -177,10 +184,12 @@ def is_incomplete_option(all_args, cmd_param): def is_incomplete_argument(current_params, cmd_param): """ - :param current_params: the current params and values for this argument as already entered + :param current_params: the current params and values for this + argument as already entered :param cmd_param: the current command parameter - :return: whether or not the last argument is incomplete and corresponds to this cmd_param. In - other words whether or not the this cmd_param argument can still accept values + :return: whether or not the last argument is incomplete and + corresponds to this cmd_param. In other words whether or not the + this cmd_param argument can still accept values """ if not isinstance(cmd_param, Argument): return False @@ -245,7 +254,8 @@ def add_subcommand_completions(ctx, incomplete, completions_out): ] ) - # Walk up the context list and add any other completion possibilities from chained commands + # Walk up the context list and add any other completion + # possibilities from chained commands while ctx.parent is not None: ctx = ctx.parent if isinstance(ctx.command, MultiCommand) and ctx.command.chain: @@ -275,8 +285,8 @@ def get_choices(cli, prog_name, args, incomplete): has_double_dash = "--" in all_args - # In newer versions of bash long opts with '='s are partitioned, but it's easier to parse - # without the '=' + # In newer versions of bash long opts with '='s are partitioned, but + # it's easier to parse without the '=' if start_of_option(incomplete) and WORDBREAK in incomplete: partition_incomplete = incomplete.partition(WORDBREAK) all_args.append(partition_incomplete[0]) diff --git a/src/click/_compat.py b/src/click/_compat.py index 6431fc2..5caa593 100644 --- a/src/click/_compat.py +++ b/src/click/_compat.py @@ -1,3 +1,4 @@ +# flake8: noqa import codecs import io import os diff --git a/src/click/core.py b/src/click/core.py index ea46e86..937d747 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -42,9 +42,7 @@ SUBCOMMAND_METAVAR = "COMMAND [ARGS]..." SUBCOMMANDS_METAVAR = "COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]..." DEPRECATED_HELP_NOTICE = " (DEPRECATED)" -DEPRECATED_INVOKE_NOTICE = ( - "DeprecationWarning: " + "The command %(name)s is deprecated." -) +DEPRECATED_INVOKE_NOTICE = "DeprecationWarning: The command %(name)s is deprecated." def _maybe_show_deprecated_notice(cmd): @@ -578,7 +576,7 @@ class Context(object): """ return self.command.get_help(self) - def invoke(*args, **kwargs): + def invoke(*args, **kwargs): # noqa: B902 """Invokes a command callback in exactly the way it expects. There are two ways to invoke this method: @@ -618,7 +616,7 @@ class Context(object): with ctx: return callback(*args, **kwargs) - def forward(*args, **kwargs): + def forward(*args, **kwargs): # noqa: B902 """Similar to :meth:`invoke` but fills in default keyword arguments from the current context if the other command expects it. This cannot invoke callbacks directly, only other commands. @@ -985,7 +983,9 @@ class Command(BaseCommand): return formatter.getvalue().rstrip("\n") def get_short_help_str(self, limit=45): - """Gets short help for the command or makes it by shortening the long help string.""" + """Gets short help for the command or makes it by shortening the + long help string. + """ return ( self.short_help or self.help @@ -1362,6 +1362,7 @@ class Group(MultiCommand): immediately registers the created command with this instance by calling into :meth:`add_command`. """ + from .decorators import command def decorator(f): cmd = command(*args, **kwargs)(f) @@ -1376,6 +1377,7 @@ class Group(MultiCommand): immediately registers the created command with this instance by calling into :meth:`add_command`. """ + from .decorators import group def decorator(f): cmd = group(*args, **kwargs)(f) @@ -2037,7 +2039,3 @@ class Argument(Parameter): def add_to_parser(self, parser, ctx): parser.add_argument(dest=self.name, nargs=self.nargs, obj=self) - - -# Circular dependency between decorators and core -from .decorators import command, group diff --git a/src/click/decorators.py b/src/click/decorators.py index 5f556e2..7e10adb 100644 --- a/src/click/decorators.py +++ b/src/click/decorators.py @@ -4,6 +4,10 @@ from functools import update_wrapper from ._compat import iteritems from ._unicodefun import _check_for_unicode_literals +from .core import Argument +from .core import Command +from .core import Group +from .core import Option from .globals import get_current_context from .utils import echo @@ -283,13 +287,13 @@ def version_option(version=None, *param_decls, **attrs): else: for dist in pkg_resources.working_set: scripts = dist.get_entry_map().get("console_scripts") or {} - for script_name, entry_point in iteritems(scripts): + for _, entry_point in iteritems(scripts): if entry_point.module_name == module: ver = dist.version break if ver is None: raise RuntimeError("Could not determine version") - echo(message % {"prog": prog, "version": ver,}, color=ctx.color) + echo(message % {"prog": prog, "version": ver}, color=ctx.color) ctx.exit() attrs.setdefault("is_flag", True) @@ -327,7 +331,3 @@ def help_option(*param_decls, **attrs): return option(*(param_decls or ("--help",)), **attrs)(f) return decorator - - -# Circular dependencies between core and decorators -from .core import Command, Group, Argument, Option diff --git a/src/click/exceptions.py b/src/click/exceptions.py index a06400b..2e2199b 100644 --- a/src/click/exceptions.py +++ b/src/click/exceptions.py @@ -248,5 +248,7 @@ class Exit(RuntimeError): :param code: the status code to exit with. """ + __slots__ = ("exit_code",) + def __init__(self, code=0): self.exit_code = code diff --git a/src/click/globals.py b/src/click/globals.py index a0157fc..1649f9a 100644 --- a/src/click/globals.py +++ b/src/click/globals.py @@ -19,7 +19,7 @@ def get_current_context(silent=False): :exc:`RuntimeError`. """ try: - return getattr(_local, "stack")[-1] + return _local.stack[-1] except (AttributeError, IndexError): if not silent: raise RuntimeError("There is no active click context.") diff --git a/src/click/termui.py b/src/click/termui.py index eb1baa8..d5239e7 100644 --- a/src/click/termui.py +++ b/src/click/termui.py @@ -156,7 +156,7 @@ def prompt( try: result = value_proc(value) except UsageError as e: - echo("Error: %s" % e.message, err=err) + echo("Error: %s" % e.message, err=err) # noqa: B306 continue if not confirmation_prompt: return result diff --git a/src/click/testing.py b/src/click/testing.py index c50418f..6ad06fb 100644 --- a/src/click/testing.py +++ b/src/click/testing.py @@ -382,5 +382,5 @@ class CliRunner(object): os.chdir(cwd) try: shutil.rmtree(t) - except (OSError, IOError): + except (OSError, IOError): # noqa: B014 pass diff --git a/src/click/types.py b/src/click/types.py index 1d3d5b3..0987190 100644 --- a/src/click/types.py +++ b/src/click/types.py @@ -261,7 +261,7 @@ class IntParamType(ParamType): def convert(self, value, param, ctx): try: return int(value) - except (ValueError, UnicodeError): + except ValueError: self.fail("%s is not a valid integer" % value, param, ctx) def __repr__(self): @@ -329,7 +329,7 @@ class FloatParamType(ParamType): def convert(self, value, param, ctx): try: return float(value) - except (UnicodeError, ValueError): + except ValueError: self.fail("%s is not a valid floating point value" % value, param, ctx) def __repr__(self): @@ -418,7 +418,7 @@ class UUIDParameterType(ParamType): if PY2 and isinstance(value, text_type): value = value.encode("ascii") return uuid.UUID(value) - except (UnicodeError, ValueError): + except ValueError: self.fail("%s is not a valid UUID value" % value, param, ctx) def __repr__(self): @@ -502,7 +502,7 @@ class File(ParamType): else: ctx.call_on_close(safecall(f.flush)) return f - except (IOError, OSError) as e: + except (IOError, OSError) as e: # noqa: B014 self.fail( "Could not open file: %s: %s" % (filename_to_ui(value), get_streerror(e),), diff --git a/src/click/utils.py b/src/click/utils.py index 210bbe4..4e97d84 100644 --- a/src/click/utils.py +++ b/src/click/utils.py @@ -126,7 +126,7 @@ class LazyFile(object): rv, self.should_close = open_stream( self.name, self.mode, self.encoding, self.errors, atomic=self.atomic ) - except (IOError, OSError) as e: + except (IOError, OSError) as e: # noqa: E402 from .exceptions import FileError raise FileError(self.name, hint=get_streerror(e)) |
