fix(37): import doesn't works for some python version #39
1 changed files with 11 additions and 4 deletions
|
@ -37,16 +37,23 @@ def get_level(module):
|
||||||
return module.level
|
return module.level
|
||||||
|
|
||||||
|
|
||||||
def get_annotators(annotators, module_name):
|
def get_annotators(annotators, module_name, file_name=None):
|
||||||
annotators[module_name] = []
|
if file_name is None:
|
||||||
|
_module_name = module_name
|
||||||
|
else:
|
||||||
|
_module_name = module_name + "." + file_name
|
||||||
|
full_file_name = f"/{file_name}.py"
|
||||||
|
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(".py") or path.endswith("__.py"):
|
if not path.endswith(".py") or path.endswith("__.py"):
|
||||||
continue
|
continue
|
||||||
|
if file_name is not None and not path.endswith(full_file_name):
|
||||||
|
continue
|
||||||
module = load_modules(module_name, path)
|
module = load_modules(module_name, path)
|
||||||
if "Annotator" not in dir(module):
|
if "Annotator" not in dir(module):
|
||||||
continue
|
continue
|
||||||
annotators[module_name].append(module.Annotator)
|
annotators[_module_name].append(module.Annotator)
|
||||||
|
|
||||||
|
|
||||||
class SpaceAnnotator: # pylint: disable=R0903
|
class SpaceAnnotator: # pylint: disable=R0903
|
||||||
|
@ -66,7 +73,7 @@ class SpaceAnnotator: # pylint: disable=R0903
|
||||||
get_annotators(ANNOTATORS, extra_annotator)
|
get_annotators(ANNOTATORS, extra_annotator)
|
||||||
for plugin in objectspace.plugins:
|
for plugin in objectspace.plugins:
|
||||||
try:
|
try:
|
||||||
get_annotators(ANNOTATORS, f"rougail.{plugin}.annotator")
|
get_annotators(ANNOTATORS, f"rougail.{plugin}", "annotator")
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
pass
|
pass
|
||||||
annotators = ANNOTATORS["rougail.annotator"].copy()
|
annotators = ANNOTATORS["rougail.annotator"].copy()
|
||||||
|
|
Loading…
Reference in a new issue