From 18273e21b3ffd8087b4b163c54e45edc0b43d039 Mon Sep 17 00:00:00 2001 From: John Franey <1728528+johnfraney@users.noreply.github.com> Date: Tue, 31 Dec 2024 13:01:04 -0400 Subject: [PATCH] fix: show exceptions in build; update Mistune (#105) Fixes build exceptions being swallowed in the ThreadPoolExecutor. Also updates Mistune to the latest version --- blurry/__init__.py | 22 ++++++-- blurry/markdown/__init__.py | 5 +- .../markdown_plugins/container_plugin.py | 2 + poetry.lock | 56 ++----------------- pyproject.toml | 2 +- 5 files changed, 30 insertions(+), 57 deletions(-) diff --git a/blurry/__init__.py b/blurry/__init__.py index 778f0a3..d2cf1ef 100644 --- a/blurry/__init__.py +++ b/blurry/__init__.py @@ -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, @@ -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), @@ -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, @@ -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" diff --git a/blurry/markdown/__init__.py b/blurry/markdown/__init__.py index a747881..9212110 100644 --- a/blurry/markdown/__init__.py +++ b/blurry/markdown/__init__.py @@ -137,7 +137,7 @@ 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) @@ -145,7 +145,8 @@ def is_blurry_renderer( 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, diff --git a/blurry/plugins/markdown_plugins/container_plugin.py b/blurry/plugins/markdown_plugins/container_plugin.py index 0bf4ec1..6d08b9a 100644 --- a/blurry/plugins/markdown_plugins/container_plugin.py +++ b/blurry/plugins/markdown_plugins/container_plugin.py @@ -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: "") diff --git a/poetry.lock b/poetry.lock index 3b67b16..ac6d349 100644 --- a/poetry.lock +++ b/poetry.lock @@ -80,7 +80,6 @@ click = ">=8.0.0" mypy-extensions = ">=0.4.3" pathspec = ">=0.9.0" platformdirs = ">=2" -tomli = {version = ">=1.1.0", markers = "python_full_version < \"3.11.0a7\""} [package.extras] colorama = ["colorama (>=0.4.3)"] @@ -684,13 +683,13 @@ files = [ [[package]] name = "mistune" -version = "3.0.2" +version = "3.1.0" description = "A sane and fast Markdown parser with useful plugins and renderers" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "mistune-3.0.2-py3-none-any.whl", hash = "sha256:71481854c30fdbc938963d3605b72501f5c10a9320ecd412c121c163a1c7d205"}, - {file = "mistune-3.0.2.tar.gz", hash = "sha256:fc7f93ded930c92394ef2cb6f04a8aabab4117a91449e72dcc8dfa646a508be8"}, + {file = "mistune-3.1.0-py3-none-any.whl", hash = "sha256:b05198cf6d671b3deba6c87ec6cf0d4eb7b72c524636eddb6dbf13823b52cee1"}, + {file = "mistune-3.1.0.tar.gz", hash = "sha256:dbcac2f78292b9dc066cd03b7a3a26b62d85f8159f2ea5fd28e55df79908d667"}, ] [[package]] @@ -730,7 +729,6 @@ files = [ argcomplete = ">=1.9.4,<4" colorlog = ">=2.6.1,<7" packaging = ">=20.9" -tomli = {version = ">=1", markers = "python_version < \"3.11\""} virtualenv = ">=20.14.1" [package.extras] @@ -1076,7 +1074,6 @@ files = [ [package.dependencies] markdown-it-py = ">=2.2.0" pygments = ">=2.13.0,<3.0.0" -typing-extensions = {version = ">=4.0.0,<5.0", markers = "python_version < \"3.11\""} [package.extras] jupyter = ["ipywidgets (>=7.5.1,<9)"] @@ -1196,47 +1193,6 @@ files = [ {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, ] -[[package]] -name = "tomli" -version = "2.2.1" -description = "A lil' TOML parser" -optional = false -python-versions = ">=3.8" -files = [ - {file = "tomli-2.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249"}, - {file = "tomli-2.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:023aa114dd824ade0100497eb2318602af309e5a55595f76b626d6d9f3b7b0a6"}, - {file = "tomli-2.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ece47d672db52ac607a3d9599a9d48dcb2f2f735c6c2d1f34130085bb12b112a"}, - {file = "tomli-2.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6972ca9c9cc9f0acaa56a8ca1ff51e7af152a9f87fb64623e31d5c83700080ee"}, - {file = "tomli-2.2.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c954d2250168d28797dd4e3ac5cf812a406cd5a92674ee4c8f123c889786aa8e"}, - {file = "tomli-2.2.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:8dd28b3e155b80f4d54beb40a441d366adcfe740969820caf156c019fb5c7ec4"}, - {file = "tomli-2.2.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:e59e304978767a54663af13c07b3d1af22ddee3bb2fb0618ca1593e4f593a106"}, - {file = "tomli-2.2.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:33580bccab0338d00994d7f16f4c4ec25b776af3ffaac1ed74e0b3fc95e885a8"}, - {file = "tomli-2.2.1-cp311-cp311-win32.whl", hash = "sha256:465af0e0875402f1d226519c9904f37254b3045fc5084697cefb9bdde1ff99ff"}, - {file = "tomli-2.2.1-cp311-cp311-win_amd64.whl", hash = "sha256:2d0f2fdd22b02c6d81637a3c95f8cd77f995846af7414c5c4b8d0545afa1bc4b"}, - {file = "tomli-2.2.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:4a8f6e44de52d5e6c657c9fe83b562f5f4256d8ebbfe4ff922c495620a7f6cea"}, - {file = "tomli-2.2.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:8d57ca8095a641b8237d5b079147646153d22552f1c637fd3ba7f4b0b29167a8"}, - {file = "tomli-2.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e340144ad7ae1533cb897d406382b4b6fede8890a03738ff1683af800d54192"}, - {file = "tomli-2.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:db2b95f9de79181805df90bedc5a5ab4c165e6ec3fe99f970d0e302f384ad222"}, - {file = "tomli-2.2.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:40741994320b232529c802f8bc86da4e1aa9f413db394617b9a256ae0f9a7f77"}, - {file = "tomli-2.2.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:400e720fe168c0f8521520190686ef8ef033fb19fc493da09779e592861b78c6"}, - {file = "tomli-2.2.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:02abe224de6ae62c19f090f68da4e27b10af2b93213d36cf44e6e1c5abd19fdd"}, - {file = "tomli-2.2.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:b82ebccc8c8a36f2094e969560a1b836758481f3dc360ce9a3277c65f374285e"}, - {file = "tomli-2.2.1-cp312-cp312-win32.whl", hash = "sha256:889f80ef92701b9dbb224e49ec87c645ce5df3fa2cc548664eb8a25e03127a98"}, - {file = "tomli-2.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:7fc04e92e1d624a4a63c76474610238576942d6b8950a2d7f908a340494e67e4"}, - {file = "tomli-2.2.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f4039b9cbc3048b2416cc57ab3bda989a6fcf9b36cf8937f01a6e731b64f80d7"}, - {file = "tomli-2.2.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:286f0ca2ffeeb5b9bd4fcc8d6c330534323ec51b2f52da063b11c502da16f30c"}, - {file = "tomli-2.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a92ef1a44547e894e2a17d24e7557a5e85a9e1d0048b0b5e7541f76c5032cb13"}, - {file = "tomli-2.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9316dc65bed1684c9a98ee68759ceaed29d229e985297003e494aa825ebb0281"}, - {file = "tomli-2.2.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e85e99945e688e32d5a35c1ff38ed0b3f41f43fad8df0bdf79f72b2ba7bc5272"}, - {file = "tomli-2.2.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ac065718db92ca818f8d6141b5f66369833d4a80a9d74435a268c52bdfa73140"}, - {file = "tomli-2.2.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:d920f33822747519673ee656a4b6ac33e382eca9d331c87770faa3eef562aeb2"}, - {file = "tomli-2.2.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:a198f10c4d1b1375d7687bc25294306e551bf1abfa4eace6650070a5c1ae2744"}, - {file = "tomli-2.2.1-cp313-cp313-win32.whl", hash = "sha256:d3f5614314d758649ab2ab3a62d4f2004c825922f9e370b29416484086b264ec"}, - {file = "tomli-2.2.1-cp313-cp313-win_amd64.whl", hash = "sha256:a38aa0308e754b0e3c67e344754dff64999ff9b513e691d0e786265c93583c69"}, - {file = "tomli-2.2.1-py3-none-any.whl", hash = "sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc"}, - {file = "tomli-2.2.1.tar.gz", hash = "sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff"}, -] - [[package]] name = "tornado" version = "6.4.2" @@ -1367,5 +1323,5 @@ watchmedo = ["PyYAML (>=3.10)"] [metadata] lock-version = "2.0" -python-versions = "^3.10" -content-hash = "44bc93a2aa92ce93edd2887cedf38e7bf41e6b2e8554e8526b94b9b46f920f06" +python-versions = "^3.11" +content-hash = "6b9769c7c71be685c87333cf72d998b3ecb16205e79dc91fcdf94015ea54d254" diff --git a/pyproject.toml b/pyproject.toml index 65f0b75..d2e5bc5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"