Skip to content

Commit

Permalink
New plugin discovery logic (without tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Nov 19, 2023
1 parent 4ecaeb6 commit b4b3b6e
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 180 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ ADD plugins /app/plugins
WORKDIR /app/

# Install Misago requirements
# RUN pip install --upgrade pip && \
# pip install -r /app/requirements.txt && \
# pip install pip-tools
RUN pip install --upgrade pip && \
pip install -r /app/requirements.txt && \
pip install pip-tools

# Bootstrap plugins
RUN ./dev bootstrap_plugins

EXPOSE 8000

CMD python manage.py runserver 0.0.0.0:8000
CMD python manage.py runserver 0.0.0.0:8000 --noreload
22 changes: 21 additions & 1 deletion dev-docs/plugins/index.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# Plugin guide
# Plugin guide

Misago implements a plugin system that enables developers to customize and extend the core functionality of the software. This plugin system itself extends existing Django applications mechanism.

> plugins vs. forking note

## Plugin installation


## Writing custom plugin

- django applications mechanism
- plugin structure
- plugins vs. forking


## Hooks

- how to hooks
- hook reference
6 changes: 3 additions & 3 deletions devproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import os

from misago import plugin_loader
from misago import discover_plugins
from misago.settings import *


Expand Down Expand Up @@ -158,9 +158,9 @@

CSRF_FAILURE_VIEW = "misago.core.errorpages.csrf_failure"

PLUGINS_LIST_PATH = os.path.join(os.path.dirname(BASE_DIR), "plugins.txt")
PLUGINS_DIRECTORY = os.environ.get("MISAGO_PLUGINS")

INSTALLED_PLUGINS = plugin_loader.get_plugins_apps()
INSTALLED_PLUGINS = discover_plugins(PLUGINS_DIRECTORY)

# Combine Misago's default installed apps with plugins
INSTALLED_APPS = [
Expand Down
2 changes: 1 addition & 1 deletion misago/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .plugins.loader import plugin_loader
from .plugins import MisagoPlugin, discover_plugins


__version__ = "0.39.0"
Expand Down
2 changes: 2 additions & 0 deletions misago/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .discover import discover_plugins
from .manifest import MisagoPlugin
31 changes: 31 additions & 0 deletions misago/plugins/discover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sys
from pathlib import Path
from typing import List


def discover_plugins(plugins_path: str | None) -> List[str]:
if not plugins_path:
return []

plugins_path_obj = Path(plugins_path)
if not plugins_path_obj.is_dir():
return []

return discover_plugins_in_directory(plugins_path_obj)


def discover_plugins_in_directory(plugins_path: Path) -> List[str]:
plugins_apps: List[str] = []

for plugin_path in plugins_path.glob("*/*/misago_plugin.py"):
plugin_package = plugin_path.parent

# Add plugin to Python path so its importable
plugin_dir = str(plugin_package.parent)
if plugin_dir not in sys.path:
sys.path.append(plugin_dir)

# Add plugin to apps to make Django include it
plugins_apps.append(plugin_package.name)

return plugins_apps
10 changes: 0 additions & 10 deletions misago/plugins/hook.py

This file was deleted.

26 changes: 0 additions & 26 deletions misago/plugins/loader.py

This file was deleted.

15 changes: 15 additions & 0 deletions misago/plugins/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from dataclasses import dataclass
from typing import Optional


@dataclass(frozen=True)
class MisagoPlugin:
name: str
description: Optional[str] = None
license: Optional[str] = None
icon: Optional[str] = None
color: Optional[str] = None
version: Optional[str] = None
author: Optional[str] = None
homepage: Optional[str] = None
repo: Optional[str] = None
62 changes: 0 additions & 62 deletions misago/plugins/pluginlist.py

This file was deleted.

45 changes: 0 additions & 45 deletions misago/plugins/tests/test_parsing_plugin_list.py

This file was deleted.

28 changes: 0 additions & 28 deletions misago/plugins/tests/test_plugin_list_validation.py

This file was deleted.

6 changes: 6 additions & 0 deletions plugins/example-plugin/example_plugin/misago_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from misago import MisagoPlugin


manifest = MisagoPlugin(
name="My example plugin",
)

0 comments on commit b4b3b6e

Please sign in to comment.