Skip to content

Commit

Permalink
Merge c10e054 into c2ef3f3
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Oct 5, 2019
2 parents c2ef3f3 + c10e054 commit d7ea3d2
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Expand Up @@ -21,7 +21,11 @@ RUN apt-get update && apt-get install -y \

# Add requirements and install them. We do this unnecessasy rebuilding.
ADD requirements.txt /
RUN pip install --upgrade pip && pip install -r requirements.txt
ADD requirements-plugins.txt /

RUN pip install --upgrade pip && \
pip install -r requirements.txt && \
pip install -r requirements-plugins.txt &&

WORKDIR /srv/misago

Expand Down
9 changes: 8 additions & 1 deletion devproject/settings.py
Expand Up @@ -13,6 +13,8 @@

import os

from misago import load_plugin_list_if_exists


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -155,7 +157,11 @@

CSRF_FAILURE_VIEW = "misago.core.errorpages.csrf_failure"

INSTALLED_APPS = [
PLUGINS_LIST_PATH = os.path.join(os.path.dirname(BASE_DIR), "plugins.txt")

INSTALLED_PLUGINS = load_plugin_list_if_exists(PLUGINS_LIST_PATH) or []

INSTALLED_APPS = INSTALLED_PLUGINS + [
# Misago overrides for Django core feature
"misago",
"misago.users",
Expand Down Expand Up @@ -195,6 +201,7 @@
"misago.faker",
"misago.menus",
"misago.sso",
"misago.plugins",
]

INTERNAL_IPS = ["127.0.0.1"]
Expand Down
3 changes: 3 additions & 0 deletions misago/__init__.py
@@ -1,2 +1,5 @@
from .plugins.pluginlist import load_plugin_list_if_exists


__version__ = "0.23"
__released__ = True
Empty file added misago/plugins/__init__.py
Empty file.
41 changes: 41 additions & 0 deletions misago/plugins/pluginlist.py
@@ -0,0 +1,41 @@
import os
from typing import Dict, List, Optional, Tuple


def load_plugin_list_if_exists(path: str) -> Optional[List[str]]:
if not os.path.exists(path):
return None

return load_plugin_list(path)


def load_plugin_list(path: str) -> List[str]:
with open(path, "r") as f:
data = f.read()
return parse_plugins_list(data)


def parse_plugins_list(data: str) -> List[str]:
plugins: List[str] = []
definitions: Dict[str, Tuple[int, str]] = {}

for line, entry in enumerate(data.splitlines()):
plugin = entry.strip()

if "#" in plugin:
comment_start = plugin.find("#")
plugin = plugin[:comment_start].strip()
if not plugin:
continue

if plugin in definitions:
first_line, first_entry = definitions[plugin]
raise ValueError(
f"plugin '{plugin}' is listed more than once: "
f"at line {first_line} ('{first_entry}') and at {line} ('{entry}')"
)
definitions[plugin] = line, entry

plugins.append(plugin)

return plugins
Empty file.
33 changes: 33 additions & 0 deletions misago/plugins/tests/test_parsing_plugin_list.py
@@ -0,0 +1,33 @@
from ..pluginlist import parse_plugins_list


def test_empty_plugins_str_is_parsed_to_empty_list():
assert parse_plugins_list("") == []


def test_comment_str_is_parsed_to_empty_list():
assert parse_plugins_list("# comment") == []


def test_line_containing_plugin_name_is_parsed():
assert parse_plugins_list("plugin") == ["plugin"]


def test_comment_is_removed_from_line_containing_plugin_name():
assert parse_plugins_list("plugin # comment") == ["plugin"]


def test_multiple_lines_containing_plugin_names_are_parsed():
assert parse_plugins_list("plugin1\nplugin2") == ["plugin1", "plugin2"]


def test_empty_lines_are_skipped_by_parser():
assert parse_plugins_list("plugin1\n\nplugin2") == ["plugin1", "plugin2"]


def test_comments_are_filtered_from_plugin_list():
assert parse_plugins_list("plugin1\n# comment\nplugin2") == ["plugin1", "plugin2"]


def test_whitespace_is_stripped_from_line_start_and_end_by_parser():
assert parse_plugins_list("plugin1\n plugin2") == ["plugin1", "plugin2"]
6 changes: 6 additions & 0 deletions plugins.txt
@@ -0,0 +1,6 @@
# List of enabled plugins
# To enable plugin, simply enter its module name here:
#
# plugin_module
#
# To enable multiple plugins, list their names in separate lines:
2 changes: 2 additions & 0 deletions requirements-plugins.in
@@ -0,0 +1,2 @@
# File purposefully left empty
# Feel free to add plugins here
6 changes: 6 additions & 0 deletions requirements-plugins.txt
@@ -0,0 +1,6 @@
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file=requirements-plugins.txt requirements-plugins.in
#

0 comments on commit d7ea3d2

Please sign in to comment.