Skip to content

Commit

Permalink
fix: show exceptions in build; update Mistune (#105)
Browse files Browse the repository at this point in the history
Fixes build exceptions being swallowed in the ThreadPoolExecutor.

Also updates Mistune to the latest version
  • Loading branch information
johnfraney authored Dec 31, 2024
1 parent 2875208 commit 18273e2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 57 deletions.
22 changes: 18 additions & 4 deletions blurry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ def gather_file_data_by_directory() -> DirectoryFileData:
for future in concurrent.futures.as_completed(markdown_future_to_path):
body, front_matter = future.result()
relative_filepath = markdown_future_to_path[future]
if exception := future.exception():
print(
f"{relative_filepath}: Could not convert file to HTML - {exception}"
)
file_data = MarkdownFileData(
body=body,
front_matter=front_matter,
Expand Down Expand Up @@ -281,6 +285,12 @@ async def build(release=True, clean: bool = False):
if filepath.is_dir():
continue
if filepath.suffix == ".md":

def on_markdown_file_processed(future: concurrent.futures.Future):
progress.advance(markdown_task)
if exception := future.exception():
print(f"{filepath}: could not process file - {exception}")

markdown_future = executor.submit(
write_html_file,
filepath.relative_to(content_directory),
Expand All @@ -290,9 +300,7 @@ async def build(release=True, clean: bool = False):
)
markdown_task_count += 1
progress.update(markdown_task, total=markdown_task_count)
markdown_future.add_done_callback(
lambda _: progress.advance(markdown_task)
)
markdown_future.add_done_callback(on_markdown_file_processed)
continue
other_future = executor.submit(
process_non_markdown_file,
Expand All @@ -302,7 +310,13 @@ async def build(release=True, clean: bool = False):
)
non_markdown_task_count += 1
progress.update(other_task, total=non_markdown_task_count)
other_future.add_done_callback(lambda _: progress.advance(other_task))

def on_non_markdown_file_processed(future: concurrent.futures.Future):
progress.advance(other_task)
if exception := future.exception():
print(f"{filepath}: could not process file - {exception}")

other_future.add_done_callback(on_non_markdown_file_processed)

print(
f"Blurring {markdown_task_count} Markdown files and {non_markdown_task_count} other files"
Expand Down
5 changes: 3 additions & 2 deletions blurry/markdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,16 @@ def link(self, text, url, title: str | None = None) -> str:


def is_blurry_renderer(
renderer: mistune.HTMLRenderer,
renderer: mistune.BaseRenderer,
) -> TypeGuard[type[BlurryRenderer]]:
return isinstance(renderer, BlurryRenderer)


renderer = BlurryRenderer(escape=False)
markdown = mistune.Markdown(
renderer,
plugins=[
# Ignoring types because the renderer is expecting markdown: Markdown rather than md: Markdown
plugins=[ # type: ignore
abbr,
def_list,
footnotes,
Expand Down
2 changes: 2 additions & 0 deletions blurry/plugins/markdown_plugins/container_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def __call__(self, directive, md):
for name in self.SUPPORTED_NAMES:
directive.register(name, self.parse)

if not md.renderer:
raise ValueError("Renderer not found on Markdown instance")
if md.renderer.NAME == "html":
md.renderer.register("admonition", render_admonition)
md.renderer.register("admonition_title", lambda plugin, text: "")
Expand Down
56 changes: 6 additions & 50 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PyLD = "^2.0.3"
Wand = "^0.6.6"
ffmpeg-python = "^0.2.0"
livereload = "^2.7.0"
mistune = "^3.0.2"
mistune = "^3.0.10"
python = "^3.11"
rich = "^13.3.3"
selectolax = "^0.3.27"
Expand Down

0 comments on commit 18273e2

Please sign in to comment.