82 lines
3.9 KiB
Python
82 lines
3.9 KiB
Python
# projectutility/core/registry_models.py
|
|
|
|
import dataclasses
|
|
from typing import List, Optional, Dict, Any
|
|
|
|
|
|
# Use frozen=True?
|
|
# If these entries are intended to be immutable after loading,
|
|
# frozen=True provides that guarantee. However, if you need to
|
|
# modify them in memory (e.g., in the ConfigWindow before saving),
|
|
# you'd need frozen=False (the default).
|
|
# Let's keep it mutable for now, as ConfigWindow modifies it.
|
|
# Consider frozen=True if you always create new objects on modification.
|
|
@dataclasses.dataclass
|
|
class ToolRegistryEntry:
|
|
"""
|
|
Represents a single tool entry definition as stored in the
|
|
'tools_registry.json' file.
|
|
|
|
This dataclass defines the expected structure and types for each
|
|
tool configured in the registry.
|
|
"""
|
|
|
|
# --- Core Required Fields ---
|
|
id: str # Unique identifier for the tool (e.g., "icon_generator_git")
|
|
display_name: str # User-friendly name shown in the GUI list
|
|
type: str # Type of the tool ('git', 'local', potentially others later)
|
|
run_command: List[str] # Base command and arguments to execute the tool
|
|
has_gui: bool # Does this tool have its own graphical interface?
|
|
|
|
# --- Optional Core Fields ---
|
|
enabled: bool = (
|
|
True # Is the tool currently enabled and discoverable? Defaults to True.
|
|
)
|
|
description: Optional[str] = None # Optional description shown in the GUI
|
|
version: Optional[str] = None # Optional version string of the tool itself
|
|
|
|
# --- Git Specific Fields (only relevant if type == 'git') ---
|
|
git_url: Optional[str] = None # URL of the Git repository to clone/update
|
|
git_ref: str = (
|
|
"main" # Default branch, tag, or commit reference to use. Defaults to 'main'.
|
|
)
|
|
local_dir_name: Optional[str] = (
|
|
None # Optional custom name for the local directory in 'managed_tools'. Defaults to 'id' if None.
|
|
)
|
|
|
|
# --- Parameter Definition Source ---
|
|
# For type='local', this can be an inline list of parameter dicts.
|
|
# For type='git', this can be a file path relative to the repo root.
|
|
# For type='local' without inline params, set to None or omit.
|
|
parameters: Optional[List[Dict[str, Any]]] = (
|
|
None # Inline parameter definitions (primarily for 'local' type)
|
|
)
|
|
parameters_definition_file: Optional[str] = (
|
|
None # Relative path to a JSON file defining parameters (primarily for 'git' type)
|
|
)
|
|
|
|
# --- Post-Init Validation (Optional) ---
|
|
# Uncomment and implement if you need complex validation after initialization.
|
|
# def __post_init__(self):
|
|
# """Performs validation after the object is created."""
|
|
# errors = []
|
|
# if self.type == 'git' and not self.git_url:
|
|
# errors.append(f"Tool '{self.id}': 'git_url' is required for type 'git'.")
|
|
# if not self.run_command:
|
|
# errors.append(f"Tool '{self.id}': 'run_command' cannot be empty.")
|
|
# # Add more validation rules here if needed
|
|
# # Example: Check parameter definition source consistency
|
|
# if self.parameters and self.parameters_definition_file:
|
|
# errors.append(f"Tool '{self.id}': Cannot define both inline 'parameters' and 'parameters_definition_file'. Choose one.")
|
|
# if self.type == 'local' and self.parameters_definition_file:
|
|
# errors.append(f"Tool '{self.id}': 'parameters_definition_file' is typically used for 'git' type tools, not 'local'.")
|
|
# if self.type == 'git' and self.parameters:
|
|
# errors.append(f"Tool '{self.id}': Inline 'parameters' are typically used for 'local' type tools. Use 'parameters_definition_file' for 'git'.")
|
|
|
|
# if errors:
|
|
# # Raise a single error summarizing all issues
|
|
# raise ValueError(f"Validation failed for ToolRegistryEntry '{self.id}':\n - " + "\n - ".join(errors))
|
|
|
|
# logger = logging.getLogger(__name__) # Requires logging import
|
|
# logger.debug(f"ToolRegistryEntry created for ID: {self.id}")
|