loader
File-based plugin loading with security checks.
This module handles loading plugins from Python files in user directories. It includes security checks for symlinks and world-writable directories.
Classes¶
Functions¶
clear_plugin_cache ¶
load_user_plugins ¶
load_user_plugins(plugin_dirs: list[Path] | None = None, force_reload: bool = False) -> list[ToolProgressPlugin]
Load custom user plugins from plugin directories.
User plugins are Python files in ~/.snakesee/plugins/ or ~/.config/snakesee/plugins/ that define classes inheriting from ToolProgressPlugin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plugin_dirs
|
list[Path] | None
|
List of directories to search. Defaults to USER_PLUGIN_DIRS. |
None
|
force_reload
|
bool
|
If True, reload plugins even if already cached. |
False
|
Returns:
| Type | Description |
|---|---|
list[ToolProgressPlugin]
|
List of loaded user plugin instances. |
Example plugin file (~/.snakesee/plugins/my_tool.py)::
from snakesee.plugins.base import ToolProgress, ToolProgressPlugin
import re
class MyToolPlugin(ToolProgressPlugin):
@property
def tool_name(self) -> str:
return "mytool"
def can_parse(self, rule_name: str, log_content: str) -> bool:
return "mytool" in rule_name.lower()
def parse_progress(self, log_content: str) -> ToolProgress | None:
match = re.search(r"Processed (\d+) items", log_content)
if match:
return ToolProgress(items_processed=int(match.group(1)), unit="items")
return None
Source code in snakesee/plugins/loader.py
validate_plugin ¶
validate_plugin(plugin: ToolProgressPlugin, source: str = 'unknown') -> PluginMetadata | None
Validate that a plugin instance is compatible and properly implemented.
Uses PluginMetadata for structured validation of plugin attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plugin
|
ToolProgressPlugin
|
The plugin instance to validate. |
required |
source
|
str
|
Description of where the plugin came from (for logging). |
'unknown'
|
Returns:
| Type | Description |
|---|---|
PluginMetadata | None
|
PluginMetadata if the plugin is valid and compatible, None otherwise. |