click-compose 2025.10.27__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,82 @@
1
+ """
2
+ Composable Click callback utilities for building flexible CLI applications.
3
+ """
4
+
5
+ from collections.abc import Callable, Sequence
6
+ from typing import TypeVar
7
+
8
+ import click
9
+
10
+ T = TypeVar("T")
11
+ U = TypeVar("U")
12
+
13
+
14
+ def sequence_validator(
15
+ *,
16
+ validator: Callable[[click.Context | None, click.Parameter | None, T], U],
17
+ ) -> Callable[
18
+ [click.Context | None, click.Parameter | None, Sequence[T]], Sequence[U]
19
+ ]:
20
+ """Wrap a single-value validator to apply it to a sequence of values.
21
+
22
+ This function takes a Click callback that validates a single value and
23
+ returns a new callback that applies the same validation to each element
24
+ in a sequence. The validator can transform the type of each element.
25
+
26
+ Args:
27
+ validator: A Click callback that validates a single value.
28
+
29
+ Returns:
30
+ A Click callback that validates a sequence of values.
31
+ """
32
+
33
+ def callback(
34
+ ctx: click.Context | None,
35
+ param: click.Parameter | None,
36
+ value: Sequence[T],
37
+ ) -> Sequence[U]:
38
+ """
39
+ Apply the validator to each element in the sequence.
40
+ """
41
+ return_values: tuple[U, ...] = ()
42
+ for item in value:
43
+ returned_value = validator(ctx, param, item)
44
+ return_values = (*return_values, returned_value)
45
+ return return_values
46
+
47
+ return callback
48
+
49
+
50
+ def multi_callback(
51
+ *,
52
+ callbacks: Sequence[Callable[..., T]],
53
+ ) -> Callable[[click.Context | None, click.Parameter | None, T], T]:
54
+ """Create a Click-compatible callback that applies multiple callbacks in
55
+ sequence.
56
+
57
+ This function takes a sequence of Click callbacks and returns a new
58
+ callback that applies each callback in order, threading the value through
59
+ each one. Each callback can transform the type, allowing for flexible
60
+ pipelines of transformations and validations.
61
+
62
+ Args:
63
+ callbacks: A sequence of Click callbacks to apply in order.
64
+
65
+ Returns:
66
+ A Click callback that applies all the given callbacks in sequence.
67
+ """
68
+
69
+ def callback(
70
+ ctx: click.Context | None,
71
+ param: click.Parameter | None,
72
+ value: T,
73
+ ) -> T:
74
+ """
75
+ Apply each callback in sequence to the value.
76
+ """
77
+ result = value
78
+ for cb in callbacks:
79
+ result = cb(ctx, param, result)
80
+ return result
81
+
82
+ return callback
click_compose/py.typed ADDED
File without changes
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.4
2
+ Name: click-compose
3
+ Version: 2025.10.27
4
+ Summary: Composable Click callback utilities for building flexible CLI applications.
5
+ Author-email: Adam Dangoor <adamdangoor@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Source, https://github.com/adamtheturtle/click-compose
8
+ Keywords: callbacks,cli,click,validation
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Python: >=3.11
18
+ Description-Content-Type: text/x-rst
19
+ License-File: LICENSE
20
+ Requires-Dist: click>=8.0.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: actionlint-py==1.7.8.24; extra == "dev"
23
+ Requires-Dist: check-manifest==0.51; extra == "dev"
24
+ Requires-Dist: deptry==0.23.1; extra == "dev"
25
+ Requires-Dist: doc8==2.0.0; extra == "dev"
26
+ Requires-Dist: docformatter==1.7.7; extra == "dev"
27
+ Requires-Dist: furo==2025.9.25; extra == "dev"
28
+ Requires-Dist: interrogate==1.7.0; extra == "dev"
29
+ Requires-Dist: mypy[faster-cache]==1.18.2; extra == "dev"
30
+ Requires-Dist: mypy-strict-kwargs==2025.4.3; extra == "dev"
31
+ Requires-Dist: packaging>=24.0; extra == "dev"
32
+ Requires-Dist: pre-commit==4.3.0; extra == "dev"
33
+ Requires-Dist: pydocstyle==6.3; extra == "dev"
34
+ Requires-Dist: pygments==2.19.2; extra == "dev"
35
+ Requires-Dist: pylint[spelling]==4.0.2; extra == "dev"
36
+ Requires-Dist: pylint-per-file-ignores==3.1.0; extra == "dev"
37
+ Requires-Dist: pyproject-fmt==2.11.0; extra == "dev"
38
+ Requires-Dist: pyright==1.1.407; extra == "dev"
39
+ Requires-Dist: pyroma==5.0; extra == "dev"
40
+ Requires-Dist: pytest==8.4.2; extra == "dev"
41
+ Requires-Dist: pytest-cov==7.0.0; extra == "dev"
42
+ Requires-Dist: pytest-regressions==2.8.3; extra == "dev"
43
+ Requires-Dist: pyyaml==6.0.3; extra == "dev"
44
+ Requires-Dist: ruff==0.14.2; extra == "dev"
45
+ Requires-Dist: shellcheck-py==0.11.0.1; extra == "dev"
46
+ Requires-Dist: shfmt-py==3.12.0.2; extra == "dev"
47
+ Requires-Dist: sphinx==8.2.3; extra == "dev"
48
+ Requires-Dist: sphinx-copybutton==0.5.2; extra == "dev"
49
+ Requires-Dist: sphinx-lint==1.0.0; extra == "dev"
50
+ Requires-Dist: sphinx-pyproject==0.3.0; extra == "dev"
51
+ Requires-Dist: sphinx-substitution-extensions==2025.10.24; extra == "dev"
52
+ Requires-Dist: sphinxcontrib-spelling==8.0.1; extra == "dev"
53
+ Requires-Dist: vulture==2.14; extra == "dev"
54
+ Requires-Dist: yamlfix==1.19.0; extra == "dev"
55
+ Provides-Extra: release
56
+ Requires-Dist: check-wheel-contents==0.6.3; extra == "release"
57
+ Dynamic: license-file
58
+
59
+ click-compose
60
+ =============
61
+
62
+ Composable Click callback utilities for building flexible CLI applications.
63
+
64
+ .. contents::
65
+ :local:
66
+
67
+ Installation
68
+ ------------
69
+
70
+ .. code-block:: shell
71
+
72
+ $ pip install click-compose
73
+
74
+ Or with ``uv``:
75
+
76
+ .. code-block:: shell
77
+
78
+ $ uv add click-compose
79
+
80
+ Quick Start
81
+ -----------
82
+
83
+ ``click-compose`` provides two main utilities for composing Click callbacks:
84
+
85
+ multi_callback
86
+ ~~~~~~~~~~~~~~
87
+
88
+ Combine multiple callbacks into a single callback that applies them in sequence:
89
+
90
+ .. code-block:: python
91
+
92
+ import click
93
+ from click_compose import multi_callback
94
+
95
+ def validate_positive(ctx, param, value):
96
+ if value <= 0:
97
+ raise click.BadParameter("Must be positive")
98
+ return value
99
+
100
+ def validate_max_100(ctx, param, value):
101
+ if value > 100:
102
+ raise click.BadParameter("Must be <= 100")
103
+ return value
104
+
105
+ @click.command()
106
+ @click.option(
107
+ "--count",
108
+ type=int,
109
+ callback=multi_callback([validate_positive, validate_max_100]),
110
+ )
111
+ def cmd(count):
112
+ click.echo(f"Count: {count}")
113
+
114
+ sequence_validator
115
+ ~~~~~~~~~~~~~~~~~~
116
+
117
+ Apply a validator to each element in a sequence (useful with ``multiple=True``):
118
+
119
+ .. code-block:: python
120
+
121
+ import click
122
+ from click_compose import sequence_validator
123
+
124
+ def validate_positive(ctx, param, value):
125
+ if value <= 0:
126
+ raise click.BadParameter("Must be positive")
127
+ return value
128
+
129
+ @click.command()
130
+ @click.option(
131
+ "--numbers",
132
+ multiple=True,
133
+ type=int,
134
+ callback=sequence_validator(validate_positive),
135
+ )
136
+ def cmd(numbers):
137
+ click.echo(f"Sum: {sum(numbers)}")
138
+
139
+ Documentation
140
+ -------------
141
+
142
+ See the `full documentation <https://adamtheturtle.github.io/click-compose/>`__.
@@ -0,0 +1,7 @@
1
+ click_compose/__init__.py,sha256=KBb4qVJmPIhgmvMDynZIBZVwKmf6DxmvpKM6-qHvzTA,2364
2
+ click_compose/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ click_compose-2025.10.27.dist-info/licenses/LICENSE,sha256=N3qm7laipxyuXkWpYllj89AObvPbtWgoABmaKfhQYL4,1069
4
+ click_compose-2025.10.27.dist-info/METADATA,sha256=rYhy-_Qwt7W73276A9O_y5I5HntUJxDcAEnhmHCqGwo,4439
5
+ click_compose-2025.10.27.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
6
+ click_compose-2025.10.27.dist-info/top_level.txt,sha256=D6w2GKY-8Qwmbiv3G8DyrtwEjiu-yd7I6n6IpPIUauU,14
7
+ click_compose-2025.10.27.dist-info/RECORD,,
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any
6
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Adam Dangoor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ click_compose