Skip to content

Commit 0252511

Browse files
maarten-icolivhoenen
authored andcommitted
Make saxonche an optional dependency
1 parent 1d92974 commit 0252511

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

imas/backends/imas_core/mdsplus_model.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import time
1313
import uuid
1414
from pathlib import Path
15-
from saxonche import PySaxonProcessor
1615
from subprocess import CalledProcessError, check_output
1716
from zlib import crc32
1817

@@ -244,11 +243,20 @@ def transform_with_xslt(xslt_processor, source, xslfile, output_file):
244243

245244
def create_model_ids_xml(cache_dir_path, fname, version):
246245
"""Use Saxon/C to compile an ids.xml suitable for creating an MDSplus model."""
246+
try:
247+
import saxonche
248+
except ImportError:
249+
raise RuntimeError(
250+
"Building mdsplus models requires the 'saxonche' python package. "
251+
"Please install this package (for example with 'pip install saxonche') "
252+
"and try again."
253+
)
254+
247255
try:
248256
with as_file(files("imas") / "assets" / "IDSDef2MDSpreTree.xsl") as xslfile:
249257
output_file = Path(cache_dir_path) / "ids.xml"
250258

251-
with PySaxonProcessor(license=False) as proc:
259+
with saxonche.PySaxonProcessor(license=False) as proc:
252260
xslt_processor = proc.new_xslt30_processor()
253261
xdm_ddgit = proc.make_string_value(str(version) or fname)
254262
xslt_processor.set_parameter("DD_GIT_DESCRIBE", xdm_ddgit)

pyproject.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[build-system]
22
# Minimum requirements for the build system to execute.
33
# Keep this on a single line for the grep magic of build scripts to work
4-
requires = ["setuptools>=61", "wheel", "numpy", "gitpython", "saxonche","packaging", "tomli;python_version<'3.11'", "setuptools_scm>8"]
4+
requires = ["setuptools>=61", "wheel", "numpy", "packaging", "tomli;python_version<'3.11'", "setuptools_scm>8"]
55

66
build-backend = "setuptools.build_meta"
77

@@ -63,8 +63,6 @@ dependencies = [
6363
"importlib_resources;python_version<'3.9'",
6464
"packaging",
6565
"xxhash >= 2",
66-
"saxonche",
67-
"gitpython",
6866
"imas_data_dictionaries",
6967
]
7068

@@ -92,6 +90,9 @@ h5py = [
9290
xarray = [
9391
"xarray",
9492
]
93+
saxonche = [
94+
"saxonche",
95+
]
9596
test = [
9697
"pytest>=5.4.1",
9798
"pytest-cov>=0.6",
@@ -101,11 +102,11 @@ test = [
101102
"asv == 0.6.1",
102103
# virtualenv is a dependency of asv
103104
"virtualenv",
104-
# Pint and xarray are used in training snippets
105+
# Pint is used in training snippets
105106
"pint",
106107
# Optional dependencies
107108
# TODO add imas-core when it is available on pypi
108-
"imas-python[netcdf,h5py,xarray]",
109+
"imas-python[netcdf,h5py,xarray,saxonche]",
109110
]
110111

111112
[project.scripts]

0 commit comments

Comments
 (0)