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(-)
Index: iotas-0.12.0/iotas/exporter.py
===================================================================
--- iotas-0.12.0.orig/iotas/exporter.py
+++ iotas-0.12.0/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.attachment_helpers import (
AttachmentsCopyOutcome,
@@ -157,20 +160,24 @@ class Exporter(GObject.Object):
content = get_note_export_content(self.__note, prefix_note_id=True)
working_dir = os.path.abspath(os.path.join(get_attachments_dir(), os.pardir))
- try:
- pypandoc.convert_text(
- content,
- out_format,
- format="gfm+attributes+implicit_figures",
- outputfile=self.__location,
- cworkdir=working_dir,
- )
- except (RuntimeError, OSError) as e:
- logging.warning(f"Failed to export {out_format} to {self.__location}: {e}")
- self.emit("failed", str(e))
+ if pypandoc:
+ try:
+ pypandoc.convert_text(
+ content,
+ out_format,
+ format="gfm+attributes+implicit_figures",
+ outputfile=self.__location,
+ cworkdir=working_dir,
+ )
+ except (RuntimeError, OSError) as e:
+ logging.warning(f"Failed to export {out_format} to {self.__location}: {e}")
+ self.emit("failed", str(e))
else:
- logging.info(f"Exported {self.__out_format} to {self.__location}")
- self.emit("finished", 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: