Key features implemented: - Added new auto-dependency plugin that scans plugin manifests for system dependencies and automatically installs missing ones - Created SystemDependencyChecker class with support for multiple package managers (apt, yum, dnf, pacman, brew, apk) - Implemented PL injection interface with functions for scan, check, install, and info operations - Added context management system in core module for plugin execution environment - Created example plugin manifest demonstrating system dependency declaration - Updated .gitignore with comprehensive file exclusion patterns The plugin provides automatic scanning and installation of system dependencies declared in plugin manifests, integrating seamlessly with the plugin loader through PL injection capabilities.
59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
"""Context class for plugin execution environment."""
|
|
|
|
from typing import Any, Dict, Optional
|
|
|
|
|
|
class Context:
|
|
"""Execution context for plugins.
|
|
|
|
Provides access to configuration, state, and utilities during plugin execution.
|
|
"""
|
|
|
|
def __init__(self, config: Optional[Dict[str, Any]] = None):
|
|
"""Initialize the context.
|
|
|
|
Args:
|
|
config: Optional configuration dictionary.
|
|
"""
|
|
self.config = config or {}
|
|
self._state: Dict[str, Any] = {}
|
|
|
|
def get(self, key: str, default: Any = None) -> Any:
|
|
"""Get a configuration value.
|
|
|
|
Args:
|
|
key: Configuration key.
|
|
default: Default value if key not found.
|
|
|
|
Returns:
|
|
The configuration value or default.
|
|
"""
|
|
return self.config.get(key, default)
|
|
|
|
def set_state(self, key: str, value: Any) -> None:
|
|
"""Set a state value.
|
|
|
|
Args:
|
|
key: State key.
|
|
value: State value.
|
|
"""
|
|
self._state[key] = value
|
|
|
|
def get_state(self, key: str, default: Any = None) -> Any:
|
|
"""Get a state value.
|
|
|
|
Args:
|
|
key: State key.
|
|
default: Default value if key not found.
|
|
|
|
Returns:
|
|
The state value or default.
|
|
"""
|
|
return self._state.get(key, default)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"Context(config={self.config})"
|
|
|
|
|
|
__all__ = ['Context']
|