Skip to content

Commit 8b1e226

Browse files
committed
move legacy Plugin base class from core to config
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
1 parent 807ae9c commit 8b1e226

File tree

15 files changed

+39
-47
lines changed

15 files changed

+39
-47
lines changed

rdmo/config/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from dataclasses import dataclass, field
44
from typing import Any
55

6+
from django.utils.module_loading import import_string
7+
68

79
@dataclass(frozen=True)
810
class DeclaredPlugin:
@@ -17,7 +19,6 @@ class DeclaredPlugin:
1719

1820
def get_plugin_instance(self):
1921
try:
20-
from django.utils.module_loading import import_string
2122
return import_string(self.python_path)(self.uri_path, self.title, self.python_path)
2223
except Exception:
2324
return None

rdmo/config/plugin_types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from django.utils.module_loading import import_string
44

5-
from rdmo.core.plugins import Plugin as LegacyPluginBase
6-
75

86
def get_plugin_type_mapping():
97
# imports at run-time only
@@ -35,6 +33,7 @@ def detect_plugin_type(python_path) -> str:
3533
else:
3634
return "has_plugin_type_but_empty"
3735

36+
from rdmo.config.plugins import PluginBase as LegacyPluginBase
3837
if not issubclass(cls, LegacyPluginBase):
3938
return "not_an_rdmo_plugin"
4039

rdmo/config/plugins.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
from rdmo.config.helpers import DeclaredPlugin
66
from rdmo.config.models import Plugin
7+
from rdmo.core.utils import import_class
8+
9+
10+
class PluginBase:
11+
pass
712

813

914
def get_plugins_from_db(project=None, plugin_type: str | None=None, user=None) -> list[DeclaredPlugin]:
@@ -29,7 +34,7 @@ def get_plugins_from_db(project=None, plugin_type: str | None=None, user=None) -
2934
continue
3035

3136
if instance.python_path not in settings.PLUGINS:
32-
continue
37+
continue # plugins are filtered by settings as well
3338

3439
if instance.plugin_type != plugin_type:
3540
continue
@@ -44,3 +49,15 @@ def get_plugins_from_db(project=None, plugin_type: str | None=None, user=None) -
4449
source=f"Plugin(id={instance.id})",
4550
))
4651
return results
52+
53+
54+
def get_plugin(plugin_settings, plugin_key):
55+
try:
56+
key, label, class_name = next(
57+
(key, label, class_name)
58+
for key, label, class_name in getattr(settings, plugin_settings)
59+
if key == plugin_key
60+
)
61+
return import_class(class_name)(key, label, class_name)
62+
except StopIteration:
63+
return None

rdmo/core/plugins.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

rdmo/options/providers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from rdmo.core.plugins import Plugin
1+
from rdmo.config.plugins import PluginBase
22

33

4-
class Provider(Plugin):
4+
class Provider(PluginBase):
55

66
plugin_type = 'optionset_provider'
77

rdmo/projects/exports.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from django.conf import settings
44
from django.http import HttpResponse
55

6+
from rdmo.config.plugins import PluginBase
67
from rdmo.core.exports import prettify_xml
7-
from rdmo.core.plugins import Plugin
88
from rdmo.core.utils import render_to_csv, render_to_json
99
from rdmo.views.templatetags import view_tags
1010
from rdmo.views.utils import ProjectWrapper
@@ -14,7 +14,7 @@
1414
from .serializers.export import SnapshotSerializer as SnapshotExportSerializer
1515

1616

17-
class Export(Plugin):
17+
class Export(PluginBase):
1818

1919
plugin_type = 'project_export'
2020

rdmo/projects/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from django.utils.safestring import mark_safe
99
from django.utils.translation import gettext_lazy as _
1010

11+
from rdmo.config.plugins import get_plugin
1112
from rdmo.core.constants import VALUE_TYPE_FILE
12-
from rdmo.core.plugins import get_plugin
1313
from rdmo.core.utils import markdown2html
1414

1515
from .constants import ROLE_CHOICES

rdmo/projects/imports.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
import requests
1313

14+
from rdmo.config.plugins import PluginBase
1415
from rdmo.core.imports import handle_fetched_file
15-
from rdmo.core.plugins import Plugin
1616
from rdmo.core.xml import get_ns_map, get_uri, read_xml_file
1717
from rdmo.domain.models import Attribute
1818
from rdmo.options.models import Option
@@ -25,7 +25,7 @@
2525
log = logging.getLogger(__name__)
2626

2727

28-
class Import(Plugin):
28+
class Import(PluginBase):
2929

3030
plugin_type = 'project_import'
3131
accept = None

rdmo/projects/management/commands/export_projects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.core.management.base import BaseCommand, CommandError
66
from django.db.models import Prefetch
77

8-
from rdmo.core.plugins import get_plugin
8+
from rdmo.config.plugins import get_plugin
99
from rdmo.core.utils import render_to_format
1010
from rdmo.projects.models import Project
1111
from rdmo.projects.utils import get_value_path

rdmo/projects/models/integration.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ def provider(self):
3939
.for_context(plugin_type="issue_provider", project=self.project)
4040
.filter(uri_path__contains=self.provider_key)
4141
)
42-
provider = plugins.first().initialize_class() if plugins else None
43-
return provider
42+
if plugins.exists():
43+
return plugins.first().initialize_class()
44+
else:
45+
return None
4446

4547
def get_option_value(self, key):
4648
try:

0 commit comments

Comments
 (0)