imas-python 0.1.dev1628__py3-none-any.whl → 0.1.dev1630__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of imas-python might be problematic. Click here for more details.

imas/__init__.py CHANGED
@@ -25,10 +25,7 @@ from . import (
25
25
  util,
26
26
  )
27
27
 
28
- PUBLISHED_DOCUMENTATION_ROOT = (
29
- "https://sharepoint.iter.org/departments/POP/CM/IMDesign/"
30
- "Code%20Documentation/imas-python-doc"
31
- )
28
+ PUBLISHED_DOCUMENTATION_ROOT = "https://imas-python.readthedocs.io/en/latest/"
32
29
  """URL to the published documentation."""
33
30
  OLDEST_SUPPORTED_VERSION = _V("3.22.0")
34
31
  """Oldest Data Dictionary version that is supported by imas-python."""
imas/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.1.dev1628'
16
- __version_tuple__ = version_tuple = (0, 1, 'dev1628')
15
+ __version__ = version = '0.1.dev1630'
16
+ __version_tuple__ = version_tuple = (0, 1, 'dev1630')
imas/assets/IDSDef.zip CHANGED
Binary file
imas/dd_helpers.py CHANGED
@@ -4,35 +4,30 @@
4
4
 
5
5
  import logging
6
6
  import os
7
- import re
8
7
  import shutil
9
- import subprocess
10
- from io import BytesIO
11
8
  from pathlib import Path
12
- from typing import Sequence, Tuple, Union
13
- from urllib.request import urlopen
9
+ from typing import Tuple
14
10
  from zipfile import ZIP_DEFLATED, ZipFile
15
11
 
16
12
  from packaging.version import Version as V
13
+ from saxonche import PySaxonProcessor
17
14
 
18
15
  logger = logging.getLogger(__name__)
19
16
 
20
17
  _idsdef_zip_relpath = Path("imas/assets/IDSDef.zip")
21
18
  _build_dir = Path("build")
22
- _saxon_local_default_name = "saxon9he.jar" # For pre-3.30.0 builds
23
- _saxon_regex = "saxon((.(?!test|xqj))*).jar" # Can be used in re.match
24
19
 
25
20
 
26
21
  def prepare_data_dictionaries():
27
22
  """Build IMAS IDSDef.xml files for each tagged version in the DD repository
28
- 1. Search for saxon or download it
23
+ 1. Use saxonche for transformations
29
24
  2. Clone the DD repository (ask for user/pass unless ssh key access is available)
30
25
  3. Generate IDSDef.xml and rename to IDSDef_${version}.xml
31
26
  4. Zip all these IDSDefs together and include in wheel
32
27
  """
28
+ print("prepare_data_dictionaries")
33
29
  from git import Repo
34
30
 
35
- saxon_jar_path = get_saxon()
36
31
  repo: Repo = get_data_dictionary_repo()
37
32
  if repo:
38
33
  newest_version_and_tag = (V("0"), None)
@@ -41,7 +36,7 @@ def prepare_data_dictionaries():
41
36
  if V(str(tag)) > V("3.21.1"):
42
37
  newest_version_and_tag = max(newest_version_and_tag, version_and_tag)
43
38
  logger.debug("Building data dictionary version %s", tag)
44
- build_data_dictionary(repo, tag, saxon_jar_path)
39
+ build_data_dictionary(repo, tag)
45
40
 
46
41
  logger.info("Creating zip file of DD versions")
47
42
 
@@ -68,105 +63,6 @@ def prepare_data_dictionaries():
68
63
  dd_zip.write(filename, arcname=arcname)
69
64
 
70
65
 
71
- # pre 3.30.0 versions of the DD have the `saxon9he.jar` file path hardcoded
72
- # in their makefiles. To be sure we can build everything, we link whatever
73
- # saxon we can find to a local file called saxon9he.jar
74
- def get_saxon() -> Path:
75
- """Search for saxon*.jar and return the path or download it.
76
- The DD build works by having Saxon in the CLASSPATH, called saxon9he.jar
77
- until DD version 3.30.0. After 3.30.0 Saxon is found by the SAXONJARFILE env
78
- variable. We will 'cheat' a little bit later by symlinking saxon9he.jar to
79
- any version of saxon we found.
80
-
81
- Check:
82
- 1. CLASSPATH
83
- 2. `which saxon`
84
- 3. /usr/share/java/*
85
- 4. or download it
86
- """
87
-
88
- local_saxon_path = Path.cwd() / _saxon_local_default_name
89
- if local_saxon_path.exists():
90
- logger.debug("Something already at '%s' not creating anew", local_saxon_path)
91
- return local_saxon_path
92
-
93
- saxon_jar_origin = Path(
94
- find_saxon_classpath()
95
- or find_saxon_bin()
96
- or find_saxon_jar()
97
- or download_saxon()
98
- )
99
- logger.info("Found Saxon JAR '%s'", saxon_jar_origin)
100
- if saxon_jar_origin.name != _saxon_local_default_name:
101
- try:
102
- os.symlink(saxon_jar_origin, local_saxon_path)
103
- except FileExistsError:
104
- # Another process could have created the symlink while we were searching
105
- logger.debug(
106
- "Link '%s' exists, parallel process might've created it",
107
- local_saxon_path,
108
- )
109
- return local_saxon_path
110
- return saxon_jar_origin
111
-
112
-
113
- def find_saxon_jar():
114
- # This finds multiple versions on my system, but they are symlinked together.
115
- # take the shortest one.
116
- jars = [
117
- path
118
- for path in Path("/usr/share/java").rglob("*")
119
- if re.match(_saxon_regex, path.name, flags=re.IGNORECASE)
120
- ]
121
-
122
- if jars:
123
- saxon_jar_path = min(jars, key=lambda x: len(x.parts))
124
- return saxon_jar_path
125
-
126
-
127
- def find_saxon_classpath():
128
- """Search JAVAs CLASSPATH for a Saxon .jar"""
129
- classpath = os.environ.get("CLASSPATH", "")
130
- for part in re.split(";|:", classpath):
131
- if (
132
- part.endswith(".jar")
133
- and part.split("/")[-1].startswith("saxon")
134
- and "test" not in part
135
- and "xqj" not in part
136
- ):
137
- return part
138
-
139
-
140
- def find_saxon_bin():
141
- """Search for a saxon executable"""
142
- saxon_bin = shutil.which("saxon")
143
- if saxon_bin:
144
- with open(saxon_bin, "r") as file:
145
- for line in file:
146
- saxon_jar_path = re.search("[^ ]*saxon[^ ]*jar", line)
147
- if saxon_jar_path:
148
- return saxon_jar_path.group(0)
149
-
150
-
151
- def download_saxon():
152
- """Downloads a zipfile containing Saxon and extract it to the current dir.
153
- Return the full path to Saxon. This can be any Saxon version. Scripts that
154
- wrap this should probably manipulate either the name of this file, and/or
155
- the CLASSPATH"""
156
-
157
- SAXON_PATH = "https://github.com/Saxonica/Saxon-HE/releases/download/SaxonHE10-9/SaxonHE10-9J.zip" # noqa: E501
158
-
159
- resp = urlopen(SAXON_PATH, timeout=120.0)
160
- zipfile = ZipFile(BytesIO(resp.read()))
161
- # Zipfile has a list of the ZipInfos. Look inside for a Saxon jar
162
- for file in zipfile.filelist:
163
- if re.match(_saxon_regex, file.filename, flags=re.IGNORECASE):
164
- path = zipfile.extract(file)
165
- del zipfile
166
- return path
167
- raise FileNotFoundError(f"No Saxon jar found in given zipfile '{SAXON_PATH}'")
168
-
169
-
170
66
  def get_data_dictionary_repo() -> Tuple[bool, bool]:
171
67
  try:
172
68
  import git # Import git here, the user might not have it!
@@ -216,47 +112,33 @@ def get_data_dictionary_repo() -> Tuple[bool, bool]:
216
112
  return repo
217
113
 
218
114
 
219
- def _run_data_dictionary(
220
- args: Union[Sequence, str], tag: str, saxon_jar_path: str
221
- ) -> int:
222
- """Run in a Data Dictionary environment. Used e.g. to run the DD Makefile
115
+ def _run_xsl_transformation(
116
+ xsd_file: Path, xsl_file: Path, tag: str, output_file: Path
117
+ ) -> None:
118
+ """
119
+ This function performs an XSL transformation using Saxon-HE (saxonche)
120
+ with the provided XSD file, XSL file, tag, and output file.
223
121
 
224
122
  Args:
225
- args: The "args" argument directly passed to :func:`subprocess.run`,
226
- e.g. ``["make", "clean"]``
227
- tag: The DD version tag that will be printed on error
228
- saxon_jar_path: The path to the saxon jar; Added to CLASSPATH and used
229
- to generate the DD
123
+ xsd_file (Path): XML Schema Definition (XSD) file
124
+ xsl_file (Path): The `xsl_file` parameter
125
+ tag (str): tag name to provide to 'DD_GIT_DESCRIBE' parameter
126
+ output_file (Path): The `output_file` parameter for resulting xml
230
127
  """
231
- env = os.environ.copy()
232
- env["CLASSPATH"] = f"{saxon_jar_path}:{env.get('CLASSPATH', '')}"
233
- result = subprocess.run(
234
- args,
235
- bufsize=0,
236
- capture_output=True,
237
- cwd=os.getcwd() + "/data-dictionary",
238
- env=env,
239
- text=True,
240
- )
241
-
242
- if result.returncode != 0:
243
- logger.warning("Error making DD version %s, make reported:", tag)
244
- logger.warning("CLASSPATH ='%s'", saxon_jar_path)
245
- logger.warning("PATH = '%s'", os.environ.get("PATH", ""))
246
- logger.warning("stdout = '%s'", result.stdout.strip())
247
- logger.warning("stderr = '%s'", result.stderr.strip())
248
- logger.warning("continuing without DD version %s", tag)
249
- else:
250
- logger.debug(
251
- "Successful make for DD %s.\n-- Make stdout --\n%s\n-- Make stderr --\n%s",
252
- tag,
253
- result.stdout,
254
- result.stderr,
128
+ with PySaxonProcessor(license=False) as proc:
129
+ logger.debug("Initializing Saxon Processor")
130
+ xsltproc = proc.new_xslt30_processor()
131
+ xdm_ddgit = proc.make_string_value(tag)
132
+ xsltproc.set_parameter("DD_GIT_DESCRIBE", xdm_ddgit)
133
+ xsltproc.transform_to_file(
134
+ source_file=str(xsd_file),
135
+ stylesheet_file=str(xsl_file),
136
+ output_file=str(output_file),
255
137
  )
256
- return result.returncode
138
+ logger.info("Transformation complete: %s -> %s", xsd_file, output_file)
257
139
 
258
140
 
259
- def build_data_dictionary(repo, tag: str, saxon_jar_path: str, rebuild=False) -> None:
141
+ def build_data_dictionary(repo, tag: str, rebuild=False) -> None:
260
142
  """Build a single version of the data dictionary given by the tag argument
261
143
  if the IDS does not already exist.
262
144
 
@@ -266,8 +148,6 @@ def build_data_dictionary(repo, tag: str, saxon_jar_path: str, rebuild=False) ->
266
148
  Args:
267
149
  repo: Repository object containing the DD source code
268
150
  tag: The DD version tag that will be build
269
- saxon_jar_path: The path to the saxon jar; Added to CLASSPATH and used
270
- to generate the DD
271
151
  rebuild: If true, overwrites existing pre-build tagged DD version
272
152
  """
273
153
  _build_dir.mkdir(exist_ok=True)
@@ -278,22 +158,11 @@ def build_data_dictionary(repo, tag: str, saxon_jar_path: str, rebuild=False) ->
278
158
  return
279
159
 
280
160
  repo.git.checkout(tag, force=True)
281
- if _run_data_dictionary(["make", "clean"], tag, saxon_jar_path) != 0:
282
- return
283
- if _run_data_dictionary(["make", "IDSDef.xml"], tag, saxon_jar_path) != 0:
284
- return
285
161
 
286
- # copy and delete original instead of move (to follow symlink)
287
- IDSDef = Path("data-dictionary/IDSDef.xml")
288
- try:
289
- shutil.copy(
290
- IDSDef, # Hardcoded in access-layer makefile
291
- result_xml,
292
- follow_symlinks=True,
293
- )
294
- except shutil.SameFileError:
295
- pass
296
- IDSDef.unlink(missing_ok=True)
162
+ # Perform the XSL transformation with saxonche
163
+ dd_xsd = Path("data-dictionary/dd_data_dictionary.xml.xsd")
164
+ dd_xsl = Path("data-dictionary/dd_data_dictionary.xml.xsl")
165
+ _run_xsl_transformation(dd_xsd, dd_xsl, tag.name, result_xml)
297
166
 
298
167
 
299
168
  if __name__ == "__main__":
imas/ids_structure.py CHANGED
@@ -252,8 +252,8 @@ class IDSStructure(IDSBase):
252
252
  "Iterating over non-empty nodes of a lazy loaded IDS will skip nodes "
253
253
  "that are not loaded. Set accept_lazy=True to continue. "
254
254
  "See the documentation for more information: "
255
- "https://sharepoint.iter.org/departments/POP/CM/IMDesign/"
256
- "Code%20Documentation/imas-python-doc/generated/imas.ids_structure."
255
+ "https://imas-python.readthedocs.io/en/latest"
256
+ "/generated/imas.ids_structure."
257
257
  "IDSStructure.html#imas.ids_structure.IDSStructure.iter_nonempty_"
258
258
  )
259
259
  for child in self._children:
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: imas-python
3
- Version: 0.1.dev1628
3
+ Version: 0.1.dev1630
4
4
  Summary: Pythonic wrappers for the IMAS Access Layer
5
- Author: imas-python Developers
5
+ Author: imas-python developers
6
6
  Author-email: Olivier Hoenen <olivier.hoenen@iter.org>
7
7
  License: GNU LESSER GENERAL PUBLIC LICENSE
8
8
  Version 3, 29 June 2007
@@ -212,6 +212,8 @@ Requires-Dist: click
212
212
  Requires-Dist: importlib_resources; python_version < "3.9"
213
213
  Requires-Dist: packaging
214
214
  Requires-Dist: xxhash>=2
215
+ Requires-Dist: saxonche
216
+ Requires-Dist: gitpython
215
217
  Provides-Extra: all
216
218
  Requires-Dist: imas[docs,h5py,imas-core,netcdf,test]; extra == "all"
217
219
  Provides-Extra: docs
@@ -247,7 +249,7 @@ Data Model.
247
249
  Install steps are described in the documentation generated from `/docs/source/installing.rst`.
248
250
 
249
251
  Documentation is autogenerated from the source using [Sphinx](http://sphinx-doc.org/)
250
- and can be found at the [ITER sharepoint](https://sharepoint.iter.org/departments/POP/CM/IMDesign/Code%20Documentation/IMAS-doc/index.html)
252
+ and can be found at the [readthedocs](https://imas-python.readthedocs.io/en/latest/)
251
253
 
252
254
  The documentation can be manually generated by installing sphinx and running:
253
255
 
@@ -1,9 +1,9 @@
1
- imas/__init__.py,sha256=TcIsTA05yiteecXpGnhm0fKw_cEHIc4TJUHC1iP5fJo,940
1
+ imas/__init__.py,sha256=9OHpTf8gCl7BJVU7U2bf9kWatBNNAhFZdgoFPcHeNQU,878
2
2
  imas/__main__.py,sha256=2qXoC0HzV4xkPQAvdubHC4rnK3G6f_2PT9TkkCHYXk8,418
3
3
  imas/_util.py,sha256=FXX13glhmgSiw-0LtjH0xv3YlM3Pa9X4jl9yz9Uv7Vs,9484
4
- imas/_version.py,sha256=37tfNBIVZOWgN0uOLXfG18OnUZiyzRJUR_f3wVBwCA8,425
4
+ imas/_version.py,sha256=OpP0F45Ue1X9KS-OpxRWnRU3SYVrRth3FtH_kqSiU4Q,425
5
5
  imas/db_entry.py,sha256=O76bfCfmH3jlZE8eJmnmPiDNqZYpwo3ooQeHOL83mE4,31767
6
- imas/dd_helpers.py,sha256=c1uvR7TvFvOLGUhj1h0PtPMm69CGBjtWrv2AC8FvU2I,10844
6
+ imas/dd_helpers.py,sha256=tKPbnje62PGNGTclpC_VKg9b-mZWy9VvkICqwzkdiGA,6314
7
7
  imas/dd_zip.py,sha256=Sz2xP-oWyhmmqEN-JGGNizieGZH8CJ6JlCjqN_0fMvw,10330
8
8
  imas/exception.py,sha256=iqsxl6M1gEjJO8YP9UBYt5OQk7faGx0EIs1XJ4YJ71U,3750
9
9
  imas/ids_base.py,sha256=zDckve7poXO9vbKPsi_17FjKMTKd6QADork7H7wIS7o,5439
@@ -17,12 +17,12 @@ imas/ids_metadata.py,sha256=kpyNKXB9-aQpjdj1df10qKZIJ7-HC5BuDOhGyhX9YMI,12258
17
17
  imas/ids_path.py,sha256=rqucboH8wO4-njy8d6lUffnfHA6L2b81wh8AJ6Y_gbU,10446
18
18
  imas/ids_primitive.py,sha256=3s0y0nxPSXjAoXEYUvsmevWOqmfCBnct-ySr_f2oU9k,16810
19
19
  imas/ids_struct_array.py,sha256=BFBa1wSZFAlZguExCTA56D8RfnaLv-nbxDIz9fMhcGE,8292
20
- imas/ids_structure.py,sha256=IqfPxjAJtDE0aM0sdyEfbvHiD3yIenX7eMsoACi--L4,13155
20
+ imas/ids_structure.py,sha256=0DRudIturYE2Aw_Jb22zBZCd_zyA0-lg8YOEI7Y_iso,13107
21
21
  imas/ids_toplevel.py,sha256=YHWZewK8JYf34pYzF_oooMILZAHgnuWCFtr0_JFjmzI,14915
22
22
  imas/setup_logging.py,sha256=auFmrFHh1CA6LVQVwo6WWebUIbCpA_7UedQ6G4h5JzM,1874
23
23
  imas/training.py,sha256=JGYjpCubUJDb_Rg0QaaDhNkBHc4Qc376U9fRq24NVXc,1576
24
24
  imas/util.py,sha256=dG282-l7m2U_VhjZ0VnQ-BpsWrzgKSxUZ1AZf-_wDOY,17822
25
- imas/assets/IDSDef.zip,sha256=iThF2_DSZXg18tv1elvtA9Maa4toX6vyytrm5bLaleE,27383258
25
+ imas/assets/IDSDef.zip,sha256=P--G2iMe4FYakrJC9PS_Hsc4JR8CK8S9zsdwKuWF_ZI,27383258
26
26
  imas/assets/IDSDef2MDSpreTree.xsl,sha256=V9eDmDnxe6oYhDP81gmdYip8cF2yST9dGxmZBaATLdA,7296
27
27
  imas/assets/IDS_fake_toplevel.xml,sha256=TJhukQuDHHVTW2U7fK_-KmTQiYOFZMY-ECZXBHQE2mk,18683
28
28
  imas/assets/IDS_minimal.xml,sha256=5B6c0J-WPzSChHWwpLPRkNawx9m6v8BM5nC0OQFnWcQ,1740
@@ -101,9 +101,9 @@ imas/test/test_str_1d.py,sha256=d6GrmV4OYG9f4ludjZBmuqyKOM9XIExTqMh8aQ1UJcQ,3453
101
101
  imas/test/test_time_slicing.py,sha256=FwbdggRJ75Suc268-89daCSaVXhzl8pZZm3Od13EiR4,6959
102
102
  imas/test/test_uda_support.py,sha256=AmakuexebZfJ2-vk_DHfNRPwHmNM2RnwzXqT0eWwWJ0,338
103
103
  imas/test/test_util.py,sha256=BW5EbL-QDIrJNH7tjBgqOacJY0TXvMidXVKpIVZlv1I,6775
104
- imas_python-0.1.dev1628.dist-info/LICENSE.txt,sha256=RzxtV7MG0zbF6dDvQsaZ1OKsHZ7CRyeILenjUIol5rs,7651
105
- imas_python-0.1.dev1628.dist-info/METADATA,sha256=o0xC-_YVQcYLN0m7_BgfyqUbtV_wbApliHE-c3Ftt9Q,13452
106
- imas_python-0.1.dev1628.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
107
- imas_python-0.1.dev1628.dist-info/entry_points.txt,sha256=e8oXj2SLwyFEiBeJRaAXRc9EYQ8eHWWn7NWdjixjeDM,99
108
- imas_python-0.1.dev1628.dist-info/top_level.txt,sha256=_WFOlA1rmpYm0T73sNo5Ntvs7S3x4cR7UE8Oy5I5eJA,5
109
- imas_python-0.1.dev1628.dist-info/RECORD,,
104
+ imas_python-0.1.dev1630.dist-info/LICENSE.txt,sha256=RzxtV7MG0zbF6dDvQsaZ1OKsHZ7CRyeILenjUIol5rs,7651
105
+ imas_python-0.1.dev1630.dist-info/METADATA,sha256=lR2NVbzINbR2-FqVrbHjeDerYMDVCS9oayI-4Dg9jAM,13446
106
+ imas_python-0.1.dev1630.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
107
+ imas_python-0.1.dev1630.dist-info/entry_points.txt,sha256=e8oXj2SLwyFEiBeJRaAXRc9EYQ8eHWWn7NWdjixjeDM,99
108
+ imas_python-0.1.dev1630.dist-info/top_level.txt,sha256=_WFOlA1rmpYm0T73sNo5Ntvs7S3x4cR7UE8Oy5I5eJA,5
109
+ imas_python-0.1.dev1630.dist-info/RECORD,,