From 366c58aa473c8c6751e688d586cbd3fdb3aa58b5 Mon Sep 17 00:00:00 2001 From: Chris Bridge Date: Mon, 15 Aug 2022 01:01:28 +0000 Subject: [PATCH] Remove module level imports of module data (#196) --- src/highdicom/_module_utils.py | 17 ++++++++++------- src/highdicom/base.py | 4 ++-- src/highdicom/legacy/sop.py | 4 ++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/highdicom/_module_utils.py b/src/highdicom/_module_utils.py index 2a33dd14..8a91a9bf 100644 --- a/src/highdicom/_module_utils.py +++ b/src/highdicom/_module_utils.py @@ -3,13 +3,6 @@ from pydicom import Dataset -from highdicom._iods import IOD_MODULE_MAP, SOP_CLASS_UID_IOD_KEY_MAP -from highdicom._modules import MODULE_ATTRIBUTE_MAP -from highdicom._iods import ( - IOD_MODULE_MAP, - SOP_CLASS_UID_IOD_KEY_MAP -) - # Allowed values for the type of an attribute class AttributeTypeValues(Enum): @@ -168,6 +161,7 @@ def construct_module_tree(module: str) -> Dict[str, Any]: dictionary that forms an item in the next level of the tree structure. """ + from highdicom._modules import MODULE_ATTRIBUTE_MAP if module not in MODULE_ATTRIBUTE_MAP: raise AttributeError(f"No such module found: '{module}'.") tree: Dict[str, Any] = {'attributes': {}} @@ -205,6 +199,10 @@ def get_module_usage( """ + from highdicom._iods import ( + IOD_MODULE_MAP, + SOP_CLASS_UID_IOD_KEY_MAP + ) try: iod_name = SOP_CLASS_UID_IOD_KEY_MAP[sop_class_uid] except KeyError as e: @@ -235,6 +233,11 @@ def is_attribute_in_iod(attribute: str, sop_class_uid: str) -> bool: specified by the sop_class_uid. False otherwise. """ + from highdicom._iods import ( + IOD_MODULE_MAP, + SOP_CLASS_UID_IOD_KEY_MAP + ) + from highdicom._modules import MODULE_ATTRIBUTE_MAP try: iod_name = SOP_CLASS_UID_IOD_KEY_MAP[sop_class_uid] except KeyError as e: diff --git a/src/highdicom/base.py b/src/highdicom/base.py index ca6e056b..f2aa7cad 100644 --- a/src/highdicom/base.py +++ b/src/highdicom/base.py @@ -16,8 +16,6 @@ ) from highdicom.valuerep import check_person_name from highdicom.version import __version__ -from highdicom._iods import IOD_MODULE_MAP, SOP_CLASS_UID_IOD_KEY_MAP -from highdicom._modules import MODULE_ATTRIBUTE_MAP from highdicom._module_utils import is_attribute_in_iod @@ -289,6 +287,8 @@ def _copy_root_attributes_of_module( DICOM Module (e.g., ``"General Series"`` or ``"Specimen"``) """ + from highdicom._iods import IOD_MODULE_MAP, SOP_CLASS_UID_IOD_KEY_MAP + from highdicom._modules import MODULE_ATTRIBUTE_MAP logger.info( 'copy {}-related attributes from dataset "{}"'.format( ie, dataset.SOPInstanceUID diff --git a/src/highdicom/legacy/sop.py b/src/highdicom/legacy/sop.py index 3ae20849..d7c3df4f 100644 --- a/src/highdicom/legacy/sop.py +++ b/src/highdicom/legacy/sop.py @@ -17,8 +17,6 @@ from highdicom.base import SOPClass from highdicom.frame import encode_frame -from highdicom._iods import IOD_MODULE_MAP, SOP_CLASS_UID_IOD_KEY_MAP -from highdicom._modules import MODULE_ATTRIBUTE_MAP logger = logging.getLogger(__name__) @@ -60,6 +58,8 @@ def _convert_legacy_to_enhanced( which instances are provided via `sf_datasets`. """ + from highdicom._iods import IOD_MODULE_MAP, SOP_CLASS_UID_IOD_KEY_MAP + from highdicom._modules import MODULE_ATTRIBUTE_MAP try: ref_ds = sf_datasets[0] except IndexError: