ModuleList: Remove hard dependency on ClassFinder
This commit is contained in:
parent
2106585d4c
commit
8fe5c77acd
@ -2,6 +2,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
from i3pystatus.core.imputil import ClassFinder
|
||||||
|
|
||||||
from i3pystatus.core import io, util
|
from i3pystatus.core import io, util
|
||||||
from i3pystatus.core.modules import Module, START_HOOKS
|
from i3pystatus.core.modules import Module, START_HOOKS
|
||||||
@ -27,7 +28,7 @@ class Status:
|
|||||||
else:
|
else:
|
||||||
self.io = io.IOHandler(input_stream)
|
self.io = io.IOHandler(input_stream)
|
||||||
|
|
||||||
self.modules = util.ModuleList(self, Module)
|
self.modules = util.ModuleList(self, ClassFinder(Module))
|
||||||
|
|
||||||
def register(self, module, *args, **kwargs):
|
def register(self, module, *args, **kwargs):
|
||||||
"""Register a new module."""
|
"""Register a new module."""
|
||||||
|
@ -61,9 +61,9 @@ def round_dict(dic, places):
|
|||||||
|
|
||||||
|
|
||||||
class ModuleList(collections.UserList):
|
class ModuleList(collections.UserList):
|
||||||
def __init__(self, status_handler, module_base):
|
def __init__(self, status_handler, class_finder):
|
||||||
self.status_handler = status_handler
|
self.status_handler = status_handler
|
||||||
self.finder = ClassFinder(module_base)
|
self.finder = class_finder
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def append(self, module, *args, **kwargs):
|
def append(self, module, *args, **kwargs):
|
||||||
|
@ -118,7 +118,7 @@ def get_all(module_path, heading, finder=None, ignore=None):
|
|||||||
finder = ClassFinder(i3pystatus.Module)
|
finder = ClassFinder(i3pystatus.Module)
|
||||||
|
|
||||||
for name, module in get_modules(module_path):
|
for name, module in get_modules(module_path):
|
||||||
classes = finder.search_module(module)
|
classes = finder.get_matching_classes(module)
|
||||||
found = []
|
found = []
|
||||||
for cls in classes:
|
for cls in classes:
|
||||||
if cls.__name__ not in found:
|
if cls.__name__ not in found:
|
||||||
|
@ -130,7 +130,7 @@ class ModuleListTests(unittest.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.status_handler = MagicMock()
|
self.status_handler = MagicMock()
|
||||||
self.ml = util.ModuleList(self.status_handler, self.ModuleBase)
|
self.ml = util.ModuleList(self.status_handler, ClassFinder(self.ModuleBase))
|
||||||
|
|
||||||
def test_append_simple(self):
|
def test_append_simple(self):
|
||||||
module = self.ModuleBase()
|
module = self.ModuleBase()
|
||||||
|
Loading…
Reference in New Issue
Block a user