File iotas-optional-pypandoc.patch of Package iotas
From 2dccbf2b1b10b7dea0f2c2dbe12ece4abd7daa72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ball=C3=B3=20Gy=C3=B6rgy?= <ballogyor@gmail.com>
Date: Mon, 14 Apr 2025 18:44:54 +0200
Subject: [PATCH] feat: Make pypandoc optional
Pypandoc is a huge dependency and it's needed only for ODT and custom
defined export formats, while exporting to HTML and PDF still works without
it.
---
iotas/exporter.py | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/iotas/exporter.py b/iotas/exporter.py
index 313d877..64e3a83 100644
--- a/iotas/exporter.py
+++ b/iotas/exporter.py
@@ -8,7 +8,10 @@ import shutil
from typing import Optional
import unicodedata
-import pypandoc
+try:
+ import pypandoc
+except ModuleNotFoundError:
+ pypandoc = None
from iotas.html_generator import HtmlGenerator
from iotas.note import Note
@@ -122,16 +125,23 @@ class Exporter(GObject.Object):
def __export_pandoc(self, out_format: str) -> None:
self.__active = True
- try:
- pypandoc.convert_text(
- self.__note.content, out_format, format="gfm", outputfile=self.__location
- )
- except (RuntimeError, OSError) as e:
- logging.warning(f"Failed to export {out_format} to {self.__location}: %s", e)
- self.emit("failed", self.__out_format, str(e))
+ if pypandoc:
+ try:
+ pypandoc.convert_text(
+ self.__note.content, out_format, format="gfm", outputfile=self.__location
+ )
+ except (RuntimeError, OSError) as e:
+ logging.warning(f"Failed to export {out_format} to {self.__location}: %s", e)
+ self.emit("failed", self.__out_format, str(e))
+ else:
+ logging.info(f"Exported {self.__out_format} to {self.__location}")
+ self.emit("finished", self.__out_format, self.__location)
else:
- logging.info(f"Exported {self.__out_format} to {self.__location}")
- self.emit("finished", self.__out_format, self.__location)
+ logging.warning(
+ f"Failed to export {out_format} to {self.__location}: "
+ "Pypandoc is not installed on your system."
+ )
+ self.emit("failed", self.__out_format, "Pypandoc is not installed on your system.")
self.__active = False
def __export_pdf(self) -> None:
--
GitLab