Skip to content

Commit

Permalink
Move object node based init away from file based init
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson committed Aug 22, 2023
1 parent 0945ee9 commit bcd7d9f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/roman_datamodels/datamodels/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ def __init__(self, init=None, **kwargs):
self._instance = None
self._asdf = None

if isinstance(init, stnode.TaggedObjectNode):
if not isinstance(self, MODEL_REGISTRY.get(init.__class__)):
expected = {mdl: node for node, mdl in MODEL_REGISTRY.items()}[self.__class__].__name__
raise ValidationError(
f"TaggedObjectNode: {init.__class__.__name__} is not of the type expected. Expected {expected}"
)
with validate.nuke_validation():
self._instance = init
self._asdf = asdf.AsdfFile({"roman": init})

return

if init is None:
self._asdf = self.open_asdf(init=None, **kwargs)
elif isinstance(init, (str, bytes, PurePath)):
Expand All @@ -91,16 +103,6 @@ def __init__(self, init=None, **kwargs):
elif isinstance(init, asdf.AsdfFile):
self._asdf = init
self._instance = self._asdf.tree["roman"]
elif isinstance(init, stnode.TaggedObjectNode):
if not isinstance(self, MODEL_REGISTRY.get(init.__class__)):
expected = {mdl: node for node, mdl in MODEL_REGISTRY.items()}[self.__class__].__name__
raise ValidationError(
f"TaggedObjectNode: {init.__class__.__name__} is not of the type expected. Expected {expected}"
)
with validate.nuke_validation():
self._instance = init
self._asdf = asdf.AsdfFile()
self._asdf.tree = {"roman": init}
else:
raise OSError("Argument does not appear to be an ASDF file or TaggedObjectNode.")

Expand Down

0 comments on commit bcd7d9f

Please sign in to comment.