Skip to content

Commit 9aac8ca

Browse files
committed
Fix timing of teardown
We just tear down the document build dir at the end, no matter what. The way it was before it would tear down, _then_ show an error message if there was an error. Now the output is more logical. (sure, same result)
1 parent 6e41748 commit 9aac8ca

2 files changed

Lines changed: 18 additions & 26 deletions

File tree

src/pdfbaker/baker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ def bake(self) -> None:
138138
if isinstance(pdf_files, Path):
139139
pdf_files = [pdf_files]
140140
pdfs_created.extend(pdf_files)
141-
if not self.keep_build:
142-
doc.teardown()
141+
if not self.keep_build:
142+
doc.teardown()
143143

144144
if pdfs_created:
145145
self.log_info("Successfully created PDFs:")

src/pdfbaker/document.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -157,30 +157,22 @@ def _process_with_custom_bake(self, bake_path: Path) -> Path | list[Path]:
157157

158158
def process(self) -> Path | list[Path]:
159159
"""Process document using standard processing."""
160-
try:
161-
if "variants" in self.config:
162-
# Multiple PDF documents
163-
pdf_files = []
164-
for variant in self.config["variants"]:
165-
self.log_info_subsection(
166-
'Processing variant "%s"...', variant["name"]
167-
)
168-
variant_config = deep_merge(self.config, variant)
169-
variant_config["variant"] = variant
170-
variant_config = render_config(variant_config)
171-
page_pdfs = self._process_pages(variant_config)
172-
pdf_files.append(self._finalize(page_pdfs, variant_config))
173-
return pdf_files
174-
175-
# Single PDF document
176-
doc_config = render_config(self.config)
177-
page_pdfs = self._process_pages(doc_config)
178-
return self._finalize(page_pdfs, doc_config)
179-
except Exception:
180-
# Ensure build directory is cleaned up if processing fails
181-
if not self.baker.keep_build:
182-
self.teardown()
183-
raise
160+
if "variants" in self.config:
161+
# Multiple PDF documents
162+
pdf_files = []
163+
for variant in self.config["variants"]:
164+
self.log_info_subsection('Processing variant "%s"...', variant["name"])
165+
variant_config = deep_merge(self.config, variant)
166+
variant_config["variant"] = variant
167+
variant_config = render_config(variant_config)
168+
page_pdfs = self._process_pages(variant_config)
169+
pdf_files.append(self._finalize(page_pdfs, variant_config))
170+
return pdf_files
171+
172+
# Single PDF document
173+
doc_config = render_config(self.config)
174+
page_pdfs = self._process_pages(doc_config)
175+
return self._finalize(page_pdfs, doc_config)
184176

185177
def _process_pages(self, config: dict[str, Any]) -> list[Path]:
186178
"""Process pages with given configuration."""

0 commit comments

Comments
 (0)