fred-dev/comfy_ui_ali
0
1from __future__ import annotations2 3from dataclasses import dataclass4import os5 6from git_utils import get_commit_hash7 8 9@dataclass10class InstalledNodePackage:11 """Information about an installed node package."""12 13 id: str14 fullpath: str15 disabled: bool16 version: str17 18 @property19 def is_unknown(self) -> bool:20 return self.version == "unknown"21 22 @property23 def is_nightly(self) -> bool:24 return self.version == "nightly"25 26 @property27 def is_from_cnr(self) -> bool:28 return not self.is_unknown and not self.is_nightly29 30 @property31 def is_enabled(self) -> bool:32 return not self.disabled33 34 @property35 def is_disabled(self) -> bool:36 return self.disabled37 38 def get_commit_hash(self) -> str:39 return get_commit_hash(self.fullpath)40 41 def isValid(self) -> bool:42 if self.is_from_cnr:43 return os.path.exists(os.path.join(self.fullpath, '.tracking'))44 45 return True46 47 @staticmethod48 def from_fullpath(fullpath: str, resolve_from_path) -> InstalledNodePackage:49 parent_folder_name = os.path.basename(os.path.dirname(fullpath))50 module_name = os.path.basename(fullpath)51 52 if module_name.endswith(".disabled"):53 node_id = module_name[:-9]54 disabled = True55 elif parent_folder_name == ".disabled":56 # Nodes under custom_nodes/.disabled/* are disabled57 node_id = module_name58 disabled = True59 else:60 node_id = module_name61 disabled = False62 63 info = resolve_from_path(fullpath)64 if info is None:65 version = 'unknown'66 else:67 node_id = info['id'] # robust module guessing68 version = info['ver']69 70 return InstalledNodePackage(71 id=node_id, fullpath=fullpath, disabled=disabled, version=version72 )73 