CLI
docstring_format_checker.cli
π
Summary
Command-line interface for the docstring format checker.
_colour
π
_colour(text: str, colour: str) -> str
Summary
Apply Rich colour markup to text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to colour. |
required |
colour
|
str
|
The colour to apply, e.g., 'red', 'green', 'blue'. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text wrapped in Rich colour markup. |
Source code in src/docstring_format_checker/cli.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
app
module-attribute
π
app = Typer(
name="docstring-format-checker",
help="A CLI tool to check and validate Python docstring formatting and completeness.",
add_completion=False,
rich_markup_mode="rich",
add_help_option=False,
)
_version_callback
π
_version_callback(
ctx: Context, param: CallbackParam, value: bool
) -> None
Summary
Print version and exit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
The context object. |
required |
param
|
CallbackParam
|
The parameter object. |
required |
value
|
bool
|
The boolean value indicating if the flag was set. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Nothing is returned. |
Source code in src/docstring_format_checker/cli.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
_example_callback
π
_example_callback(
ctx: Context, param: CallbackParam, value: Optional[str]
) -> None
Summary
Handle example flag and show appropriate example content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
The context object. |
required |
param
|
CallbackParam
|
The parameter object. |
required |
value
|
Optional[str]
|
The example type to show: 'config' or 'usage'. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Nothing is returned. |
Source code in src/docstring_format_checker/cli.py
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 | |
_show_usage_examples_callback
π
_show_usage_examples_callback() -> None
Summary
Show examples and exit.
Returns:
| Type | Description |
|---|---|
None
|
Nothing is returned. |
Source code in src/docstring_format_checker/cli.py
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 | |
_show_config_example_callback
π
_show_config_example_callback() -> None
Summary
Show configuration example and exit.
Returns:
| Type | Description |
|---|---|
None
|
Nothing is returned. |
Source code in src/docstring_format_checker/cli.py
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 | |
_help_callback_main
π
_help_callback_main(
ctx: Context, param: CallbackParam, value: bool
) -> None
Summary
Show help and exit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
The context object. |
required |
param
|
CallbackParam
|
The parameter object. |
required |
value
|
bool
|
The boolean value indicating if the flag was set. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Nothing is returned. |
Source code in src/docstring_format_checker/cli.py
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 | |
_format_error_messages
π
_format_error_messages(error_message: str) -> str
!!! note "Summary"
Format error messages for better readability in CLI output.
Params:
error_message (str):
The raw error message that may contain semicolon-separated errors
Returns:
(str):
Formatted error message with each error prefixed with "- " and separated by ";
"
Source code in src/docstring_format_checker/cli.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
_display_results
π
_display_results(
results: dict[str, list[DocstringError]],
quiet: bool,
output: str,
check: bool,
) -> int
Summary
Display the results of docstring checking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict[str, list[DocstringError]]
|
Dictionary mapping file paths to lists of errors |
required |
quiet
|
bool
|
Whether to suppress success messages and error details |
required |
output
|
str
|
Output format: 'table' or 'list' |
required |
check
|
bool
|
Whether this is a check run (affects quiet behavior) |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code ( |
Source code in src/docstring_format_checker/cli.py
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 | |
_count_errors_and_files
π
_count_errors_and_files(
results: dict[str, list[DocstringError]],
) -> dict[str, int]
Summary
Count total errors, functions, and files from results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict[str, list[DocstringError]]
|
Dictionary mapping file paths to lists of errors. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Dictionary containing total_errors, total_functions, and total_files. |
Source code in src/docstring_format_checker/cli.py
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 | |
_display_quiet_summary
π
_display_quiet_summary(error_stats: dict[str, int]) -> None
Summary
Display summary in quiet mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_stats
|
dict[str, int]
|
Dictionary containing total_errors, total_functions, and total_files. |
required |
Source code in src/docstring_format_checker/cli.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
_display_table_output
π
_display_table_output(
results: dict[str, list[DocstringError]],
) -> None
Summary
Display results in table format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict[str, list[DocstringError]]
|
Dictionary mapping file paths to lists of errors. |
required |
Source code in src/docstring_format_checker/cli.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
_create_error_header
π
_create_error_header(error: DocstringError) -> str
Summary
Create formatted header for a single error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
DocstringError
|
The error to create a header for. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted header string with line number, item type, and name. |
Source code in src/docstring_format_checker/cli.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |
_split_error_messages
π
_split_error_messages(message: str) -> list[str]
Summary
Split compound error message into individual messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The error message to split. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of individual error messages. |
Source code in src/docstring_format_checker/cli.py
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | |
_format_error_output
π
_format_error_output(error: DocstringError) -> list[str]
Summary
Format single error for display output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
DocstringError
|
The error to format. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of formatted lines to print. |
Source code in src/docstring_format_checker/cli.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 | |
_display_list_output
π
_display_list_output(
results: dict[str, list[DocstringError]],
) -> None
Summary
Display results in list format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict[str, list[DocstringError]]
|
Dictionary mapping file paths to lists of errors. |
required |
Source code in src/docstring_format_checker/cli.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
_display_final_summary
π
_display_final_summary(error_stats: dict[str, int]) -> None
Summary
Display the final summary line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_stats
|
dict[str, int]
|
Dictionary containing total_errors, total_functions, and total_files. |
required |
Source code in src/docstring_format_checker/cli.py
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
check_docstrings
π
check_docstrings(
paths: list[str],
config: Optional[str] = None,
exclude: Optional[list[str]] = None,
quiet: bool = False,
output: str = "list",
check: bool = False,
) -> None
Summary
Core logic for checking docstrings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list[str]
|
The path(s) to the file(s) or directory(ies) to check. |
required |
config
|
Optional[str]
|
The path to the configuration file.
Default: |
None
|
exclude
|
Optional[list[str]]
|
List of glob patterns to exclude from checking.
Default: |
None
|
quiet
|
bool
|
Whether to suppress output.
Default: |
False
|
output
|
str
|
Output format: 'table' or 'list'.
Default: |
'list'
|
check
|
bool
|
Whether to throw error if issues are found.
Default: |
False
|
Returns:
| Type | Description |
|---|---|
None
|
Nothing is returned. |
Source code in src/docstring_format_checker/cli.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | |
_validate_and_process_paths
π
_validate_and_process_paths(paths: list[str]) -> list[Path]
Summary
Validate input paths and return valid paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list[str]
|
List of path strings to validate. |
required |
Raises:
| Type | Description |
|---|---|
Exit
|
If any paths do not exist. |
Returns:
| Type | Description |
|---|---|
list[Path]
|
List of valid Path objects. |
Source code in src/docstring_format_checker/cli.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | |
_load_and_validate_config
π
_load_and_validate_config(
config: Optional[str], target_paths: list[Path]
) -> Config
Summary
Load and validate configuration from file or auto-discovery.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[str]
|
Optional path to configuration file. |
required |
target_paths
|
list[Path]
|
List of target paths for auto-discovery. |
required |
Raises:
| Type | Description |
|---|---|
Exit
|
If configuration loading fails. |
Returns:
| Type | Description |
|---|---|
Config
|
Loaded configuration object. |
Source code in src/docstring_format_checker/cli.py
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | |
_load_explicit_config
π
_load_explicit_config(config: str) -> Config
Summary
Load configuration from explicitly specified path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Path to configuration file. |
required |
Raises:
| Type | Description |
|---|---|
Exit
|
If configuration file does not exist. |
Returns:
| Type | Description |
|---|---|
Config
|
Loaded configuration object. |
Source code in src/docstring_format_checker/cli.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 | |
_load_auto_discovered_config
π
_load_auto_discovered_config(
target_paths: list[Path],
) -> Config
Summary
Load configuration from auto-discovery or defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_paths
|
list[Path]
|
List of target paths to search for configuration. |
required |
Returns:
| Type | Description |
|---|---|
Config
|
Loaded configuration object from found config or defaults. |
Source code in src/docstring_format_checker/cli.py
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 | |
_process_all_paths
π
_process_all_paths(
checker: DocstringChecker,
target_paths: list[Path],
exclude: Optional[list[str]],
) -> dict[str, list[DocstringError]]
Summary
Process all target paths and collect docstring errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checker
|
DocstringChecker
|
The checker instance to use. |
required |
target_paths
|
list[Path]
|
List of paths to check (files or directories). |
required |
exclude
|
Optional[list[str]]
|
Optional list of exclusion patterns. |
required |
Raises:
| Type | Description |
|---|---|
Exit
|
If an error occurs during checking. |
Returns:
| Type | Description |
|---|---|
dict[str, list[DocstringError]]
|
Dictionary mapping file paths to lists of errors. |
Source code in src/docstring_format_checker/cli.py
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
main
π
main(
ctx: Context,
paths: Optional[list[str]] = Argument(
None,
help="Path(s) to Python file(s) or directory(s) for DFC to check",
),
config: Optional[str] = Option(
None,
"--config",
"-f",
help="Path to configuration file (TOML format)",
),
exclude: Optional[list[str]] = Option(
None,
"--exclude",
"-x",
help="Glob patterns to exclude (can be used multiple times)",
),
output: str = Option(
"list",
"--output",
"-o",
help="Output format: 'table' or 'list'",
show_default=True,
),
check: bool = Option(
False,
"--check",
"-c",
help="Throw error (exit 1) if any issues are found",
),
quiet: bool = Option(
False,
"--quiet",
"-q",
help="Only output pass/fail confirmation, suppress errors unless failing",
),
example: Optional[str] = Option(
None,
"--example",
"-e",
callback=_example_callback,
is_eager=True,
help="Show examples: 'config' for configuration example, 'usage' for usage examples",
),
version: Optional[bool] = Option(
None,
"--version",
"-v",
callback=_version_callback,
is_eager=True,
help="Show version and exit",
),
help_flag: Optional[bool] = Option(
None,
"--help",
"-h",
callback=_help_callback_main,
is_eager=True,
help="Show this message and exit",
),
) -> None
Summary
Check Python docstring formatting and completeness.
Details
This tool analyzes Python files and validates that functions, methods, and classes have properly formatted docstrings according to the configured sections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
The context object for the command. |
required |
paths
|
Optional[list[str]]
|
Path(s) to Python file(s) or directory(ies) to check. |
Argument(None, help='Path(s) to Python file(s) or directory(s) for DFC to check')
|
config
|
Optional[str]
|
Path to configuration file (TOML format). |
Option(None, '--config', '-f', help='Path to configuration file (TOML format)')
|
exclude
|
Optional[list[str]]
|
Glob patterns to exclude. |
Option(None, '--exclude', '-x', help='Glob patterns to exclude (can be used multiple times)')
|
output
|
str
|
Output format: 'table' or 'list'. |
Option('list', '--output', '-o', help="Output format: 'table' or 'list'", show_default=True)
|
check
|
bool
|
Throw error if any issues are found. |
Option(False, '--check', '-c', help='Throw error (exit 1) if any issues are found')
|
quiet
|
bool
|
Only output pass/fail confirmation. |
Option(False, '--quiet', '-q', help='Only output pass/fail confirmation, suppress errors unless failing')
|
example
|
Optional[str]
|
Show examples: 'config' or 'usage'. |
Option(None, '--example', '-e', callback=_example_callback, is_eager=True, help="Show examples: 'config' for configuration example, 'usage' for usage examples")
|
version
|
Optional[bool]
|
Show version and exit. |
Option(None, '--version', '-v', callback=_version_callback, is_eager=True, help='Show version and exit')
|
help_flag
|
Optional[bool]
|
Show help message and exit. |
Option(None, '--help', '-h', callback=_help_callback_main, is_eager=True, help='Show this message and exit')
|
Returns:
| Type | Description |
|---|---|
None
|
Nothing is returned. |
Source code in src/docstring_format_checker/cli.py
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 | |
entry_point
π
entry_point() -> None
Summary
Entry point for the CLI scripts defined in pyproject.toml.
Source code in src/docstring_format_checker/cli.py
912 913 914 915 916 917 | |