1212logger = logging .getLogger (__name__ )
1313
1414
15- PGK_PATH = os .path .join (
15+ PKG_JSON_PATH = os .path .join (
1616 os .path .dirname (__file__ ),
1717 '..' ,
1818 'src' ,
19- 'highdicom'
19+ 'highdicom' ,
20+ '_standard' ,
2021)
2122
2223
@@ -25,10 +26,6 @@ def _load_json_from_file(filename):
2526 return json .load (f )
2627
2728
28- def _dump_json (data ):
29- return json .dumps (data , indent = 4 , sort_keys = True )
30-
31-
3229def _create_sop_to_iods (directory ):
3330 filename = os .path .join (directory , 'sops.json' )
3431 sops = _load_json_from_file (filename )
@@ -97,14 +94,16 @@ def _create_modules(directory):
9794 return modules
9895
9996
100- if __name__ == '__main__' :
101-
97+ if __name__ == "__main__" :
10298 logging .basicConfig ()
10399 logger .setLevel (logging .DEBUG )
104100
105101 # Positional argument is path to directory containing JSON files generated
106102 # using the dicom-standard Python package, see
107103 # https://github.com/innolitics/dicom-standard/tree/master/standard
104+ # If generating yourself using the instructions in that repo, be sure to
105+ # use "make all" instead of just "make", otherwise some of the required
106+ # files are skipped
108107 try :
109108 directory = sys .argv [1 ]
110109 except IndexError as e :
@@ -119,37 +118,16 @@ def _create_modules(directory):
119118 current_time = datetime .datetime .time (now ).strftime ('%H:%M:%S' )
120119
121120 iods = _create_iods (directory )
122- iods_docstr = '\n ' .join ([
123- '"""DICOM Information Object Definitions (IODs)' ,
124- f'auto-generated on { current_date } at { current_time } .' ,
125- '"""' ,
126- 'from typing import Dict, List'
127- ])
121+ iods_filename = os .path .join (PKG_JSON_PATH , 'iods.json' )
122+ with open (iods_filename , 'w' ) as jf :
123+ json .dump (iods , jf , indent = 2 )
124+
128125 sop_to_iods = _create_sop_to_iods (directory )
129- iods_filename = os .path .join (PGK_PATH , '_iods.py' )
130- with open (iods_filename , 'w' ) as fp :
131- fp .write (iods_docstr )
132- fp .write ('\n \n ' )
133- iods_formatted = _dump_json (iods ).replace ('null' , 'None' )
134- fp .write (
135- f'IOD_MODULE_MAP: Dict[str, List[Dict[str, str]]] = { iods_formatted } '
136- )
137- fp .write ('\n \n ' )
138- sop_to_iods_formatted = _dump_json (sop_to_iods ).replace ('null' , 'None' )
139- fp .write (f'SOP_CLASS_UID_IOD_KEY_MAP = { sop_to_iods_formatted } ' )
126+ sop_to_iods_filename = os .path .join (PKG_JSON_PATH , 'sop_class_to_iod.json' )
127+ with open (sop_to_iods_filename , 'w' ) as jf :
128+ json .dump (sop_to_iods , jf , indent = 2 )
140129
141130 modules = _create_modules (directory )
142- modules_docstr = '\n ' .join ([
143- '"""DICOM modules'
144- f'auto-generated on { current_date } at { current_time } .'
145- '"""' ,
146- 'from typing import Dict, List, Sequence, Union'
147- ])
148- modules_filename = os .path .join (PGK_PATH , '_modules.py' )
149- with open (modules_filename , 'w' ) as fp :
150- fp .write (modules_docstr )
151- fp .write ('\n \n ' )
152- modules_formatted = _dump_json (modules ).replace ('null' , 'None' )
153- fp .write (
154- f'MODULE_ATTRIBUTE_MAP: Dict[str, List[Dict[str, Union[str, Sequence[str]]]]] = { modules_formatted } ' # noqa: E501
155- )
131+ modules_filename = os .path .join (PKG_JSON_PATH , 'modules.json' )
132+ with open (modules_filename , 'w' ) as jf :
133+ json .dump (modules , jf , indent = 2 )
0 commit comments