divisor.save
1# SPDX-License-Identifier: MPL-2.0 AND LicenseRef-Commons-Clause-License-Condition-1.0 2# <!-- // /* d a r k s h a p e s */ --> 3 4from pathlib import Path 5from nnll.save_generation import name_save_file_as, save_output 6from nnll.constants import ExtensionType 7from nnll.hyperchain import HyperChain 8from PIL import Image 9 10 11class SaveFile: 12 intermediate_image: Image.Image 13 hyperchain: HyperChain 14 extension: ExtensionType | set[str] = ExtensionType.WEBP 15 save_folder_path: Path = Path(__file__).resolve().parent.parent / ".output" 16 17 def __enter__(self) -> "SaveFile": 18 """Return instanced self""" 19 return self 20 21 def __exit__(self, exc_type, exc_val, exc_tb) -> None: 22 """Perform cleanup regardless of success or exception""" 23 self._cleanup() 24 25 def _cleanup(self) -> None: 26 """Release resources held by the instance and close methods (PIL.Image)""" 27 if hasattr(self.intermediate_image, "close"): 28 try: 29 self.intermediate_image.close() 30 except Exception: 31 pass # ignore errors during cleanup 32 33 self.intermediate_image = None # type: ignore[assignment] 34 self.hyperchain = None # type: ignore[assignment] 35 36 def with_hyperchain(self) -> None: 37 file_path_named = name_save_file_as( 38 extension=self.extension, 39 save_folder_path=self.save_folder_path, 40 ) 41 save_output( 42 file_path_named, 43 self.intermediate_image, 44 self.extension, 45 str(self.hyperchain), 46 )
class
SaveFile:
12class SaveFile: 13 intermediate_image: Image.Image 14 hyperchain: HyperChain 15 extension: ExtensionType | set[str] = ExtensionType.WEBP 16 save_folder_path: Path = Path(__file__).resolve().parent.parent / ".output" 17 18 def __enter__(self) -> "SaveFile": 19 """Return instanced self""" 20 return self 21 22 def __exit__(self, exc_type, exc_val, exc_tb) -> None: 23 """Perform cleanup regardless of success or exception""" 24 self._cleanup() 25 26 def _cleanup(self) -> None: 27 """Release resources held by the instance and close methods (PIL.Image)""" 28 if hasattr(self.intermediate_image, "close"): 29 try: 30 self.intermediate_image.close() 31 except Exception: 32 pass # ignore errors during cleanup 33 34 self.intermediate_image = None # type: ignore[assignment] 35 self.hyperchain = None # type: ignore[assignment] 36 37 def with_hyperchain(self) -> None: 38 file_path_named = name_save_file_as( 39 extension=self.extension, 40 save_folder_path=self.save_folder_path, 41 ) 42 save_output( 43 file_path_named, 44 self.intermediate_image, 45 self.extension, 46 str(self.hyperchain), 47 )
save_folder_path: pathlib._local.Path =
PosixPath('/Users/e6d64/Documents/GitHub/darkshapes/divisor/.output')