diff --git a/imas/backends/imas_core/mdsplus_model.py b/imas/backends/imas_core/mdsplus_model.py index 48864346..3c91cefb 100644 --- a/imas/backends/imas_core/mdsplus_model.py +++ b/imas/backends/imas_core/mdsplus_model.py @@ -12,7 +12,6 @@ import time import uuid from pathlib import Path -from saxonche import PySaxonProcessor from subprocess import CalledProcessError, check_output from zlib import crc32 @@ -244,11 +243,20 @@ def transform_with_xslt(xslt_processor, source, xslfile, output_file): def create_model_ids_xml(cache_dir_path, fname, version): """Use Saxon/C to compile an ids.xml suitable for creating an MDSplus model.""" + try: + import saxonche + except ImportError: + raise RuntimeError( + "Building mdsplus models requires the 'saxonche' python package. " + "Please install this package (for example with 'pip install saxonche') " + "and try again." + ) + try: with as_file(files("imas") / "assets" / "IDSDef2MDSpreTree.xsl") as xslfile: output_file = Path(cache_dir_path) / "ids.xml" - with PySaxonProcessor(license=False) as proc: + with saxonche.PySaxonProcessor(license=False) as proc: xslt_processor = proc.new_xslt30_processor() xdm_ddgit = proc.make_string_value(str(version) or fname) xslt_processor.set_parameter("DD_GIT_DESCRIBE", xdm_ddgit) diff --git a/pyproject.toml b/pyproject.toml index 6134366c..066e0ea9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [build-system] # Minimum requirements for the build system to execute. # Keep this on a single line for the grep magic of build scripts to work -requires = ["setuptools>=61", "wheel", "numpy", "gitpython", "saxonche","packaging", "tomli;python_version<'3.11'", "setuptools_scm>8"] +requires = ["setuptools>=61", "wheel", "numpy", "packaging", "tomli;python_version<'3.11'", "setuptools_scm>8"] build-backend = "setuptools.build_meta" @@ -63,8 +63,6 @@ dependencies = [ "importlib_resources;python_version<'3.9'", "packaging", "xxhash >= 2", - "saxonche", - "gitpython", "imas_data_dictionaries", ] @@ -92,6 +90,9 @@ h5py = [ xarray = [ "xarray", ] +saxonche = [ + "saxonche", +] test = [ "pytest>=5.4.1", "pytest-cov>=0.6", @@ -101,11 +102,11 @@ test = [ "asv == 0.6.1", # virtualenv is a dependency of asv "virtualenv", - # Pint and xarray are used in training snippets + # Pint is used in training snippets "pint", # Optional dependencies # TODO add imas-core when it is available on pypi - "imas-python[netcdf,h5py,xarray]", + "imas-python[netcdf,h5py,xarray,saxonche]", ] [project.scripts]