Skip to content

Commit

Permalink
Remove straight.plugin from anitya dependencies
Browse files Browse the repository at this point in the history
This library caused issue with python 3.12 and as there is no update to this
library for 3 years it is best to just remove it.

The new solution is using standard libraries instead and doesn't introduce new
dependencies. Also no test was touched, so the logic is still the same.

Fixes #1769

Signed-off-by: Michal Konecny <[email protected]>
  • Loading branch information
Zlopez committed Apr 30, 2024
1 parent 4eca223 commit 5f22ecb
Show file tree
Hide file tree
Showing 4 changed files with 353 additions and 319 deletions.
31 changes: 22 additions & 9 deletions anitya/lib/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Module handling the load/call of the plugins of anitya."""

import inspect
import logging
import os
import pkgutil
from importlib import import_module

from straight.plugin import load

from anitya.lib.backends import BaseBackend
from anitya.lib.ecosystems import BaseEcosystem
from anitya.lib.versions import Version
import anitya.lib.backends as anitya_backends
import anitya.lib.ecosystems as anitya_ecosystems
import anitya.lib.versions as anitya_versions

_log = logging.getLogger(__name__)

Expand All @@ -38,7 +40,18 @@ def __init__(self, namespace, base_class):

def get_plugins(self):
"""Return the list of plugins."""
return load(self._namespace, subclasses=self._base_class)
module_path = os.path.dirname(self._namespace.__file__)
module_names = [name for _, name, _ in pkgutil.iter_modules([module_path])]
plugins = []
for module_name in module_names:
module = import_module(f"{self._namespace.__name__}.{module_name}")
classes = [obj for _, obj in inspect.getmembers(module, inspect.isclass)]
for cls in classes:
if cls == self._base_class:
continue
if issubclass(cls, self._base_class):
plugins.append(cls)
return plugins

def get_plugin_names(self):
"""Return the list of plugin names."""
Expand All @@ -54,9 +67,9 @@ def get_plugin(self, plugin_name):
return plugin


BACKEND_PLUGINS = _PluginManager("anitya.lib.backends", BaseBackend)
ECOSYSTEM_PLUGINS = _PluginManager("anitya.lib.ecosystems", BaseEcosystem)
VERSION_PLUGINS = _PluginManager("anitya.lib.versions", Version)
BACKEND_PLUGINS = _PluginManager(anitya_backends, anitya_backends.BaseBackend)
ECOSYSTEM_PLUGINS = _PluginManager(anitya_ecosystems, anitya_ecosystems.BaseEcosystem)
VERSION_PLUGINS = _PluginManager(anitya_versions, anitya_versions.Version)


def _load_backend_plugins(session):
Expand Down
1 change: 1 addition & 0 deletions news/1769.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove `straight.plugin` dependency
Loading

0 comments on commit 5f22ecb

Please sign in to comment.