diff --git a/src/rougail/annotator/__init__.py b/src/rougail/annotator/__init__.py index fbb3b866e..c7fce21f1 100644 --- a/src/rougail/annotator/__init__.py +++ b/src/rougail/annotator/__init__.py @@ -58,10 +58,12 @@ def get_annotators(annotators, module_name): annotators[module_name] = [] for pathobj in importlib.resources.files(module_name).iterdir(): path = str(pathobj) - if not path.endswith('__') and not path.endswith('__.py'): - module = load_modules(path) - if 'Annotator' in dir(module): - annotators[module_name].append(module.Annotator) + if path.endswith('__') or path.endswith('__.py'): + continue + module = load_modules(path) + if 'Annotator' not in dir(module): + continue + annotators[module_name].append(module.Annotator) class SpaceAnnotator: # pylint: disable=R0903 @@ -69,25 +71,26 @@ class SpaceAnnotator: # pylint: disable=R0903 """ def __init__(self, objectspace, - eosfunc_files, ): global ANNOTATORS if ANNOTATORS is None: ANNOTATORS = {} get_annotators(ANNOTATORS, 'rougail.annotator') - for extra_annotator in objectspace.rougailconfig['extra_annotators']: - get_annotators(ANNOTATORS, extra_annotator) for extra_annotator in objectspace.rougailconfig['extra_annotators']: - if extra_annotator not in ANNOTATORS: - get_annotators(ANNOTATORS, extra_annotator) + if extra_annotator in ANNOTATORS: + continue + get_annotators(ANNOTATORS, extra_annotator) annotators = ANNOTATORS['rougail.annotator'].copy() for extra_annotator in objectspace.rougailconfig['extra_annotators']: annotators.extend(ANNOTATORS[extra_annotator]) annotators = sorted(annotators, key=get_level) functions = [] - for eosfunc_file in eosfunc_files: - if isfile(eosfunc_file): - functions.extend(dir(load_modules(eosfunc_file))) + functions_files = objectspace.rougailconfig['functions_file'] + if not isinstance(functions_files, list): + functions_files = [functions_files] + for functions_file in functions_files: + if isfile(functions_file): + functions.extend(dir(load_modules(functions_file))) for annotator in annotators: annotator(objectspace, functions,