Miscellaneous documentation & docstring changes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kevin Yap · committed by Kevin Yap · parent b131df8 · Browse files · 14 files·+124 added−128 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
14 files+124 added−128 removed
- other:+124 added−128 removed
Provenance
- Commit
0f894fa- Tree
5ca4cee- Author
Kevin Yap <me@kevinyap.ca>- Committer
Kevin Yap <me@kevinyap.ca>- Parent
b131df8
14 files changed+124 added−128 removed
modified:click/__init__.py+3 added-3 removed
1 unmodified line2 """3 click4 ~~~~~5 6- click is a simple Python module that wraps the stdlib's optparse to make7- writing command line scripts fun. Unlike other modules it's based around6+ Click is a simple Python module that wraps the stdlib's optparse to make7+ writing command line scripts fun. Unlike other modules, it's based around8 a simple API that does not come with too much magic and is composable.9 10- In case optparse ever goes away from the stdlib it will be shipped by10+ In case optparse ever gets removed from the stdlib, it will be shipped by11 this module.12 13 :copyright: (c) 2014 by Armin Ronacher.14 :license: BSD, see LICENSE for more details.71 unmodified linesmodified:click/_compat.py+33 added-36 removed
41 unmodified lines42 def __init__(self, stream, encoding, errors, **extra):43 io.TextIOWrapper.__init__(self, _FixupStream(stream),44 encoding, errors, **extra)45 46- # The io module is already a place where Python 2 got the47- # python 3 text behavior forced on, so we need to unbreak48- # it to look like python 2 stuff.46+ # The io module is a place where the Python 3 text behavior47+ # was forced upon Python 2, so we need to unbreak48+ # it to look like Python 2.49 if PY2:50 def write(self, x):51 if isinstance(x, str) or is_bytes(x):52 try:15 unmodified lines68 69 70 class _FixupStream(object):71 """The new io interface needs more from streams than streams72- traditionally implement. As such this fixup stuff is necessary in72+ traditionally implement. As such, this fix-up code is necessary in73 some circumstances.74 """75 76 def __init__(self, stream):5 unmodified lines82 def read1(self, size):83 f = getattr(self._stream, 'read1', None)84 if f is not None:85 return f(size)86- # Only python 2 we dispatch to readline instead of read as we86+ # We only dispatch to readline instead of read in Python 2 as we87 # do not want cause problems with the different implementation88 # of line buffering.89 if PY2:90 return self._stream.readline(size)45 unmodified lines136 return isinstance(x, (buffer, bytearray))137 138 _identifier_re = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$')139 140- # For Windows we need to force stdout/stdin/stderr to binary if it's140+ # For Windows, we need to force stdout/stdin/stderr to binary if it's141 # fetched for that. This obviously is not the most correct way to do142- # it as it changes global state. Unfortunately there does not seem to142+ # it as it changes global state. Unfortunately, there does not seem to143 # be a clear better way to do it as just reopening the file in binary144 # mode does not change anything.145 #146- # An option would be to do what python 3 does and to open the file as147- # binary only, patch it back to the system and then use a wrapper146+ # An option would be to do what Python 3 does and to open the file as147+ # binary only, patch it back to the system, and then use a wrapper148 # stream that converts newlines. It's not quite clear what's the149 # correct option here.150 if sys.platform == 'win32':151 import msvcrt50 unmodified lines202 return isinstance(stream.read(0), bytes)203 except Exception:204 return default205 # This happens in some cases where the stream was already206- # closed. In this case we assume the defalt.206+ # closed. In this case, we assume the default.207 208 def _is_binary_writer(stream, default=False):209 try:210 stream.write(b'')7 unmodified lines218 return True219 220 def _find_binary_reader(stream):221 # We need to figure out if the given stream is already binary.222- # This can happen because the official docs recommend detatching222+ # This can happen because the official docs recommend detaching223 # the streams to get binary streams. Some code might do this, so224 # we need to deal with this case explicitly.225- is_binary = _is_binary_reader(stream, False)226-227- if is_binary:225+ if _is_binary_reader(stream, False):226 return stream227 228 buf = getattr(stream, 'buffer', None)229+231- # Same situation here, this time we assume that the buffer is230+ # Same situation here; this time we assume that the buffer is231 # actually binary in case it's closed.232 if buf is not None and _is_binary_reader(buf, True):233 return buf234 6 unmodified lines241 return stream242 243 buf = getattr(stream, 'buffer', None)244 246- # Same situation here, this time we assume that the buffer is245+ # Same situation here; this time we assume that the buffer is246 # actually binary in case it's closed.247 if buf is not None and _is_binary_writer(buf, True):248 return buf249 250 def _stream_is_misconfigured(stream):252- """A stream is misconfigured if it's encoding is ASCII."""251+ """A stream is misconfigured if its encoding is ASCII."""252 return is_ascii_encoding(getattr(stream, 'encoding', None))253 254 def _is_compatible_text_stream(stream, encoding, errors):255 stream_encoding = getattr(stream, 'encoding', None)2 unmodified lines258 # Perfect match.259 if stream_encoding == encoding and stream_errors == errors:260 return True261 263- # Otherwise it's only a compatible stream if we did not ask for262+ # Otherwise, it's only a compatible stream if we did not ask for263 # an encoding.264 if encoding is None:265 return stream_encoding is not None266 2 unmodified lines269 def _force_correct_text_reader(text_reader, encoding, errors):270 if _is_binary_reader(text_reader, False):271 binary_reader = text_reader272 else:274- # If there is no target encoding set we need to verify that the275- # reader is actually not misconfigured.273+ # If there is no target encoding set, we need to verify that the274+ # reader is not actually misconfigured.275 if encoding is None and not _stream_is_misconfigured(text_reader):276 return text_reader277 278 if _is_compatible_text_stream(text_reader, encoding, errors):279 return text_reader280 282- # If the reader has no encoding we try to find the underlying281+ # If the reader has no encoding, we try to find the underlying282 # binary reader for it. If that fails because the environment is283 # misconfigured, we silently go with the same reader because this285- # is too common to happen. In that case mojibake is better than284+ # is too common to happen. In that case, mojibake is better than285 # exceptions.286 binary_reader = _find_binary_reader(text_reader)287 if binary_reader is None:288 return text_reader289 291- # At this point we default the errors to replace instead of strict290+ # At this point, we default the errors to replace instead of strict291 # because nobody handles those errors anyways and at this point292 # we're so fundamentally fucked that nothing can repair it.293 if errors is None:294 errors = 'replace'2 unmodified lines297 def _force_correct_text_writer(text_writer, encoding, errors):298 if _is_binary_writer(text_writer, False):299 binary_writer = text_writer300 else:302- # If there is no target encoding set we need to verify that the303- # writer is actually not misconfigured.301+ # If there is no target encoding set, we need to verify that the302+ # writer is not actually misconfigured.303 if encoding is None and not _stream_is_misconfigured(text_writer):304 return text_writer305 306 if _is_compatible_text_stream(text_writer, encoding, errors):307 return text_writer308 310- # If the writer has no encoding we try to find the underlying309+ # If the writer has no encoding, we try to find the underlying310 # binary writer for it. If that fails because the environment is311 # misconfigured, we silently go with the same writer because this313- # is too common to happen. In that case mojibake is better than312+ # is too common to happen. In that case, mojibake is better than313 # exceptions.314 binary_writer = _find_binary_writer(text_writer)315 if binary_writer is None:316 return text_writer317 319- # At this point we default the errors to replace instead of strict318+ # At this point, we default the errors to replace instead of strict319 # because nobody handles those errors anyways and at this point320 # we're so fundamentally fucked that nothing can repair it.321 if errors is None:322 errors = 'replace'52 unmodified lines375 376 377 def open_stream(filename, mode='r', encoding=None, errors='strict',378 atomic=False):380- # standard streams first. These are simple because they don't need379+ # Standard streams first. These are simple because they don't need380 # special handling for the atomic flag. It's entirely ignored.381 if filename == '-':382 if 'w' in mode:383 if 'b' in mode:2 unmodified lines386 if 'b' in mode:387 return get_binary_stdin(), False388 return get_text_stdin(encoding=encoding, errors=errors), False389 391- # Non-atomic writes directly go out through the regular open392- # functions.390+ # Non-atomic writes directly go out through the regular open functions.391 if not atomic:392 if encoding is None:393 return open(filename, mode), True394 return io.open(filename, mode, encoding=encoding, errors=errors), True395 396 # Atomic writes are more complicated. They work by opening a file397 # as a proxy in the same folder and then using the fdopen400- # functionality to wrap it in a python file. Then we wrap it in an398+ # functionality to wrap it in a Python file. Then we wrap it in an399 # atomic file that moves the file over on close.400 import tempfile401 fd, tmp_filename = tempfile.mkstemp(dir=os.path.dirname(filename),402 prefix='.__atomic-write')5 unmodified lines408 409 return _AtomicFile(f, tmp_filename, filename), True410 411 414-# Used in a destructor call, needs extra protection from interpreter415-# cleanup.412+# Used in a destructor call, needs extra protection from interpreter cleanup.413 _rename = os.rename414 415 416 class _AtomicFile(object):31 unmodified lines448 auto_wrap_for_ansi = None449 colorama = None450 451 455-# If we're on windows we provide transparent integration through456-# colorama. This will make ansi colors through the echo function452+# If we're on Windows, we provide transparent integration through453+# colorama. This will make ANSI colors through the echo function454 # work automatically.455 if sys.platform.startswith('win'):456 try:457 import colorama69 unmodified linesmodified:click/_termui_impl.py+1 added-1 removed
1 unmodified line2 click._termui_impl3 ~~~~~~~~~~~~~~~~~~4 5 This module contains implementations for the termui module. To keep the6- import time of click down some infrequently used functionality is placed6+ import time of click down, some infrequently used functionality is placed7 in this module and only imported as needed.8 9 :copyright: (c) 2014 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.477 unmodified linesmodified:click/core.py+20 added-20 removed
36 unmodified lines37 code = getattr(callback, '__code__', None)38 args = getattr(code, 'co_argcount', 3)39 40 if args < 3:41- # This will become a warning in Click 3.042- ##from warnings import warn43- ##warn(Warning('Invoked legacy parameter callback "%s". The new '44- ## 'signature for such callbacks starting with '45- ## 'Click 2.0 is (ctx, param, value).'46- ## % callback), stacklevel=3)41+ # This will become a warning in click 3.0:42+ ## from warnings import warn43+ ## warn(Warning('Invoked legacy parameter callback "%s". The new '44+ ## 'signature for such callbacks starting with '45+ ## 'click 2.0 is (ctx, param, value).'46+ ## % callback), stacklevel=3)47 return callback(ctx, value)48 return callback(ctx, param, value)49 50 84 unmodified lines135 self.args = []136 #: this flag indicates if a subcommand is going to be executed.137 #: a group callback can use this information to figure out if it's138 #: being executed directly or because the execution flow passes139- #: onwards to a subcommand. By default it's `None` but it can be139+ #: onwards to a subcommand. By default it's `None`, but it can be140 #: the name of the subcommand to execute.141 self.invoked_subcommand = None142 if obj is None and parent is not None:143 obj = parent.obj144 #: the user object stored.145 self.obj = obj146- #: A dictionary (like object) with defaults for parameters.146+ #: A dictionary (-like object) with defaults for parameters.147 self.default_map = default_map148 149 if terminal_width is None and parent is not None:150 terminal_width = parent.terminal_width31 unmodified lines182 183 def call_on_close(self, f):184 """This decorator remembers a function as callback that should be185 executed when the context tears down. This is most useful to bind186- resource handling to the script execution. For instance file objects186+ resource handling to the script execution. For instance, file objects187 opened by the :class:`File` type will register their close callbacks188 here.189 190 :param f: the function to execute on teardown.126 unmodified lines317 Most code will never use this as it does not implement a lot of useful318 functionality but it can act as the direct subclass of alternative319 parsing methods that do not depend on the click parser.320 321- For instance this can be used to bridge click and other systems like321+ For instance, this can be used to bridge click and other systems like322 argparse or docopt.323 324 Because base commands do not implement a lot of the API that other325- parts of click take for granted they are not supported for all326- operations. For instance they cannot be used with the decorators325+ parts of click take for granted, they are not supported for all326+ operations. For instance, they cannot be used with the decorators327 usually and they have no built-in callback system.328 329 :param name: the name of the command to use unless a group overrides it.330 """94 unmodified lines425 if prog_name is None:426 prog_name = make_str(os.path.basename(427 sys.argv and sys.argv[0] or __file__))428 429- # Hook for the bash completion. This only activates if the bash429+ # Hook for the Bash completion. This only activates if the Bash430 # completion is actually enabled, otherwise this is quite a fast431 # noop.432 _bashcomplete(self, prog_name, complete_var)433 233 unmodified lines667 cmd_name = make_str(ctx.args[0])668 cmd = self.get_command(ctx, cmd_name)669 670 # If we don't find the command we want to show an error message671- # to the user that it was not provided. However there is671+ # to the user that it was not provided. However, there is672 # something else we should do: if the first argument looks like673 # an option we want to kick off parsing again for arguments to674 # resolve things like --help which now should go to the main675 # place.116 unmodified lines792 Some settings are supported by both options and arguments.793 794 .. versionchanged:: 2.0795 Changed signature for parameter callback to also be passed the796- parameter. In click 2.0 the old callback format will still work796+ parameter. In click 2.0, the old callback format will still work,797 but it will raise a warning to give you change to migrate the798 code easier.799 800 :param param_decls: the parameter declarations for this option or801 argument. This is a list of flags or argument802 names.803 :param type: the type that should be used. Either a :class:`ParamType`804- or a python type. The later is converted into the former804+ or a Python type. The later is converted into the former805 automatically if supported.806 :param required: controls if this is optional or not.807- :param default: the default value if omitted. This can also be a callable807+ :param default: the default value if omitted. This can also be a callable,808 in which case it's invoked when the default is needed809 without any arguments.810 :param callback: a callback that should be executed after the parameter811 was matched. This is called as ``fn(ctx, param,812 value)`` and needs to return the value. Before click813- 2.0 the signature was ``(ctx, value)``.813+ 2.0, the signature was ``(ctx, value)``.814 :param nargs: the number of arguments to match. If not ``1`` the return815 value is a tuple instead of single value.816 :param metavar: how the value is represented in the help page.817 :param expose_value: if this is `True` then the value is passed onwards133 unmodified lines951 return []952 953 954 class Option(Parameter):955- """Options are usually optionaly values on the command line and955+ """Options are usually optional values on the command line and956 have some extra features that arguments don't have.957 958 All other parameters are passed onwards to the parameter constructor.959 960 :param show_default: controls if the default value should be shown on the961- help page. Normally defaults are not shown.961+ help page. Normally, defaults are not shown.962 :param prompt: if set to `True` or a non empty string then the user will963 be prompted for input if not set. If set to `True` the964 prompt will be the option name capitalized.965 :param confirmation_prompt: if set then the value will need to be confirmed298 unmodified linesmodified:click/decorators.py+7 added-7 removed
6 unmodified lines7 from .utils import echo8 9 10 def pass_context(f):11- """Marks a callback that it wants to receive the current context11+ """Marks a callback as wanting to receive the current context12 object as first argument.13 """14 f.__click_pass_context__ = True15 return f16 17 18 def pass_obj(f):19- """Similar to :func:`pass_context` but only pass the object on the19+ """Similar to :func:`pass_context`, but only pass the object on the20 context onwards (:attr:`Context.obj`). This is useful if that object21 represents the state of a nested system.22 """23 @pass_context106 unmodified lines130 131 132 def argument(*param_decls, **attrs):133 """Attaches an option to the command. All positional arguments are134- passed as parameter declarations to :class:`Argument`, all keyword134+ passed as parameter declarations to :class:`Argument`; all keyword135 arguments are forwarded unchanged. This is equivalent to creating an136 :class:`Option` instance manually and attaching it to the137 :attr:`Command.params` list.138 """4 unmodified lines143 144 145 def option(*param_decls, **attrs):146 """Attaches an option to the command. All positional arguments are147- passed as parameter declarations to :class:`Option`, all keyword147+ passed as parameter declarations to :class:`Option`; all keyword148 arguments are forwarded unchanged. This is equivalent to creating an149 :class:`Option` instance manually and attaching it to the150 :attr:`Command.params` list.151 """3 unmodified lines155 return decorator156 157 158 def confirmation_option(*param_decls, **attrs):159- """Shortcut for confirmation prompts that can be ignored by bypassed159+ """Shortcut for confirmation prompts that can be ignored by passing160 ``--yes`` as parameter.161 162 This is equivalent to decorating a function with :func:`option` with163 the following parameters::97 unmodified lines261 262 def help_option(*param_decls, **attrs):263 """Adds a ``--help`` option which immediately ends the program264 printing out the help page. This is usually unnecessary to add as265- this is added by default to all commands unless supressed.265+ this is added by default to all commands unless suppressed.266 267- Like :func:`version_option` this is implemented as eager option that267+ Like :func:`version_option`, this is implemented as eager option that268 prints in the callback and exits.269 270 All arguments are forwarded to :func:`option`.271 """16 unmodified linesmodified:click/exceptions.py+5 added-5 removed
2 unmodified lines3 from .utils import echo4 5 6 class ClickException(Exception):7- """An exception that click can handle and show to the user.."""7+ """An exception that click can handle and show to the user."""8 9 #: The exit code for this exception10 exit_code = 111 37 unmodified lines49 50 class BadParameter(UsageError):51 """An exception that formats out a standardized error message for a52 bad parameter. This is useful when thrown from a callback or type as53- click will attach contextual information to it (for instance like54- which parameter it is).53+ click will attach contextual information to it (for instance, which54+ parameter it is).55 56 .. versionadded:: 2.057 58 :param param: the parameter object that caused this error. This can59- be left and click if possible will attach this info60- itself.59+ be left out, and click will attach this info itself60+ if possible.61 :param param_hint: a string that shows up as parameter name. This62 can be used as alternative to `param` in cases63 where custom validation should happen. If it is64 a string it's used as such, if it's a list then38 unmodified linesmodified:click/formatting.py+6 added-6 removed
17 unmodified lines18 19 20 def wrap_text(text, width=78, initial_indent='', subsequent_indent='',21 preserve_paragraphs=False):22- """A helper function that intelligently wraps text. By default it22+ """A helper function that intelligently wraps text. By default, it23 assumes that it operates on a single paragraph of text but if the24 `preserve_paragraphs` parameter is provided it will intelligently25 handle paragraphs (defined by two empty lines).26 27- If paragraphs are handled a paragraph can be prefixed with an empty27+ If paragraphs are handled, a paragraph can be prefixed with an empty28 line containing the ``\\b`` character (``\\x08``) to indicate that29 no rewrapping should happen in that block.30 31 :param text: the text that should be rewrapped.49 unmodified lines81 return '\n\n'.join(rv)82 83 84 class HelpFormatter(object):85- """This class helps with formatting text based help pages. It's86- usually just needed for very special internal cases but it's also85+ """This class helps with formatting text-based help pages. It's86+ usually just needed for very special internal cases, but it's also87 exposed so that developers can write their own fancy outputs.88 89- At present it always writes into memory.89+ At present, it always writes into memory.90 91 :param indent_increment: the additional increment for each level.92 :param width: the width for the text. This defaults to the terminal93 width clamped to a maximum of 78.96 unmodified lines190 self.write('\n')191 192 @contextmanager193 def section(self, name):194- """Helpful context manager that writes a paragraph, a heading194+ """Helpful context manager that writes a paragraph, a heading,195 and the indents.196 197 :param name: the section name that is written as heading.198 """20 unmodified linesmodified:click/parser.py+3 added-4 removed
145 unmodified lines146 147 def add_option(self, opts, dest, action=None, nargs=1, const=None,148 obj=None):149 """Adds a new option named `dest` to the parser. The destination150- is not inferred unlike with optparse and needs to be explicitly150+ is not inferred (unlike with optparse) and needs to be explicitly151 provided. Action can be any of ``store``, ``store_const``,152 ``append``, ``appnd_const`` or ``count``.153 154 The `obj` can be used to identify the option in the order list48 unmodified lines203 def _process_args_for_options(self, state):204 while state.rargs:205 arg = state.rargs.pop(0)206 arglen = len(arg)207- # Double dash es always handled explicitly regardless of what207+ # Double dashes always handled explicitly regardless of what208 # prefixes are valid.209 if arg == '--':210 return211 elif arg[:1] in self._opt_prefixes and arglen > 1:46 unmodified lines258 self._error('no such option: %s. (Possible options: %s)'259 % (opt, ', '.join(possibilities)))260 261 def _process_long_opt(self, arg, state):262- # Value explicitly attached to arg? Pretend it's the next263- # argument.262+ # Value explicitly attached to arg? Pretend it's the next argument.263 if '=' in arg:264 opt, next_arg = arg.split('=', 1)265 state.rargs.insert(0, next_arg)266 had_explicit_value = True71 unmodified linesmodified:click/termui.py+18 added-18 removed
34 unmodified lines35 value_proc=None, prompt_suffix=': ', show_default=True):36 """Prompts a user for input. This is a convenience function that can37 be used to prompt a user for input later.38 39- If the user aborts the input by sending a interrupt signal this39+ If the user aborts the input by sending a interrupt signal, this40 function will catch it and raise a :exc:`Abort` exception.41 42 :param text: the text to show for the prompt.43 :param default: the default value to use if no input happens. If this147 unmodified lines191 info_sep=' ', width=36, file=None):192 """This function creates an iterable context manager that can be used193 to iterate over something while showing a progress bar. It will194 either iterate over the `iterable` or `length` items (that are counted195- up). While iteration happens this function will print a rendered195+ up). While iteration happens, this function will print a rendered196 progress bar to the given `file` (defaults to stdout) and will attempt197- to calculate remaining time and more. By default this progress bar197+ to calculate remaining time and more. By default, this progress bar198 will not be rendered if the file is not a terminal.199 200 The context manager creates the progress bar. When the context201 manager is entered the progress bar is already displayed. With every202- iteration over the progress bar the iterable passed to the bar is203- advanced and the bar is updated. When the context manager exits202+ iteration over the progress bar, the iterable passed to the bar is203+ advanced and the bar is updated. When the context manager exits,204 a newline is printed and the progress bar is finalized on screen.205 206 No printing must happen or the progress bar will be unintentionally207 destroyed.169 unmodified lines377 extension='.txt', filename=None):378 r"""Edits the given text in the defined editor. If an editor is given379 (should be the full path to the executable but the regular operating380 system search path is used for finding the executable) it overrides381- the detected editor. Optionally some environment variables can be382- used. If the editor is closed without changes `None` is returned. In381+ the detected editor. Optionally, some environment variables can be382+ used. If the editor is closed without changes, `None` is returned. In383 case a file is edited directly the return value is always `None` and384 `require_save` and `extension` are ignored.385 386 If the editor cannot be opened a :exc:`UsageError` is raised.387 388- Note for Windows: to simplify cross platform usage the newlines are389- automatically converted from POSIX to Windows and reverse. As such the390- message here will have ``\n`` as newline markers.388+ Note for Windows: to simplify cross-platform usage, the newlines are389+ automatically converted from POSIX to Windows and vice versa. As such,390+ the message here will have ``\n`` as newline markers.391 392 :param text: the text to edit.393 :param editor: optionally the editor to use. Defaults to automatic394 detection.16 unmodified lines411 412 413 def launch(url, wait=False, locate=False):414 """This function launches the given URL (or filename) in the default415- viewer application for this file type. If this is an executable it415+ viewer application for this file type. If this is an executable, it416 might launch the executable in a new session. The return value is417- the exit code of the launched application. Usually ``0`` indicates417+ the exit code of the launched application. Usually, ``0`` indicates418 success.419 420 Examples::421 1 unmodified line423 click.launch('/my/downloaded/file', locate=True)424 425 .. versionadded:: 2.0426 427- :param url: url or filename of the thing to launch.427+ :param url: URL or filename of the thing to launch.428 :param wait: waits for the program to stop.429 :param locate: if this is set to `True` then instead of launching the430 application associated with the URL it will attempt to431 launch a file manager with the file located. This432- might have weird effects if the url does not point to432+ might have weird effects if the URL does not point to433 the filesystem.434 """435 from ._termui_impl import open_url436 return open_url(url, wait=wait, locate=locate)16 unmodified lines453 is piped into the standard input.454 455 .. versionadded:: 2.0456 457- :param echo: if set to `True` the character read will also show up on458- the terminal. The default is not not show it.457+ :param echo: if set to `True`, the character read will also show up on458+ the terminal. The default is to not show it.459 """460 f = _getchar461 if f is None:462 from ._termui_impl import getchar as f2 unmodified lines465 466 def pause(info='Press any key to continue ...'):467 """This command stops execution and waits for the user to press any468 key to continue. This is similar to the Windows batch "pause"469- command. If the program is not run through a terminal this command470- will do nothing instead.469+ command. If the program is not run through a terminal, this command470+ will instead do nothing.471 472 .. versionadded:: 2.0473 474 :param info: the info string to print before pausing.13 unmodified linesmodified:click/testing.py+6 added-6 removed
87 unmodified lines88 )89 90 91 class CliRunner(object):92- """The CLI runner provides functionality to invoke a Click command line92+ """The CLI runner provides functionality to invoke a click command line93 script for unittesting purposes in a isolated environment. This only94- works in single-threaded systems without any concurrency as it changes94+ works in single-threaded systems without any concurrency as it changes the95 global interpreter state.96 97 :param charset: the character set for the input and output data. This is98- utf-8 by default and should not be changed currently as98+ UTF-8 by default and should not be changed currently as99 the reporting to click only works in Python 2 properly.100 :param env: a dictionary with environment variables for overriding.101 :param echo_stdin: if this is set to `True`, then reading from stdin writes102 to stdout. This is useful for showing examples in23 unmodified lines126 return rv127 128 @contextlib.contextmanager129 def isolation(self, input=None, env=None):130- """A context manager that set up the isolation for invoking of a131- command line tool. This sets up stdin with the given input data,130+ """A context manager that sets up the isolation for invoking of a131+ command line tool. This sets up stdin with the given input data132 and `os.environ` with the overrides from the given dictionary.133- This also rebinds some internals in Click to be mocked (like the133+ This also rebinds some internals in click to be mocked (like the134 prompt functionality).135 136 This is automatically done in the :meth:`invoke` method.137 131 unmodified linesmodified:click/types.py+8 added-8 removed
14 unmodified lines15 * it needs to pass through None unchanged16 * it needs to convert from a string17 * it needs to convert its result type through unchanged18 (eg: needs to be idempotent)19- * it needs to be able to deal with param and context being none.19+ * it needs to be able to deal with param and context being `None`.20 This can be the case when the object is used with prompt21 inputs.22 """23 24 unmodified lines48 def split_envvar_value(self, rv):49 """Given a value from an environment variable this splits it up50 into small chunks depending on the defined envvar list splitter.51 52- If the splitter is set to `None` which means that whitespace splits,53- then leading and trailing whitespace is ignored. Otherwise leading52+ If the splitter is set to `None`, which means that whitespace splits,53+ then leading and trailing whitespace is ignored. Otherwise, leading54 and trailing splitters usually lead to empty items being included.55 """56 return (rv or '').split(self.envvar_list_splitter)57 168 unmodified lines226 227 Files can be opened for reading or writing. The special value ``-``228 indicates stdin or stdout depending on the mode.229 230- By default the file is opened for reading text data but it can also be230+ By default, the file is opened for reading text data, but it can also be231 opened in binary mode or for writing. The encoding parameter can be used232 to force a specific encoding.233 234 The `lazy` flag controls if the file should be opened immediately or235 upon first IO. The default is to be non lazy for standard input and236 output streams as well as files opened for reading, lazy otherwise.237 238- Starting with click 2.0 files can also be opened atomically in which238+ Starting with click 2.0, files can also be opened atomically in which239 case all writes go into a separate file in the same folder and upon240 completion the file will be moved over to the original location. This241 is useful if a file regularly read by other users is modified.242 35 unmodified lines278 279 f, should_close = open_stream(value, self.mode,280 self.encoding, self.errors,281 atomic=self.atomic)282- # If a context is provided we automatically close the file282+ # If a context is provided, we automatically close the file283 # at the end of the context execution (or flush out). If a284- # context does not exist it's the caller's responsibility to284+ # context does not exist, it's the caller's responsibility to285 # properly close the file. This for instance happens when the286 # type is used with prompts.287 if ctx is not None:288 if should_close:10 unmodified lines299 300 class Path(ParamType):301 """The path type is similar to the :class:`File` type but it performs302 different checks. First of all, instead of returning a open file303- handle it returns just the filename. Secondly it can perform various303+ handle it returns just the filename. Secondly, it can perform various304 basic checks about what the file or directory should be.305 306 :param exists: if set to true, the file or directory needs to exist for307 this value to be valid. If this is not required and a124 unmodified linesmodified:click/utils.py+12 added-12 removed
17 unmodified lines18 return '-'.join(name.split()).lower()19 20 21 def unpack_args(args, nargs_spec):22- """Given an iterable of arguments and an iterable of nargs specifications22+ """Given an iterable of arguments and an iterable of nargs specifications,23 it returns a tuple with all the unpacked arguments at the first index24 and all remaining arguments as the second.25 26 The nargs specification is the number of arguments that should be consumed28 unmodified lines55 if nargs == 1:56 rv.append(_fetch(args))57 elif nargs > 1:58 x = [_fetch(args) for _ in range(nargs)]59- # If we're reversed we're pulling in the arguments in reverse59+ # If we're reversed, we're pulling in the arguments in reverse,60 # so we need to turn them around.61 if spos is not None:62 x.reverse()63 rv.append(tuple(x))2 unmodified lines66 raise TypeError('Cannot have two nargs < 0')67 spos = len(rv)68 rv.append(None)69 70- # spos is the position of the wildcard (star). If it's not None70+ # spos is the position of the wildcard (star). If it's not `None`,71 # we fill it with the remainder.72 if spos is not None:73 rv[spos] = tuple(args)74 args = []119 unmodified lines194 195 196 def echo(message=None, file=None, nl=True):197 """Prints a message plus a newline to the given file or stdout. On198- first sight this looks like the print function but it has improved199- support for handling unicode and binary data that does not fail no198+ first sight, this looks like the print function, but it has improved199+ support for handling Unicode and binary data that does not fail no200 matter how badly configured the system is.201 202- Primarily it means that you can print binary data as well as unicode202+ Primarily it means that you can print binary data as well as Unicode203 data on both 2.x and 3.x to the given file in the most appropriate way204 possible. This is a very carefree function as in that it will try its205 best to not fail.206 207- In addition to that if `colorama`_ is installed the echo function will207+ In addition to that, if `colorama`_ is installed, the echo function will208 also support clever handling of ANSI codes. Essentially it will then209 do the following:210 211 - add transparent handling of ANSI color codes on Windows.31 unmodified lines243 binary_file.write(b'\n')244 binary_file.flush()245 return246 247- # ANSI style support. If there is no message or we are dealing with247+ # ANSI-style support. If there is no message or we are dealing with248 # bytes nothing is happening. If we are connected to a file we want249 # to strip colors. If we have support for wrapping streams (windows250 # through colorama) we want to do that.251 if message and not is_bytes(message):45 unmodified lines297 def format_filename(filename, shorten=False):298 """Formats a filename for user display. The main purpose of this299 function is to ensure that the filename can be displayed at all. This300 will decode the filename to unicode if necessary in a way that it will301- not fail. Optionally it can shorten the filename to not include the301+ not fail. Optionally, it can shorten the filename to not include the302 full path to the filename.303 304 :param filename: formats a filename for UI display. This will also convert305 the filename into unicode without failing.8 unmodified lines314 def get_app_dir(app_name, roaming=True, force_posix=False):315 r"""Returns the config folder for the application. The default behavior316 is to return whatever is most appropriate for the operating system.317 318- To give you an idea, for an app called ``"Foo Bar"`` something like318+ To give you an idea, for an app called ``"Foo Bar"``, something like319 the following folders could be returned:320 321 Mac OS X:322 ``~/Library/Application Support/Foo Bar``15 unmodified lines338 .. versionadded:: 2.0339 340 :param app_name: the application name. This should be properly capitalized341 and can contain whitespace.342- :param roaming: controls if the folder should be roaming or not on windows.342+ :param roaming: controls if the folder should be roaming or not on Windows.343 Has no affect otherwise.344- :param force_posix: if this is set to `True` then on any posix system the344+ :param force_posix: if this is set to `True` then on any POSIX system the345 folder will be stored in the home folder with a leading346 dot instead of the XDG config home or darwin's347 application support folder.348 """14 unmodified linesmodified:docs/api.rst+1 added-1 removed
1 unmodified line2 ===3 4 .. module:: click5 6-This part of the documentation shows the full API reference of all public6+This part of the documentation lists the full API reference of all public7 classes and functions.8 9 Decorators10 ----------157 unmodified linesmodified:docs/complex.rst+1 added-1 removed
93 unmodified lines94 def cli(ctx, repo_home, debug):95 ctx.obj = Repo(repo_home, debug)96 97 98-So let's understand what this does. We create a group command which can98+Let's understand what this does. We create a group command which can99 have subcommands. When it is invoked, it will create an instance of a100 ``Repo`` class. This holds the state for our command line tool. In this101 case, it just remembers some parameters, but at this point it could also102 start loading configuration files and so on.117 unmodified lines