Skip to content

Commit ae9af2a

Browse files
committed
Merge branch 'develop' of https://github.com/iterorganization/imas-python into feature/lazy-load-from-netcdf
2 parents a110d69 + a8a86d4 commit ae9af2a

File tree

5 files changed

+47
-43
lines changed

5 files changed

+47
-43
lines changed

.github/workflows/linting.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: push
55
jobs:
66
build:
77

8-
runs-on: ubuntu-latest
8+
runs-on: ubuntu-22.04
99

1010
steps:
1111
- name: Checkout IMAS-Python sources
@@ -14,7 +14,9 @@ jobs:
1414
- name: Set up Python
1515
uses: actions/setup-python@v5
1616
with:
17-
python-version: '3.x'
17+
# until saxonche is available in 3.13
18+
# https://saxonica.plan.io/issues/6561
19+
python-version: "<3.13"
1820

1921
- name: Display Python version
2022
run: python -c "import sys; print(sys.version)"

.github/workflows/publish.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ on: push
55
jobs:
66
build:
77
name: Build distribution
8-
runs-on: ubuntu-latest
8+
runs-on: ubuntu-22.04
99
steps:
1010
- uses: actions/checkout@v4
1111
with:
1212
fetch-depth: 0
1313
- name: Set up Python
1414
uses: actions/setup-python@v5
1515
with:
16-
python-version: "3.x"
16+
# until saxonche is available in 3.13
17+
# https://saxonica.plan.io/issues/6561
18+
python-version: "<3.13"
1719
- name: Install pypa/build
1820
run: >-
1921
python3 -m pip install pip setuptools wheel build
@@ -30,7 +32,7 @@ jobs:
3032
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
3133
needs:
3234
- build
33-
runs-on: ubuntu-latest
35+
runs-on: ubuntu-22.04
3436
environment:
3537
name: pypi
3638
url: https://pypi.org/p/imas-python
@@ -50,7 +52,7 @@ jobs:
5052
if: github.ref=='refs/heads/develop' # only publish to TestPyPI on develop pushes
5153
needs:
5254
- build
53-
runs-on: ubuntu-latest
55+
runs-on: ubuntu-22.04
5456
environment:
5557
name: testpypi
5658
url: https://test.pypi.org/p/imas-python

ci/run_pytest.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ source /etc/profile.d/modules.sh
1313
module purge
1414
# Modules are supplied as arguments in the CI job:
1515
if [ -z "$@" ]; then
16-
module load IMAS-AL-Core
16+
module load IMAS-AL-Core Java MDSplus
1717
else
1818
module load $@
1919
fi

imas/backends/imas_core/mdsplus_model.py

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Helper functions to create MDSPlus reference models
22
# and store them in a cache directory (.cache/imas/MDSPlus/name-HASH/)
3-
"""Module for generating and working with MDSplus models.
4-
"""
3+
"""Module for generating and working with MDSplus models."""
54

65
import errno
76
import getpass
@@ -235,6 +234,14 @@ def model_exists(path: Path) -> bool:
235234
)
236235

237236

237+
def transform_with_xslt(xslt_processor, source, xslfile, output_file):
238+
return xslt_processor.transform_to_file(
239+
source_file=str(source),
240+
stylesheet_file=str(xslfile),
241+
output_file=str(output_file),
242+
)
243+
244+
238245
def create_model_ids_xml(cache_dir_path, fname, version):
239246
"""Use Saxon/C to compile an ids.xml suitable for creating an MDSplus model."""
240247
try:
@@ -243,40 +250,32 @@ def create_model_ids_xml(cache_dir_path, fname, version):
243250

244251
with PySaxonProcessor(license=False) as proc:
245252
xslt_processor = proc.new_xslt30_processor()
246-
247-
xslt_processor.compile_stylesheet(stylesheet_file=str(xslfile))
248-
249-
input_xml = get_dd_xml(version) if version else None
250-
if fname:
251-
source_file = str(fname)
252-
elif input_xml:
253-
source_file = input_xml # Use standard input for the XML string
254-
else:
255-
raise ValueError(
256-
"Either 'fname' or 'version' must be provided to generate XML."
257-
)
258-
259-
# xdm_ddgit = proc.make_string_value(str(version or fname))
260-
# xsltproc.set_parameter("DD_GIT_DESCRIBE", xdm_ddgit)
261-
# xdm_algit = proc.make_string_value(os.environ.get
262-
# ("AL_VERSION", "0.0.0"))
263-
# xsltproc.set_parameter("AL_GIT_DESCRIBE", xdm_algit)
264-
# Transform XML
265-
result = xslt_processor.transform_to_file(
266-
source_file=source_file,
267-
output_file=str(output_file),
268-
initial_template_params={
269-
"DD_GIT_DESCRIBE": str(version or fname),
270-
"AL_GIT_DESCRIBE": os.environ.get("AL_VERSION", "0.0.0"),
271-
},
253+
xdm_ddgit = proc.make_string_value(str(version) or fname)
254+
xslt_processor.set_parameter("DD_GIT_DESCRIBE", xdm_ddgit)
255+
xdm_algit = proc.make_string_value(
256+
os.environ.get("AL_VERSION", "0.0.0")
272257
)
273-
274-
if result is False:
275-
logger.error(
276-
"Transformation failed: Check Saxon/C logs for details."
277-
)
278-
raise RuntimeError("Saxon/C XSLT transformation failed.")
279-
258+
xslt_processor.set_parameter("AL_GIT_DESCRIBE", xdm_algit)
259+
if (
260+
fname is not None
261+
and fname != "-"
262+
and fname != ""
263+
and os.path.exists(fname)
264+
):
265+
transform_with_xslt(xslt_processor, fname, xslfile, output_file)
266+
elif version is not None and version != "":
267+
xml_string = get_dd_xml(version)
268+
269+
with tempfile.NamedTemporaryFile(
270+
delete=True, mode="w+b"
271+
) as temp_file:
272+
temp_file.write(xml_string)
273+
temp_file.seek(0)
274+
transform_with_xslt(
275+
xslt_processor, temp_file.name, xslfile, output_file
276+
)
277+
else:
278+
raise MDSPlusModelError("Either fname or version must be provided")
280279
except Exception as e:
281280
if fname:
282281
logger.error("Error making MDSplus model IDS.xml for %s", fname)

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ dependencies = [
7171
[project.optional-dependencies]
7272
# these self-dependencies are available since pip 21.2
7373
all = [
74-
"imas[test,docs,imas-core,netcdf,h5py]"
74+
"imas-python[test,docs,netcdf,h5py]"
75+
# "imas-python[test,docs,imas-core,netcdf,h5py]" TODO enable when imas-core is available on pypi
7576
]
7677
docs = [
7778
"sphinx>=6.0.0,<7.0.0",

0 commit comments

Comments
 (0)