[AI]
Поддержка плагинов
This commit is contained in:
@@ -4,12 +4,18 @@ from typing import Optional
|
||||
from docx import Document
|
||||
from .style_registry import StyleRegistry
|
||||
from .renderer import render_markdown_to_docx
|
||||
|
||||
from .plugin_loader import load_plugins_from_path
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def process_document(input_dir: Path, output_dir: Path, style_config_path: Path, template_path: Optional[Path] = None, theme_name: Optional[str] = None):
|
||||
def process_document(
|
||||
input_dir: Path, output_dir: Path, style_config_path: Path,
|
||||
template_path: Optional[Path] = None, theme_name: Optional[str] = None,
|
||||
plugins_dir: Optional[Path] = None
|
||||
):
|
||||
if plugins_dir and plugins_dir.exists():
|
||||
load_plugins_from_path(plugins_dir)
|
||||
if theme_name:
|
||||
theme_path = Path("resources/themes") / f"{theme_name}.yaml"
|
||||
if theme_path.exists():
|
||||
|
||||
16
src/core/plugin_loader.py
Normal file
16
src/core/plugin_loader.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
from ..handlers import register_handler
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def load_plugins_from_path(plugins_dir: Path):
|
||||
"""Загружает все .py файлы из папки как плагины."""
|
||||
for py_file in plugins_dir.glob("*.py"):
|
||||
spec = importlib.util.spec_from_file_location(py_file.stem, py_file)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
# Теперь все @register_handler в module выполнены
|
||||
logger.info(f"Загружен плагин: {py_file.name}")
|
||||
Reference in New Issue
Block a user