chore: standardize string quotes and fix import ordering across multiple modules
This commit is contained in:
+14
-9
@@ -1,10 +1,11 @@
|
||||
import importlib.util
|
||||
import os
|
||||
import sys
|
||||
import importlib.util
|
||||
from typing import List, Dict, Callable, Any
|
||||
from typing import Callable, Dict, List
|
||||
|
||||
from pr.core.logging import get_logger
|
||||
|
||||
logger = get_logger('plugins')
|
||||
logger = get_logger("plugins")
|
||||
|
||||
PLUGINS_DIR = os.path.expanduser("~/.pr/plugins")
|
||||
|
||||
@@ -21,7 +22,7 @@ class PluginLoader:
|
||||
logger.info("No plugins directory found")
|
||||
return []
|
||||
|
||||
plugin_files = [f for f in os.listdir(PLUGINS_DIR) if f.endswith('.py')]
|
||||
plugin_files = [f for f in os.listdir(PLUGINS_DIR) if f.endswith(".py")]
|
||||
|
||||
for plugin_file in plugin_files:
|
||||
try:
|
||||
@@ -44,16 +45,20 @@ class PluginLoader:
|
||||
sys.modules[plugin_name] = module
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
if hasattr(module, 'register_tools'):
|
||||
if hasattr(module, "register_tools"):
|
||||
tools = module.register_tools()
|
||||
if isinstance(tools, list):
|
||||
self.plugin_tools.extend(tools)
|
||||
self.loaded_plugins[plugin_name] = module
|
||||
logger.info(f"Loaded plugin: {plugin_name} ({len(tools)} tools)")
|
||||
else:
|
||||
logger.warning(f"Plugin {plugin_name} register_tools() did not return a list")
|
||||
logger.warning(
|
||||
f"Plugin {plugin_name} register_tools() did not return a list"
|
||||
)
|
||||
else:
|
||||
logger.warning(f"Plugin {plugin_name} does not have register_tools() function")
|
||||
logger.warning(
|
||||
f"Plugin {plugin_name} does not have register_tools() function"
|
||||
)
|
||||
|
||||
def get_plugin_function(self, tool_name: str) -> Callable:
|
||||
for plugin_name, module in self.loaded_plugins.items():
|
||||
@@ -67,7 +72,7 @@ class PluginLoader:
|
||||
|
||||
|
||||
def create_example_plugin():
|
||||
example_plugin = os.path.join(PLUGINS_DIR, 'example_plugin.py')
|
||||
example_plugin = os.path.join(PLUGINS_DIR, "example_plugin.py")
|
||||
|
||||
if os.path.exists(example_plugin):
|
||||
return
|
||||
@@ -121,7 +126,7 @@ def register_tools():
|
||||
|
||||
try:
|
||||
os.makedirs(PLUGINS_DIR, exist_ok=True)
|
||||
with open(example_plugin, 'w') as f:
|
||||
with open(example_plugin, "w") as f:
|
||||
f.write(example_code)
|
||||
logger.info(f"Created example plugin at {example_plugin}")
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user