@@ -71,8 +71,10 @@ def __init__(
7171 base_config = deep_merge (base_config , DEFAULT_DOCUMENT_CONFIG )
7272 base_config ["directories" ]["config" ] = config_path .parent .resolve ()
7373
74+ self .document .log_trace_section (
75+ "Loading document configuration: %s" , config_path
76+ )
7477 super ().__init__ (base_config , config_path )
75- self .document .log_trace_section ("Document configuration: %s" , config_path )
7678 self .document .log_trace (self .pretty ())
7779
7880 self .bake_path = self ["directories" ]["config" ] / "bake.py"
@@ -168,15 +170,13 @@ def process(self) -> Path | list[Path]:
168170 variant_config ["variant" ] = variant
169171 variant_config = render_config (variant_config )
170172 page_pdfs = self ._process_pages (variant_config )
171- pdf_files .append (
172- self ._combine_and_compress (page_pdfs , variant_config )
173- )
173+ pdf_files .append (self ._finalize (page_pdfs , variant_config ))
174174 return pdf_files
175175
176176 # Single PDF document
177177 doc_config = render_config (self .config )
178178 page_pdfs = self ._process_pages (doc_config )
179- return self ._combine_and_compress (page_pdfs , doc_config )
179+ return self ._finalize (page_pdfs , doc_config )
180180 except Exception :
181181 # Ensure build directory is cleaned up if processing fails
182182 if not self .baker .keep_build :
@@ -189,7 +189,6 @@ def _process_pages(self, config: dict[str, Any]) -> list[Path]:
189189 self .log_debug_subsection ("Pages to process:" )
190190 self .log_debug (self .config .pages )
191191 for page_num , page_config in enumerate (self .config .pages , start = 1 ):
192- # FIXME: just call with config - already merged
193192 page = PDFBakerPage (
194193 document = self ,
195194 page_number = page_num ,
@@ -200,10 +199,10 @@ def _process_pages(self, config: dict[str, Any]) -> list[Path]:
200199
201200 return pdf_files
202201
203- def _combine_and_compress (
204- self , pdf_files : list [Path ], doc_config : dict [str , Any ]
205- ) -> Path :
202+ def _finalize (self , pdf_files : list [Path ], doc_config : dict [str , Any ]) -> Path :
206203 """Combine PDF pages and optionally compress."""
204+ self .log_debug_subsection ("Finalizing document..." )
205+ self .log_debug ("Combining PDF pages..." )
207206 try :
208207 combined_pdf = combine_pdfs (
209208 pdf_files ,
@@ -215,6 +214,7 @@ def _combine_and_compress(
215214 output_path = self .config .dist_dir / f"{ doc_config ['filename' ]} .pdf"
216215
217216 if doc_config .get ("compress_pdf" , False ):
217+ self .log_debug ("Compressing PDF document..." )
218218 try :
219219 compress_pdf (combined_pdf , output_path )
220220 self .log_info ("PDF compressed successfully" )
@@ -227,23 +227,22 @@ def _combine_and_compress(
227227 else :
228228 os .rename (combined_pdf , output_path )
229229
230- self .log_info ("Created PDF: %s" , output_path )
230+ self .log_info ("Created %s" , output_path . name )
231231 return output_path
232232
233233 def teardown (self ) -> None :
234- """Clean up build directory after successful processing."""
234+ """Clean up build directory after processing."""
235235 self .log_debug_subsection (
236236 "Tearing down build directory: %s" , self .config .build_dir
237237 )
238238 if self .config .build_dir .exists ():
239- # Remove all files in the build directory
239+ self . log_debug ( "Removing files in build directory..." )
240240 for file_path in self .config .build_dir .iterdir ():
241241 if file_path .is_file ():
242242 file_path .unlink ()
243243
244- # Try to remove the build directory
245244 try :
245+ self .log_debug ("Removing build directory..." )
246246 self .config .build_dir .rmdir ()
247247 except OSError :
248- # Directory not empty - this is expected if we have subdirectories
249- pass
248+ self .log_warning ("Build directory not empty - not removing" )
0 commit comments