From 472d48d95ea0aa7f59a25d2c4082a5336516f0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 15 Jun 2026 15:15:56 +0200 Subject: [PATCH] Make saxonche dependency optional --- README.rst | 2 ++ pyproject.toml | 3 ++- src/facturx/facturx.py | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index f27ed87..9487bf9 100644 --- a/README.rst +++ b/README.rst @@ -139,6 +139,8 @@ Contributors Changelog ========= + * Make saxonche dependency optional + * Version 4.3 dated 2026-05-26 (`OCA code sprint Santander `_) * Restore compatibility with lxml 4.6.5 diff --git a/pyproject.toml b/pyproject.toml index f24d956..ea2a290 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,13 +22,14 @@ license = {file = "LICENSE.txt"} dependencies = [ "pypdf>=5.3.0", "lxml", - "saxonche", ] requires-python = ">=3.9" dynamic = ["version"] [project.optional-dependencies] +schematron = ["saxonche"] test = [ + "saxonche", "pytest", "coverage[toml]", ] diff --git a/src/facturx/facturx.py b/src/facturx/facturx.py index c69809e..d6002b3 100644 --- a/src/facturx/facturx.py +++ b/src/facturx/facturx.py @@ -32,7 +32,10 @@ from io import BytesIO, IOBase from tempfile import NamedTemporaryFile -import saxonche +try: + import saxonche +except ImportError: + saxonche = None from lxml import etree from pypdf import PdfReader, PdfWriter from pypdf.generic import ( @@ -242,6 +245,9 @@ def xml_check_schematron(xml, flavor="autodetect", level="autodetect"): :return: True if the XML is valid against the schematron raise an error if it is not valid against the schematron """ + if not saxonche: + logger.info("Missing saxonche module, schematron validation skipped") + return True logger.debug("xml_check_schematron with factur-x lib %s", VERSION) if not isinstance(flavor, str): raise ValueError("Wrong type for flavor argument")