fix(37): import doesn't works for some python version

This commit is contained in:
egarette@silique.fr 2024-11-04 12:15:17 +01:00
parent ad1928bc88
commit dcc42a4ea0

View file

@ -37,16 +37,23 @@ def get_level(module):
return module.level
def get_annotators(annotators, module_name):
annotators[module_name] = []
def get_annotators(annotators, module_name, file_name=None):
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():
path = str(pathobj)
if not path.endswith(".py") or path.endswith("__.py"):
continue
if file_name is not None and not path.endswith(full_file_name):
continue
module = load_modules(module_name, path)
if "Annotator" not in dir(module):
continue
annotators[module_name].append(module.Annotator)
annotators[_module_name].append(module.Annotator)
class SpaceAnnotator: # pylint: disable=R0903
@ -66,7 +73,7 @@ class SpaceAnnotator: # pylint: disable=R0903
get_annotators(ANNOTATORS, extra_annotator)
for plugin in objectspace.plugins:
try:
get_annotators(ANNOTATORS, f"rougail.{plugin}.annotator")
get_annotators(ANNOTATORS, f"rougail.{plugin}", "annotator")
except ModuleNotFoundError:
pass
annotators = ANNOTATORS["rougail.annotator"].copy()