-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path__init__.py
More file actions
457 lines (441 loc) · 11 KB
/
Copy path__init__.py
File metadata and controls
457 lines (441 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# Copyright Kevin Deldycke <kevin@deldycke.com> and contributors.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""Expose package-wide elements."""
from __future__ import annotations
from typing import TYPE_CHECKING
# Mypy override: the ``from click import *`` / ``from cloup import *`` star imports
# below make mypy resolve these re-implemented names to the click or cloup base class,
# which hides click-extra's own attributes. Declaring the correct types here first,
# before the star imports, makes mypy treat the later bindings as no-redefs and keeps
# click-extra's subclasses canonical for consumers of this package.
if TYPE_CHECKING:
from .commands import Command, Group
from .context import Context, pass_context
from .highlight import HelpFormatter
from .parameters import Argument, Option
from .styling import Style
from .theme import HelpTheme
# Import all click's module-level content to allow for drop-in replacement.
# XXX Star import is really badly supported by mypy for now and leads to lots of
# "Module 'XXX' has no attribute 'YYY'". See: https://github.com/python/mypy/issues/4930
# The ignore mirrors the cloup star import below: the names pre-declared in the
# TYPE_CHECKING block above are re-implemented by click-extra, so click's originals
# arrive here as incompatible redefinitions.
from click import * # type: ignore[assignment]
from click._utils import UNSET
from click.core import ParameterSource
# NoSuchCommand (PR pallets/click#3228) and get_pager_file (PR pallets/click#1572)
# are Click 8.4.0 additions, absent on the Click 8.3.x releases click-extra still
# supports. Import them only when present so click-extra mirrors Click's own public
# surface; the matching __all__ entries are trimmed below when they are missing.
try:
from click import NoSuchCommand, get_pager_file
_HAS_CLICK_8_4_EXPORTS = True
except ImportError: # Click < 8.4.0.
_HAS_CLICK_8_4_EXPORTS = False
# Overrides click helpers with cloup's.
from cloup import * # type: ignore[no-redef, assignment]
# XXX Import types first to avoid circular imports. The True condition is a hack to
# prevent ruff from re-ordering imports.
if True:
from .types import ChoiceSource, EnumChoice, MultiChoice
# Override cloup.Style with our own version. The override must happen after
# ``from cloup import *`` (which would otherwise re-shadow our subclass) and
# before any module that does ``from . import Style`` is loaded (parameters,
# version, testing all do).
from . import styling as _styling_module
Style = _styling_module.Style # type: ignore[misc]
del _styling_module
# Imported for its registration side effect: defining the module registers the
# ``carapace`` shell completion class (see click_extra.carapace.CarapaceComplete),
# so dynamic Carapace completion resolves in any CLI that imports click_extra.
from . import (
carapace as carapace,
context,
)
from .accessibility import AccessibleOption, clear, echo_via_pager
from .color import (
ColorOption,
NoColorOption,
)
from .commands import (
Command,
Group,
HelpCommand,
LazyGroup,
)
from .config import (
CONFIG_PATH_METADATA_KEY,
DEFAULT_SUBCOMMANDS_KEY,
EXTENSION_METADATA_KEY,
NO_CONFIG,
NORMALIZE_KEYS_METADATA_KEY,
PREPEND_SUBCOMMANDS_KEY,
VCS,
ConfigFormat,
ConfigOption,
ConfigValidator,
DumpConfigOption,
NoConfigOption,
ValidateConfigOption,
ValidationError,
ValidationReport,
flatten_config_keys,
format_from_path,
get_tool_config,
make_schema_callable,
normalize_config_keys,
parse_content,
read_file,
run_config_validation,
serialize_content,
)
from .context import Context, pass_context
from .decorators import ( # type: ignore[no-redef]
accessible_option,
argument,
color_option,
columns_option,
command,
config_option,
dump_config_option,
group,
help_option,
jobs_option,
lazy_group,
man_option,
no_color_option,
no_config_option,
option,
quiet_option,
show_params_option,
sort_by_option,
table_format_option,
telemetry_option,
theme_option,
timer_option,
validate_config_option,
verbose_option,
verbosity_option,
version_option,
zero_exit_option,
)
from .execution import (
CPU_COUNT,
DEFAULT_JOBS,
JobsOption,
TimerOption,
ZeroExitOption,
run_jobs,
)
from .highlight import (
HelpFormatter,
HelpKeywords,
)
from .logging import (
Formatter,
LogLevel,
QuietOption,
StreamHandler,
VerboseOption,
VerbosityOption,
basicConfig,
new_logger,
)
from .man_page import (
ManOption,
ManPage,
render_manpage,
render_manpages,
write_manpages,
)
from .parameters import (
Argument,
ExtraOption,
Option,
ParamStructure,
ShowParamsOption,
format_param_row,
get_param_spec,
last_param,
require_sibling_param,
search_params,
)
from .spinner import ( # type: ignore[no-redef]
SPINNERS,
ProgressOption,
Spinner,
SpinnerPreset,
progressbar,
)
from .table import (
ColumnsOption,
ColumnSpec,
SortByOption,
TableFormat,
TableFormatOption,
print_data,
print_table,
render_columns_markdown_table,
render_table,
select_columns,
select_row,
serialize_data,
)
from .telemetry import TelemetryOption
from .test_suite import (
DEFAULT_TEST_SUITE,
SUITE_FORMATS,
CLITestCase,
SkippedTest,
cases_from_data,
load_test_suite,
parse_test_suite,
run_test_suite,
)
from .testing import CliRunner, Result
from .theme import (
BUILTIN_THEMES,
HelpTheme,
ThemeOption,
get_current_theme,
get_default_theme,
register_theme,
set_default_theme,
theme_registry,
)
from .version import VersionOption
__all__ = [
"BOOL",
"BUILTIN_THEMES",
"CONFIG_PATH_METADATA_KEY",
"CPU_COUNT",
"DEFAULT_JOBS",
"DEFAULT_SUBCOMMANDS_KEY",
"DEFAULT_TEST_SUITE",
"EXTENSION_METADATA_KEY",
"FLOAT",
"INT",
"NORMALIZE_KEYS_METADATA_KEY",
"NO_CONFIG",
"PREPEND_SUBCOMMANDS_KEY",
"SPINNERS",
"STRING",
"SUITE_FORMATS",
"UNPROCESSED",
"UNSET",
"UUID",
"VCS",
"Abort",
"AccessibleOption",
"Argument",
"BadArgumentUsage",
"BadOptionUsage",
"BadParameter",
"CLITestCase",
"Choice",
"ChoiceSource",
"CliRunner",
"ClickException",
"Color",
"ColorOption",
"ColumnSpec",
"ColumnsOption",
"Command",
"CommandCollection",
"ConfigFormat",
"ConfigOption",
"ConfigValidator",
"ConstraintMixin",
"Context",
"DateTime",
"DumpConfigOption",
"EnumChoice",
"ExtraOption",
"File",
"FileError",
"FloatRange",
"Formatter",
"Group",
"HelpCommand",
"HelpFormatter",
"HelpKeywords",
"HelpSection",
"HelpTheme",
"IntRange",
"JobsOption",
"LazyGroup",
"LogLevel",
"ManOption",
"ManPage",
"MissingParameter",
"MultiChoice",
"NoColorOption",
"NoConfigOption",
"NoSuchCommand",
"NoSuchOption",
"Option",
"OptionGroup",
"OptionGroupMixin",
"ParamStructure",
"ParamType",
"Parameter",
"ParameterSource",
"Path",
"ProgressOption",
"QuietOption",
"Result",
"Section",
"SectionMixin",
"ShowParamsOption",
"SkippedTest",
"SortByOption",
"Spinner",
"SpinnerPreset",
"StreamHandler",
"Style",
"TableFormat",
"TableFormatOption",
"TelemetryOption",
"ThemeOption",
"TimerOption",
"Tuple",
"UsageError",
"ValidateConfigOption",
"ValidationError",
"ValidationReport",
"VerboseOption",
"VerbosityOption",
"VersionOption",
"ZeroExitOption",
"accessible_option",
"annotations",
"argument",
"basicConfig",
"cases_from_data",
"clear",
"color_option",
"columns_option",
"command",
"config_option",
"confirm",
"confirmation_option",
"constrained_params",
"constraint",
"context",
"dir_path",
"dump_config_option",
"echo",
"echo_via_pager",
"edit",
"file_path",
"flatten_config_keys",
"format_filename",
"format_from_path",
"format_param_row",
"get_app_dir",
"get_binary_stream",
"get_current_context",
"get_current_theme",
"get_default_theme",
"get_pager_file",
"get_param_spec",
"get_text_stream",
"get_tool_config",
"getchar",
"group",
"help_option",
"jobs_option",
"last_param",
"launch",
"lazy_group",
"load_test_suite",
"make_pass_decorator",
"make_schema_callable",
"man_option",
"new_logger",
"no_color_option",
"no_config_option",
"normalize_config_keys",
"open_file",
"option",
"option_group",
"parse_content",
"parse_test_suite",
"pass_context",
"pass_obj",
"password_option",
"path",
"pause",
"print_data",
"print_table",
"progressbar",
"prompt",
"quiet_option",
"read_file",
"register_theme",
"render_columns_markdown_table",
"render_manpage",
"render_manpages",
"render_table",
"require_sibling_param",
"run_config_validation",
"run_jobs",
"run_test_suite",
"search_params",
"secho",
"select_columns",
"select_row",
"serialize_content",
"serialize_data",
"set_default_theme",
"show_params_option",
"sort_by_option",
"style",
"table_format_option",
"telemetry_option",
"theme_option",
"theme_registry",
"timer_option",
"unstyle",
"validate_config_option",
"verbose_option",
"verbosity_option",
"version_option",
"warnings",
"wrap_text",
"write_manpages",
"zero_exit_option",
]
"""Expose all of Click, Cloup and Click Extra.
.. note::
The content of ``__all__`` is checked by a unittest and sorted by
``ruff`` via `RUF022 <https://docs.astral.sh/ruff/rules/unsorted-dunder-all/>`_.
"""
# NoSuchCommand and get_pager_file are only re-exported on Click >= 8.4.0 (see the
# guarded import above). Drop them from the public API on older Click so ``__all__``
# matches the names actually bound in this module.
if not _HAS_CLICK_8_4_EXPORTS:
__all__.remove("NoSuchCommand")
__all__.remove("get_pager_file")
del _HAS_CLICK_8_4_EXPORTS
__version__ = "8.2.0.dev0"
__git_branch__ = ""
__git_date__ = ""
__git_long_hash__ = ""
__git_short_hash__ = ""
__git_tag__ = ""
__git_tag_sha__ = ""