From dcc42a4ea031b683295bb38d4c6ab87c10ffc02d Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 4 Nov 2024 12:15:17 +0100 Subject: [PATCH] fix(37): import doesn't works for some python version --- src/rougail/annotator/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/rougail/annotator/__init__.py b/src/rougail/annotator/__init__.py index 3660b1d5f..74d4c0518 100644 --- a/src/rougail/annotator/__init__.py +++ b/src/rougail/annotator/__init__.py @@ -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()