Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion doclang/schematron_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from typing import Union

from lxml import etree
from saxonche import PySaxonProcessor

from doclang._schemas import _bundled_sch_path
from doclang.utils import _ensure_namespace
Expand Down Expand Up @@ -117,6 +116,13 @@ def _transpile_schematron_to_xslt(sch_file, verbose=False):
if verbose:
print(f"Transpiling Schematron: {sch_file}")

try:
from saxonche import PySaxonProcessor
except ImportError:
raise ImportError(
"saxonche is required for Schematron validation. Install it with: pip install doclang[schematron]"
) from None

with PySaxonProcessor(license=False) as proc:
xslt_proc = proc.new_xslt30_processor()

Expand Down Expand Up @@ -162,6 +168,13 @@ def _validate_with_schematron(
tmp_xml_path = tmp.name

# File is still open but flushed, Saxon can read it
try:
from saxonche import PySaxonProcessor
except ImportError:
raise ImportError(
"saxonche is required for Schematron validation. Install it with: pip install doclang[schematron]"
) from None

with PySaxonProcessor(license=False) as proc:
if verbose:
print(f"Using XSLT processor version: {proc.version}")
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ classifiers = [
]
dependencies = [
"lxml>=6.0.2",
"saxonche>=12.9.0",
"typer>=0.15.1",
]

[project.optional-dependencies]
schematron = ["saxonche>=12.9.0"]

[project.urls]
Homepage = "https://www.doclang.ai/"
Documentation = "https://github.com/doclang-project/doclang/blob/main/README.md"
Expand Down
9 changes: 7 additions & 2 deletions uv.lock

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

Loading