Files
ComfyAssets-ComfyUI-KikoTools/kikotools/base/base_node.py
T
Vito Sansevero ab23992c29 chore: project housekeeping and configuration updates
- Add code quality tools: flake8, mypy, black, pre-commit
- Add .gitattributes for line ending consistency
- Add .secrets.baseline for secret scanning
- Update GitHub workflows for better CI/CD
- Update documentation formatting and examples
- Add CLAUDE.md for AI assistant guidance
- Add scripts directory for automation tools
- Update project configuration in pyproject.toml
- Improve type hints and code formatting across all modules
- Update test configurations and fixtures
2025-08-01 08:35:08 -07:00

75 lines
2.0 KiB
Python

"""
Base node class for all ComfyAssets tools
Provides consistent categorization and shared functionality
"""
from typing import Dict, Any, Optional
import logging
logger = logging.getLogger(__name__)
class ComfyAssetsBaseNode:
"""
Base class for all ComfyAssets nodes
Provides:
- Consistent "ComfyAssets" categorization
- Standardized error handling and logging
- Common validation patterns
- Consistent return type handling
"""
CATEGORY = "ComfyAssets"
def validate_inputs(self, **kwargs) -> None:
"""
Common input validation logic
Override in subclasses for specific validation needs
Args:
**kwargs: Input parameters to validate
Raises:
ValueError: If validation fails
"""
pass
def handle_error(self, error_msg: str, exception: Optional[Exception] = None) -> None:
"""
Standardized error handling with logging
Args:
error_msg: Human-readable error message
exception: Optional original exception for logging
"""
logger.error(f"{self.__class__.__name__}: {error_msg}")
if exception:
logger.exception(f"Original exception: {exception}")
raise ValueError(error_msg)
def log_info(self, message: str) -> None:
"""
Standardized info logging
Args:
message: Information message to log
"""
logger.info(f"{self.__class__.__name__}: {message}")
@classmethod
def get_node_info(cls) -> Dict[str, Any]:
"""
Get standardized node information for debugging/introspection
Returns:
Dict containing node metadata
"""
return {
"class_name": cls.__name__,
"category": getattr(cls, "CATEGORY", "Unknown"),
"function": getattr(cls, "FUNCTION", "Unknown"),
"return_types": getattr(cls, "RETURN_TYPES", ()),
"return_names": getattr(cls, "RETURN_NAMES", ()),
}