Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion imas/backends/db_entry_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get(
destination: IDSToplevel,
lazy: bool,
nbc_map: Optional[NBCPathMap],
) -> None:
) -> IDSToplevel:
"""Implement DBEntry.get/get_slice/get_sample. Load data from the data source.

Args:
Expand Down
6 changes: 3 additions & 3 deletions imas/db_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __init__(
legacy = True
except TypeError as exc2:
raise TypeError(
f"Incorrect arguments to {__class__.__name__}.__init__(): "
"Incorrect arguments to DBEntry.__init__(): "
f"{exc1.args[0]}, {exc2.args[0]}"
) from None

Expand Down Expand Up @@ -561,7 +561,7 @@ def _get(
raise RuntimeError("Database entry is not open.")
if lazy and destination:
raise ValueError("Cannot supply a destination IDS when lazy loading.")
if not self._ids_factory.exists(ids_name):
if autoconvert and not self._ids_factory.exists(ids_name):
raise IDSNameError(ids_name, self._ids_factory)

# Note: this will raise an exception when the ids/occurrence is not filled:
Expand All @@ -577,7 +577,7 @@ def _get(
ids_name,
occurrence,
)
elif dd_version != self.dd_version and dd_version not in dd_xml_versions():
elif dd_version not in dd_xml_versions() and dd_version != self.dd_version:
# We don't know the DD version that this IDS was written with
if ignore_unknown_dd_version:
# User chooses to ignore this problem, load as if it was stored with
Expand Down
19 changes: 18 additions & 1 deletion imas/ids_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ def __init__(
version: DD version string, e.g. "3.38.1".
xml_path: XML file containing data dictionary definition.
"""
if version is None and xml_path is None:
# Defer loading the DD definitions until we really need them
self.__deferred_init = True
else:
# If a specific version or xml_path is requested, we still load immediately
# so any exceptions are raise when creating the IDSfactory
self.__do_init(version, xml_path)
self.__deferred_init = False

def __do_init(self, version: str | None, xml_path: str | pathlib.Path | None):
"""Actual initalization logic"""
Comment thread
maarten-ic marked this conversation as resolved.
Outdated
self._xml_path = xml_path
self._etree = dd_zip.dd_etree(version, xml_path)
self._ids_elements = {
Expand Down Expand Up @@ -71,10 +82,16 @@ def __dir__(self) -> Iterable[str]:
return sorted(set(object.__dir__(self)).union(self._ids_elements))

def __getattr__(self, name: str) -> Any:
# Actually initialize when we deferred it before
if self.__deferred_init:
self.__do_init(None, None)
self.__deferred_init = False
return getattr(self, name)
# Check if the name matches any IDS and return a 'constructor' for it
if name in self._ids_elements:
# Note: returning a partial to mimic AL HLI, e.g. factory.core_profiles()
return partial(IDSToplevel, self, self._ids_elements[name])
raise AttributeError(f"{type(self)!r} object has no attribute {name!r}")
raise AttributeError(f"'IDSFactory' has no attribute {name!r}")

def __iter__(self) -> Iterator[str]:
"""Iterate over the IDS names defined by the loaded Data Dictionary"""
Expand Down
Loading