Поддержка плагинов
This commit is contained in:
Mikan
2025-12-08 17:27:26 +03:00
parent 8da965234c
commit 5b08f6792a
4 changed files with 52 additions and 3 deletions

View File

@@ -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
View 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}")