Removed ModuleFinder, changed ClassFinder
ClassFinder: Removed exclude argument, which is basically covered with obj.__module__ == module.__name__ which ensures that no imported classes are found, which was the only use case for exclude.
This commit is contained in:
parent
a2104f5d2f
commit
92b2af56a8
@ -10,7 +10,7 @@ from .core.util import *
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"SettingsBase",
|
"SettingsBase",
|
||||||
"ClassFinder", "ModuleFinder",
|
"ClassFinder",
|
||||||
"Module", "AsyncModule", "IntervalModule",
|
"Module", "AsyncModule", "IntervalModule",
|
||||||
"i3pystatus", "I3statusHandler",
|
"i3pystatus", "I3statusHandler",
|
||||||
]
|
]
|
||||||
@ -56,7 +56,7 @@ class i3pystatus:
|
|||||||
else:
|
else:
|
||||||
self.io = core.io.IOHandler(input_stream)
|
self.io = core.io.IOHandler(input_stream)
|
||||||
|
|
||||||
self.finder = ModuleFinder()
|
self.finder = ClassFinder(Module)
|
||||||
|
|
||||||
def register(self, module, *args, **kwargs):
|
def register(self, module, *args, **kwargs):
|
||||||
"""Register a new module."""
|
"""Register a new module."""
|
||||||
@ -74,5 +74,3 @@ class i3pystatus:
|
|||||||
for module in self.modules:
|
for module in self.modules:
|
||||||
module.inject(j)
|
module.inject(j)
|
||||||
I3statusHandler = i3pystatus
|
I3statusHandler = i3pystatus
|
||||||
|
|
||||||
ModuleFinder = functools.partial(ClassFinder, baseclass=Module, exclude=[Module, IntervalModule, AsyncModule])
|
|
||||||
|
@ -100,16 +100,14 @@ class SettingsBase:
|
|||||||
class ClassFinder:
|
class ClassFinder:
|
||||||
"""Support class to find classes of specific bases in a module"""
|
"""Support class to find classes of specific bases in a module"""
|
||||||
|
|
||||||
def __init__(self, baseclass, exclude=[]):
|
def __init__(self, baseclass):
|
||||||
self.baseclass = baseclass
|
self.baseclass = baseclass
|
||||||
self.exclude = exclude
|
|
||||||
|
|
||||||
def predicate_factory(self, module):
|
def predicate_factory(self, module):
|
||||||
def predicate(obj):
|
def predicate(obj):
|
||||||
return (
|
return (
|
||||||
inspect.isclass(obj) and
|
inspect.isclass(obj) and
|
||||||
issubclass(obj, self.baseclass) and
|
issubclass(obj, self.baseclass) and
|
||||||
obj not in self.exclude and
|
|
||||||
obj.__module__ == module.__name__
|
obj.__module__ == module.__name__
|
||||||
)
|
)
|
||||||
return predicate
|
return predicate
|
||||||
|
@ -115,7 +115,7 @@ def get_module(finder, modname):
|
|||||||
def get_all(module_path, heading, finder=None):
|
def get_all(module_path, heading, finder=None):
|
||||||
mods = []
|
mods = []
|
||||||
if finder is None:
|
if finder is None:
|
||||||
finder = i3pystatus.ModuleFinder()
|
finder = i3pystatus.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.search_module(module)
|
||||||
|
Loading…
Reference in New Issue
Block a user