Skip to content

Commit c07bb93

Browse files
authored
Merge branch 'stable' into unset-in-default-map
2 parents 6de2121 + c7e1ba8 commit c07bb93

23 files changed

Lines changed: 1242 additions & 371 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ repos:
1313
hooks:
1414
- id: check-merge-conflict
1515
- id: debug-statements
16+
exclude: ^(src/click/testing\.py|tests/test_testing\.py)$
1617
- id: fix-byte-order-marker
1718
- id: trailing-whitespace
1819
- id: end-of-file-fixer

CHANGES.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@ Unreleased
1616
- Treat ``Sentinel.UNSET`` values in a ``default_map`` as absent, so they fall
1717
through to the next default source instead of being used as the value.
1818
:issue:`3224` :pr:`3240`
19+
- Patch ``pdb.Pdb`` in ``CliRunner`` isolation so ``pdb.set_trace()``,
20+
``breakpoint()``, and debuggers subclassing ``pdb.Pdb`` (ipdb, pdbpp) can
21+
interact with the real terminal instead of the captured I/O streams.
22+
:issue:`654` :issue:`824` :issue:`843` :pr:`951` :pr:`3235`
23+
- Add optional randomized parallel test execution using ``pytest-randomly`` and
24+
``pytest-xdist`` to detect test pollution and race conditions. :pr:`3151`
25+
- Add contributor documentation for running stress tests, randomized
26+
parallel tests, and Flask smoke tests. :pr:`3151` :pr:`3177`
27+
- Show custom ``show_default`` string in prompts, matching the existing
28+
help text behavior. :issue:`2836` :pr:`2837` :pr:`3165` :pr:`3262` :pr:`3280`
29+
:pr:`3328``
30+
- Fix ``default=True`` with boolean ``flag_value`` always returning the
31+
``flag_value`` instead of ``True``. The ``default=True`` to ``flag_value``
32+
substitution now only applies to non-boolean flags, where ``True`` acts as a
33+
sentinel meaning "activate this flag by default". For boolean flags,
34+
``default=True`` is returned as a literal value. :issue:`3111` :pr:`3239`
35+
- Mark ``make_default_short_help`` as private API. :issue:`3189` :pr:`3250`
36+
- ``CliRunner``'s redirected streams now expose the original file descriptor
37+
via ``fileno()``, so that ``faulthandler``, ``subprocess``, and other
38+
C-level consumers no longer crash with ``io.UnsupportedOperation``.
39+
:issue:`2865`
40+
- Change :class:`ParameterSource` to an :class:`~enum.IntEnum` and reorder
41+
its members from most to least explicit, so values can be compared to
42+
check whether a parameter was explicitly provided. :issue:`2879` :pr:`3248`
1943

2044
Version 8.3.2
2145
-------------
Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
.. _arguments:
1+
(arguments)=
22

3-
Arguments
4-
=========
3+
# Arguments
54

6-
.. currentmodule:: click
5+
```{currentmodule} click
6+
```
77

88
Arguments are:
99

10-
* Are positional in nature.
11-
* Similar to a limited version of :ref:`options <options>` that can take an arbitrary number of inputs
12-
* :ref:`Documented manually <documenting-arguments>`.
10+
* Are positional in nature.
11+
* Similar to a limited version of {ref}`options <options>` that can take an arbitrary number of inputs
12+
* {ref}`Documented manually <documenting-arguments>`.
1313

1414
Useful and often used kwargs are:
1515

16-
* ``default``: Passes a default.
17-
* ``nargs``: Sets the number of arguments. Set to -1 to take an arbitrary number.
16+
* `default`: Passes a default.
17+
* `nargs`: Sets the number of arguments. Set to -1 to take an arbitrary number.
1818

19-
Basic Arguments
20-
---------------
19+
## Basic Arguments
2120

22-
A minimal :class:`click.Argument` solely takes one string argument: the name of the argument. This will assume the argument is required, has no default, and is of the type ``str``.
21+
A minimal {class}`click.Argument` solely takes one string argument: the name of the argument. This will assume the argument is required, has no default, and is of the type `str`.
2322

2423
Example:
2524

25+
```{eval-rst}
2626
.. click:example::
2727
2828
@click.command()
@@ -36,19 +36,21 @@ And from the command line:
3636
.. click:run::
3737
3838
invoke(touch, args=['foo.txt'])
39+
```
3940

41+
An argument may be assigned a {ref}`parameter type <parameter-types>`. If no type is provided, the type of the default value is used. If no default value is provided, the type is assumed to be {data}`STRING`.
4042

41-
An argument may be assigned a :ref:`parameter type <parameter-types>`. If no type is provided, the type of the default value is used. If no default value is provided, the type is assumed to be :data:`STRING`.
43+
```{admonition} Note on Required Arguments
44+
:class: note
4245
43-
.. admonition:: Note on Required Arguments
46+
It is possible to make an argument required by setting `required=True`. It is not recommended since we think command line tools should gracefully degrade into becoming no ops. We think this because command line tools are often invoked with wildcard inputs and they should not error out if the wildcard is empty.
47+
```
4448

45-
It is possible to make an argument required by setting ``required=True``. It is not recommended since we think command line tools should gracefully degrade into becoming no ops. We think this because command line tools are often invoked with wildcard inputs and they should not error out if the wildcard is empty.
49+
## Multiple Arguments
4650

47-
Multiple Arguments
48-
-----------------------------------
49-
50-
To set the number of argument use the ``nargs`` kwarg. It can be set to any positive integer and -1. Setting it to -1, makes the number of arguments arbitrary (which is called variadic) and can only be used once. The arguments are then packed as a tuple and passed to the function.
51+
To set the number of argument use the `nargs` kwarg. It can be set to any positive integer and -1. Setting it to -1, makes the number of arguments arbitrary (which is called variadic) and can only be used once. The arguments are then packed as a tuple and passed to the function.
5152

53+
```{eval-rst}
5254
.. click:example::
5355
5456
@click.command()
@@ -64,18 +66,21 @@ And from the command line:
6466
.. click:run::
6567
6668
invoke(copy, args=['foo.txt', 'usr/david/foo.txt', 'usr/mitsuko/foo.txt'])
69+
```
6770

68-
.. admonition:: Note on Handling Files
71+
```{admonition} Note on Handling Files
72+
:class: note
6973
70-
This is not how you should handle files and files paths. This merely used as a simple example. See :ref:`handling-files` to learn more about how to handle files in parameters.
74+
This is not how you should handle files and files paths. This merely used as a simple example. See {ref}`handling-files` to learn more about how to handle files in parameters.
75+
```
7176

72-
Argument Escape Sequences
73-
---------------------------
77+
## Argument Escape Sequences
7478

75-
If you want to process arguments that look like options, like a file named ``-foo.txt`` or ``--foo.txt`` , you must pass the ``--`` separator first. After you pass the ``--``, you may only pass arguments. This is a common feature for POSIX command line tools.
79+
If you want to process arguments that look like options, like a file named `-foo.txt` or `--foo.txt` , you must pass the `--` separator first. After you pass the `--`, you may only pass arguments. This is a common feature for POSIX command line tools.
7680

7781
Example usage:
7882

83+
```{eval-rst}
7984
.. click:example::
8085
8186
@click.command()
@@ -90,9 +95,11 @@ And from the command line:
9095
.. click:run::
9196
9297
invoke(touch, ['--', '-foo.txt', 'bar.txt'])
98+
```
9399

94-
If you don't like the ``--`` marker, you can set ignore_unknown_options to True to avoid checking unknown options:
100+
If you don't like the `--` marker, you can set ignore_unknown_options to True to avoid checking unknown options:
95101

102+
```{eval-rst}
96103
.. click:example::
97104
98105
@click.command(context_settings={"ignore_unknown_options": True})
@@ -107,17 +114,17 @@ And from the command line:
107114
.. click:run::
108115
109116
invoke(touch, ['-foo.txt', 'bar.txt'])
117+
```
110118

119+
(environment-variables)=
111120

112-
.. _environment-variables:
113-
114-
Environment Variables
115-
---------------------
121+
## Environment Variables
116122

117-
Arguments can use environment variables. To do so, pass the name(s) of the environment variable(s) via `envvar` in ``click.argument``.
123+
Arguments can use environment variables. To do so, pass the name(s) of the environment variable(s) via `envvar` in `click.argument`.
118124

119125
Checking one environment variable:
120126

127+
```{eval-rst}
121128
.. click:example::
122129
123130
@click.command()
@@ -156,3 +163,4 @@ And from the command line:
156163
with open('hello.txt', 'w') as f:
157164
f.write('Hello World from second variable!')
158165
invoke(echo, env={'SRC_2': 'hello.txt'})
166+
```

docs/click-concepts.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Click Concepts
2+
3+
This section covers concepts about Click's design.
4+
5+
```{contents}
6+
---
7+
depth: 1
8+
local: true
9+
---
10+
```
11+
12+
(callback-evaluation-order)=
13+
14+
## Callback Evaluation Order
15+
16+
Click works a bit differently than some other command line parsers in that
17+
it attempts to reconcile the order of arguments as defined by the
18+
programmer with the order of arguments as defined by the user before
19+
invoking any callbacks.
20+
21+
This is an important concept to understand when porting complex
22+
patterns to Click from optparse or other systems. A parameter
23+
callback invocation in optparse happens as part of the parsing step,
24+
whereas a callback invocation in Click happens after the parsing.
25+
26+
The main difference is that in optparse, callbacks are invoked with the raw
27+
value as it happens, whereas a callback in Click is invoked after the
28+
value has been fully converted.
29+
30+
Generally, the order of invocation is driven by the order in which the user
31+
provides the arguments to the script; if there is an option called `--foo`
32+
and an option called `--bar` and the user calls it as `--bar --foo`, then
33+
the callback for `bar` will fire before the one for `foo`.
34+
35+
There are three exceptions to this rule which are important to know:
36+
37+
Eagerness:
38+
> An option can be set to be "eager". All eager parameters are
39+
> evaluated before all non-eager parameters, but again in the order as
40+
> they were provided on the command line by the user.
41+
42+
> This is important for parameters that execute and exit like `--help`
43+
> and `--version`. Both are eager parameters, but whatever parameter
44+
> comes first on the command line will win and exit the program.
45+
46+
Repeated parameters:
47+
> If an option or argument is split up on the command line into multiple
48+
> places because it is repeated -- for instance, `--exclude foo --include
49+
> baz --exclude bar` -- the callback will fire based on the position of
50+
> the first option. In this case, the callback will fire for
51+
> `exclude` and it will be passed both options (`foo` and
52+
> `bar`), then the callback for `include` will fire with `baz`
53+
> only.
54+
55+
> Note that even if a parameter does not allow multiple versions, Click
56+
> will still accept the position of the first, but it will ignore every
57+
> value except the last. The reason for this is to allow composability
58+
> through shell aliases that set defaults.
59+
60+
Missing parameters:
61+
> If a parameter is not defined on the command line, the callback will
62+
> still fire. This is different from how it works in optparse where
63+
> undefined values do not fire the callback. Missing parameters fire
64+
> their callbacks at the very end which makes it possible for them to
65+
> default to values from a parameter that came before.
66+
67+
Most of the time you do not need to be concerned about any of this,
68+
but it is important to know how it works for some advanced cases.

docs/click-concepts.rst

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)