Generate Mkdocs
generate_mkdocs
Script to generate MFX documentation.
This script: 1. Cleans outdated .md files from docs/ folder (except index.md) 2. Finds all .py files in the repo (respecting .gitignore) 3. Generates .md files only if they don't exist or content changed 4. Generates mkdocs.yml with all files organized by module structure
Attributes
Functions
build_nav_from_structure
Build mkdocs nav structure from module structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Dict
|
Nested dictionary representing module structure |
required |
max_depth
|
int
|
Maximum depth to traverse, by default 10 |
10
|
current_depth
|
int
|
Current traversal depth, by default 0 |
0
|
Returns:
| Type | Description |
|---|---|
List
|
Navigation structure for mkdocs |
Source code in scripts/generate_mkdocs.py
clean_docs_folder
clean_docs_folder(docs_path: Path, valid_md_files: Set[Path], preserve_files: Optional[Set[str]] = None, backup: bool = False) -> None
Remove only orphaned .md files from docs folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs_path
|
Path
|
Path to docs folder |
required |
valid_md_files
|
Set[Path]
|
Set of valid markdown file paths |
required |
preserve_files
|
Optional[Set[str]]
|
Files to preserve from deletion, by default None |
None
|
backup
|
bool
|
Whether to create backup before cleaning, by default False |
False
|
Source code in scripts/generate_mkdocs.py
create_extra_css
Create extra CSS file for custom styling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs_path
|
Path
|
Documentation folder path |
required |
Source code in scripts/generate_mkdocs.py
505 506 507 508 509 510 511 512 513 514 515 516 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 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 | |
create_md_file
Create markdown file with mkdocstrings notation only if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
md_path
|
Path
|
Path where markdown file should be created |
required |
module_path
|
str
|
Python module path (e.g., 'package.module.file') |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if file was created/updated, False if unchanged |
Source code in scripts/generate_mkdocs.py
create_mkdocs_config
Create mkdocs configuration dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nav_structure
|
List
|
Navigation structure |
required |
repo_path
|
Path
|
Repository root path |
required |
Returns:
| Type | Description |
|---|---|
Dict
|
MkDocs configuration dictionary |
Source code in scripts/generate_mkdocs.py
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 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
find_python_files
find_python_files(repo_path: Path, gitignore_patterns: Set[str], exclude_dirs: Optional[Set[str]] = None) -> List[Path]
Find all Python files in repository, respecting .gitignore and exclusions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
Path
|
Repository root path |
required |
gitignore_patterns
|
Set[str]
|
Set of gitignore patterns |
required |
exclude_dirs
|
Optional[Set[str]]
|
Additional directories to exclude, by default None |
None
|
Returns:
| Type | Description |
|---|---|
List[Path]
|
Sorted list of Python file paths |
Source code in scripts/generate_mkdocs.py
generate_docs
generate_docs(repo_path: str = '.', docs_path: str = 'docs', backup: bool = False, show_ignored: bool = False, exclude_dirs: Optional[Set[str]] = None) -> None
Main documentation generation function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Repository root path, by default '.' |
'.'
|
docs_path
|
str
|
Documentation folder path, by default 'docs' |
'docs'
|
backup
|
bool
|
Whether to create backups, by default False |
False
|
show_ignored
|
bool
|
Whether to show gitignore patterns, by default False |
False
|
exclude_dirs
|
Optional[Set[str]]
|
Additional directories to exclude, by default None |
None
|
Source code in scripts/generate_mkdocs.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 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 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 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 793 794 795 796 797 798 799 800 801 | |
get_module_path
Convert file path to Python module path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
py_file
|
Path
|
Python file path |
required |
repo_path
|
Path
|
Repository root path |
required |
Returns:
| Type | Description |
|---|---|
str
|
Python module path (e.g., 'package.module.file') |
Source code in scripts/generate_mkdocs.py
is_ignored
is_ignored(path: Path, repo_path: Path, gitignore_patterns: Set[str], exclude_dirs: Optional[Set[str]] = None) -> bool
Check if path should be ignored based on gitignore and exclusions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to check |
required |
repo_path
|
Path
|
Repository root path |
required |
gitignore_patterns
|
Set[str]
|
Set of gitignore patterns |
required |
exclude_dirs
|
Optional[Set[str]]
|
Additional directories to exclude, by default None |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if path should be ignored, False otherwise |
Source code in scripts/generate_mkdocs.py
organize_by_module_structure
Organize Python files by their module structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
python_files
|
List[Path]
|
List of Python file paths |
required |
repo_path
|
Path
|
Repository root path |
required |
Returns:
| Type | Description |
|---|---|
Dict
|
Nested dictionary representing module structure |
Source code in scripts/generate_mkdocs.py
parse_gitignore
Parse .gitignore file and return set of patterns to ignore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
Path
|
Path to repository root |
required |
Returns:
| Type | Description |
|---|---|
Set[str]
|
Set of gitignore patterns |