reorganize annotator loader
This commit is contained in:
parent
4765744953
commit
b8e343c31d
1 changed files with 15 additions and 12 deletions
|
@ -58,9 +58,11 @@ def get_annotators(annotators, module_name):
|
||||||
annotators[module_name] = []
|
annotators[module_name] = []
|
||||||
for pathobj in importlib.resources.files(module_name).iterdir():
|
for pathobj in importlib.resources.files(module_name).iterdir():
|
||||||
path = str(pathobj)
|
path = str(pathobj)
|
||||||
if not path.endswith('__') and not path.endswith('__.py'):
|
if path.endswith('__') or path.endswith('__.py'):
|
||||||
|
continue
|
||||||
module = load_modules(path)
|
module = load_modules(path)
|
||||||
if 'Annotator' in dir(module):
|
if 'Annotator' not in dir(module):
|
||||||
|
continue
|
||||||
annotators[module_name].append(module.Annotator)
|
annotators[module_name].append(module.Annotator)
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,25 +71,26 @@ class SpaceAnnotator: # pylint: disable=R0903
|
||||||
"""
|
"""
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
objectspace,
|
objectspace,
|
||||||
eosfunc_files,
|
|
||||||
):
|
):
|
||||||
global ANNOTATORS
|
global ANNOTATORS
|
||||||
if ANNOTATORS is None:
|
if ANNOTATORS is None:
|
||||||
ANNOTATORS = {}
|
ANNOTATORS = {}
|
||||||
get_annotators(ANNOTATORS, 'rougail.annotator')
|
get_annotators(ANNOTATORS, 'rougail.annotator')
|
||||||
for extra_annotator in objectspace.rougailconfig['extra_annotators']:
|
for extra_annotator in objectspace.rougailconfig['extra_annotators']:
|
||||||
get_annotators(ANNOTATORS, extra_annotator)
|
if extra_annotator in ANNOTATORS:
|
||||||
for extra_annotator in objectspace.rougailconfig['extra_annotators']:
|
continue
|
||||||
if extra_annotator not in ANNOTATORS:
|
|
||||||
get_annotators(ANNOTATORS, extra_annotator)
|
get_annotators(ANNOTATORS, extra_annotator)
|
||||||
annotators = ANNOTATORS['rougail.annotator'].copy()
|
annotators = ANNOTATORS['rougail.annotator'].copy()
|
||||||
for extra_annotator in objectspace.rougailconfig['extra_annotators']:
|
for extra_annotator in objectspace.rougailconfig['extra_annotators']:
|
||||||
annotators.extend(ANNOTATORS[extra_annotator])
|
annotators.extend(ANNOTATORS[extra_annotator])
|
||||||
annotators = sorted(annotators, key=get_level)
|
annotators = sorted(annotators, key=get_level)
|
||||||
functions = []
|
functions = []
|
||||||
for eosfunc_file in eosfunc_files:
|
functions_files = objectspace.rougailconfig['functions_file']
|
||||||
if isfile(eosfunc_file):
|
if not isinstance(functions_files, list):
|
||||||
functions.extend(dir(load_modules(eosfunc_file)))
|
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:
|
for annotator in annotators:
|
||||||
annotator(objectspace,
|
annotator(objectspace,
|
||||||
functions,
|
functions,
|
||||||
|
|
Loading…
Reference in a new issue