diff --git a/__init__.py b/__init__.py index 07ea6b2..df9df2e 100644 --- a/__init__.py +++ b/__init__.py @@ -1,6 +1,12 @@ -from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS +from .nodes import YARS, YARSAdv + + +NODE_CLASS_MAPPINGS = {"YARS": YARS, "YARSAdv": YARSAdv} +NODE_DISPLAY_NAME_MAPPINGS = { + "YARS": "yaResolution Selector", + "YARSAdv": "yaResolution Selector (Advanced)", +} -__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"] # --------------------------- Install web extension ---------------------------- import shutil @@ -14,12 +20,11 @@ script_path = node_dir / "js" / "quickNodes.js" destination_dir = comfy_dir / "web" / "extensions" / "tropfchen" destination_path = destination_dir / "yarsQuickNodes.js" -ER = "during installing Embedding Picker web extension" try: destination_dir.mkdir(parents=True, exist_ok=True) shutil.copy2(script_path, destination_path) except PermissionError as permission_error: - print(f"Permission error {ER}: {permission_error}") + print(f"Permission error: {permission_error}") except Exception as e: - print(f"An unexpected error occurred {ER}: {e}") + print(f"An unexpected error occurred: {e}") diff --git a/nodes.py b/nodes.py index 44b73a5..70efa2c 100644 --- a/nodes.py +++ b/nodes.py @@ -2,29 +2,29 @@ import re class Dimensions: - def __init__(self, width: int, height: int): + def __init__(self, width, height): self.width = width self.height = height @property - def width(self): + def width(self) -> int: return self._width @width.setter - def width(self, value: int): + def width(self, value): if value < 64: raise ValueError("width of less than 64 pixel") - self._width = int(value / 2) * 2 if value % 2 else value + self._width = int(value / 2) * 2 if value % 2 else int(value) @property - def height(self): + def height(self) -> int: return self._height @height.setter - def height(self, value: int): + def height(self, value): if value < 64: raise ValueError("height of less than 64 pixel") - self._height = int(value / 2) * 2 if value % 2 else value + self._height = int(value / 2) * 2 if value % 2 else int(value) def calculate_aspect_ratio( @@ -44,13 +44,13 @@ def calculate_aspect_ratio( else: height *= ratio - return Dimensions(int(width), int(height)) + return Dimensions(width, height) def calculate_constant_constant_resolution( base_resolution: int, ratio: float ) -> Dimensions: - pixel_count = base_resolution ** 2 + pixel_count = base_resolution**2 new_height = (pixel_count * ratio) ** 0.5 new_width = new_height / ratio return Dimensions(new_width, new_height) @@ -186,12 +186,6 @@ class YARSAdv: return (d.width, d.height) -NODE_CLASS_MAPPINGS = {"YARS": YARS, "YARSAdv": YARSAdv} -NODE_DISPLAY_NAME_MAPPINGS = { - "YARS": "yaResolution Selector", - "YARSAdv": "yaResolution Selector (Advanced)", -} - if __name__ == "__main__": import unittest @@ -238,4 +232,9 @@ if __name__ == "__main__": ): Dimensions(55, 512) + def test_dimensions_returns_ints(self): + d = Dimensions(153.584, 128.0000) + self.assertIsInstance(d.width, int) + self.assertIsInstance(d.height, int) + unittest.main()