Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.

Commit dd9be10

Browse files
authored
Merge pull request #1036 from ess-dmsc/ECDC-3518-only-partial-depends-on-support
ECDC-3518-only-partial-depends-on-support
2 parents 7c37604 + cfa3747 commit dd9be10

File tree

8 files changed

+192
-134
lines changed

8 files changed

+192
-134
lines changed

nexus_constructor/json/json_warnings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class TransformDependencyMissing:
2929
message: str = attr.ib()
3030

3131

32+
@attr.s
33+
class RelativeDependsonWrong:
34+
message = attr.ib(type=str)
35+
36+
3237
@attr.s
3338
class NameFieldMissing:
3439
message: str = attr.ib()
@@ -44,6 +49,7 @@ class NXClassAttributeMissing:
4449
InvalidShape,
4550
InvalidTransformation,
4651
TransformDependencyMissing,
52+
RelativeDependsonWrong,
4753
NameFieldMissing,
4854
NXClassAttributeMissing,
4955
]

nexus_constructor/json/load_from_json.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
NameFieldMissing,
2424
NXClassAttributeMissing,
2525
TransformDependencyMissing,
26+
RelativeDependsonWrong,
2627
)
2728
from nexus_constructor.json.load_from_json_utils import (
2829
DEPENDS_ON_IGNORE,
@@ -113,8 +114,19 @@ def _set_components_depends_on(self):
113114
except KeyError:
114115
self.warnings.append(
115116
TransformDependencyMissing(
116-
f"Component {component_name} depends on {depends_on_id.transform_name} in component "
117-
f"{depends_on_id.component_name}, but that transform was not successfully loaded from the JSON"
117+
f"Component {component_name} depends on "
118+
+ (
119+
depends_on_id.transform_name
120+
if depends_on_id is not None
121+
else "Unknown"
122+
)
123+
+ " in component "
124+
+ (
125+
depends_on_id.component_name
126+
if depends_on_id is not None
127+
else "Unknown"
128+
)
129+
+ ", but that transform was not successfully loaded from the JSON"
118130
)
119131
)
120132

@@ -138,9 +150,19 @@ def _set_transforms_depends_on(self):
138150
except KeyError:
139151
self.warnings.append(
140152
TransformDependencyMissing(
141-
f"Transformation {transform_id.transform_name} in component {transform_id.component_name} "
142-
f"depends on {depends_on_id.transform_name} in component {depends_on_id.component_name}, "
143-
f"but that transform was not successfully loaded from the JSON"
153+
f"Transformation {transform_id.transform_name} in component {transform_id.component_name} depends on "
154+
+ (
155+
depends_on_id.transform_name
156+
if depends_on_id is not None
157+
else "Unknown"
158+
)
159+
+ " in component "
160+
+ (
161+
depends_on_id.component_name
162+
if depends_on_id is not None
163+
else "Unknown"
164+
)
165+
+ ", but that transform was not successfully loaded from the JSON"
144166
)
145167
)
146168

@@ -387,11 +409,20 @@ def _add_transform_and_shape_to_component(self, component, children_dict):
387409
)
388410
transformation_reader.add_transformations_to_component()
389411
self.warnings += transformation_reader.warnings
390-
depends_on_path = _find_depends_on_path(children_dict, component.name)
391-
if depends_on_path not in DEPENDS_ON_IGNORE:
392-
depends_on_id = TransformId(
393-
*get_component_and_transform_name(depends_on_path)
394-
)
412+
depends_on = _find_depends_on_path(children_dict, component.name)
413+
if depends_on not in DEPENDS_ON_IGNORE:
414+
if depends_on[0] != "/":
415+
# we are always in the NXtransformations group but the path could be anything
416+
if len(depends_on.split("/")) <= 2:
417+
depends_on = "/transformations/" + depends_on.split("/")[-1]
418+
else:
419+
self.warnings.append(
420+
RelativeDependsonWrong(
421+
f"depends_on in component {component.name} is relative, but we only support relative paths of length 1 or 2"
422+
)
423+
)
424+
depends_on = component.absolute_path + depends_on
425+
depends_on_id = TransformId(*get_component_and_transform_name(depends_on))
395426
self._components_depends_on[component.name] = (component, depends_on_id)
396427
else:
397428
self._components_depends_on[component.name] = (component, None)

nexus_constructor/json/load_from_json_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
NodeType,
1010
)
1111

12-
DEPENDS_ON_IGNORE = [None, "."]
12+
DEPENDS_ON_IGNORE = [None, 'None', ".", ""]
1313

1414

1515
def _find_shape_information(children: List[Dict]) -> Union[Dict, None]:

nexus_constructor/json/transformation_reader.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,15 @@ def _create_transformations(self, json_transformations: list):
306306
depends_on = _find_attribute_from_list_or_dict(
307307
CommonAttrs.DEPENDS_ON, attributes
308308
)
309+
if depends_on not in DEPENDS_ON_IGNORE:
310+
# relative paths warnings were sent to user when JSON was read in
311+
if depends_on[0] != "/":
312+
depends_on = (
313+
self.parent_component.absolute_path
314+
+ "/transformations/"
315+
+ depends_on
316+
)
317+
309318
if module == DATASET:
310319
values = self._get_transformation_attribute(
311320
CommonKeys.VALUES, config, name
@@ -319,15 +328,14 @@ def _create_transformations(self, json_transformations: list):
319328
angle_or_magnitude = 0.0
320329
else:
321330
continue
322-
temp_depends_on = None
323331

324332
transform = self.parent_component._create_and_add_transform(
325333
name=name,
326334
transformation_type=transformation_type,
327335
angle_or_magnitude=angle_or_magnitude,
328336
units=units,
329337
vector=QVector3D(*vector),
330-
depends_on=temp_depends_on,
338+
depends_on=None,
331339
values=values,
332340
)
333341
offset = self._find_attribute_in_list(CommonAttrs.OFFSET, name, attributes)

nx-class-documentation/html/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ <h1>User Manual and Reference Documentation<a class="headerlink" href="#user-man
109109
</div>
110110
<hr class="docutils" />
111111
<p class="rubric">Publishing Information</p>
112-
<p>This manual built Sep 15, 2023.</p>
112+
<p>This manual built Sep 18, 2023.</p>
113113
<div class="admonition seealso">
114114
<p class="admonition-title">See also</p>
115115
<p>This document is available in these formats online:</p>

nx-class-documentation/html/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)