55import os
66import sys
77from pathlib import Path
8+ from typing import Any
89
910import click
1011import yaml
1718
1819
1920@click .group ()
20- def cli ():
21+ def cli () -> None :
2122 """Generate PDF documents from YAML-configured SVG templates."""
2223
2324
@@ -33,7 +34,9 @@ def cli():
3334 is_flag = True ,
3435 help = "Debug mode (implies --verbose, keeps build files)" ,
3536)
36- def bake (config_file , verbose = False , quiet = False , debug = False ):
37+ def bake (
38+ config_file : Path , verbose : bool = False , quiet : bool = False , debug : bool = False
39+ ) -> int :
3740 """Parse config file and bake PDFs."""
3841 if debug :
3942 verbose = True
@@ -59,13 +62,13 @@ def bake(config_file, verbose=False, quiet=False, debug=False):
5962 return 0
6063
6164
62- def _load_config (config_file ) :
65+ def _load_config (config_file : Path ) -> dict [ str , Any ] :
6366 """Load configuration from a YAML file."""
6467 with open (config_file , encoding = "utf-8" ) as f :
6568 return yaml .safe_load (f )
6669
6770
68- def _setup_output_directories (base_dir ) :
71+ def _setup_output_directories (base_dir : Path ) -> tuple [ Path , Path ] :
6972 """Create and return build and dist directories."""
7073 build_dir = base_dir / "build"
7174 dist_dir = base_dir / "dist"
@@ -74,9 +77,11 @@ def _setup_output_directories(base_dir):
7477 return build_dir , dist_dir
7578
7679
77- def _get_document_paths (base_dir , documents ):
80+ def _get_document_paths (
81+ base_dir : Path , documents : list [dict [str , str ] | str ]
82+ ) -> dict [str , Path ]:
7883 """Resolve document paths to absolute paths."""
79- document_paths = {}
84+ document_paths : dict [ str , Path ] = {}
8085
8186 for doc_name in documents :
8287 if isinstance (doc_name , dict ):
@@ -92,7 +97,7 @@ def _get_document_paths(base_dir, documents):
9297 return document_paths
9398
9499
95- def _validate_document_path (doc_name , doc_path ) :
100+ def _validate_document_path (doc_name : str , doc_path : Path ) -> tuple [ Path , Path ] | bool :
96101 """Validate that a document has all required files."""
97102 if not doc_path .is_dir ():
98103 logger .warning ('Directory missing for document "%s" at %s' , doc_name , doc_path )
@@ -111,7 +116,13 @@ def _validate_document_path(doc_name, doc_path):
111116 return bake_path , config_yml_path
112117
113118
114- def _process_document (doc_name , doc_path , config , build_dir , dist_dir ):
119+ def _process_document (
120+ doc_name : str ,
121+ doc_path : Path ,
122+ config : dict [str , Any ],
123+ build_dir : Path ,
124+ dist_dir : Path ,
125+ ) -> None :
115126 """Process an individual document."""
116127 validation_result = _validate_document_path (doc_name , doc_path )
117128 if not validation_result :
@@ -143,7 +154,7 @@ def _process_document(doc_name, doc_path, config, build_dir, dist_dir):
143154 )
144155
145156
146- def _load_document_bake_module (doc_name , bake_path ) :
157+ def _load_document_bake_module (doc_name : str , bake_path : Path ) -> Any :
147158 """Load the document's bake.py module."""
148159 doc_bake = importlib .util .spec_from_file_location (
149160 f"documents.{ doc_name } .bake" , bake_path
@@ -153,7 +164,9 @@ def _load_document_bake_module(doc_name, bake_path):
153164 return module
154165
155166
156- def _setup_document_output_directories (build_dir , dist_dir , doc_name ):
167+ def _setup_document_output_directories (
168+ build_dir : Path , dist_dir : Path , doc_name : str
169+ ) -> tuple [Path , Path ]:
157170 """Set up and clean document-specific build and dist directories."""
158171 doc_build_dir = build_dir / doc_name
159172 doc_dist_dir = dist_dir / doc_name
@@ -169,7 +182,7 @@ def _setup_document_output_directories(build_dir, dist_dir, doc_name):
169182 return doc_build_dir , doc_dist_dir
170183
171184
172- def _teardown_build_directories (build_dir , doc_names ) :
185+ def _teardown_build_directories (build_dir : Path , doc_names : list [ str ]) -> None :
173186 """Clean up build directories after successful processing.
174187
175188 Args:
0 commit comments