File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6363
6464SUPPORTED_WRITERS : dict = {}
6565
66+ # Maps common file extensions to the package needed by ImageWriter backends.
67+ FILETYPE_HINT : dict [str , str ] = {
68+ "nii" : "nibabel" ,
69+ "nii.gz" : "nibabel" ,
70+ "mha" : "itk" ,
71+ "mhd" : "itk" ,
72+ "nrrd" : "itk" ,
73+ "png" : "pillow" ,
74+ "jpg" : "pillow" ,
75+ "jpeg" : "pillow" ,
76+ "tif" : "pillow" ,
77+ "tiff" : "pillow" ,
78+ "bmp" : "pillow" ,
79+ }
80+
6681
6782def register_writer (ext_name , * im_writers ):
6883 """
@@ -116,21 +131,8 @@ def resolve_writer(ext_name, error_if_not_found=True) -> Sequence:
116131 except Exception : # other writer init errors indicating it exists
117132 avail_writers .append (_writer )
118133 if not avail_writers and error_if_not_found :
119- install_hints : dict = {
120- "nii" : "nibabel" ,
121- "nii.gz" : "nibabel" ,
122- "mha" : "itk" ,
123- "mhd" : "itk" ,
124- "nrrd" : "itk" ,
125- "png" : "pillow" ,
126- "jpg" : "pillow" ,
127- "jpeg" : "pillow" ,
128- "tif" : "pillow" ,
129- "tiff" : "pillow" ,
130- "bmp" : "pillow" ,
131- }
132- hint = install_hints .get (fmt )
133- extra = f" Try installing the required package: pip install { hint } " if hint else ""
134+ hint = FILETYPE_HINT .get (fmt )
135+ extra = f" Try: pip install { hint } " if hint else ""
134136 raise OptionalImportError (f"No ImageWriter backend found for '{ fmt } '.{ extra } " )
135137 writer_tuple = ensure_tuple (avail_writers )
136138 SUPPORTED_WRITERS [fmt ] = writer_tuple
You can’t perform that action at this time.
0 commit comments