summaryrefslogtreecommitdiff
path: root/searx/engines/__init__.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2025-09-11 19:10:27 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2025-09-18 19:40:03 +0200
commit8f8343dc0d78bb57215afc3e99fd9000fce6e0cf (patch)
tree7c0aa8587ed4bc47e403b4148a308191e2d21c55 /searx/engines/__init__.py
parent23257bddce864cfc44d64324dee36b32b1cf5248 (diff)
[mod] addition of various type hints / engine processors
Continuation of #5147 .. typification of the engine processors. BTW: - removed obsolete engine property https_support - fixed & improved currency_convert - engine instances can now implement a engine.setup method [#5147] https://github.com/searxng/searxng/pull/5147 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/__init__.py')
-rw-r--r--searx/engines/__init__.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py
index b1e24aea2..30ef7fd75 100644
--- a/searx/engines/__init__.py
+++ b/searx/engines/__init__.py
@@ -51,7 +51,10 @@ ENGINE_DEFAULT_ARGS: dict[str, int | str | list[t.Any] | dict[str, t.Any] | bool
DEFAULT_CATEGORY = 'other'
categories: "dict[str, list[Engine|types.ModuleType]]" = {'general': []}
+
engines: "dict[str, Engine | types.ModuleType]" = {}
+"""Global registered engine instances."""
+
engine_shortcuts = {}
"""Simple map of registered *shortcuts* to name of the engine (or ``None``).
@@ -144,6 +147,9 @@ def load_engine(engine_data: dict[str, t.Any]) -> "Engine | types.ModuleType | N
set_loggers(engine, engine_name)
+ if not call_engine_setup(engine, engine_data):
+ return None
+
if not any(cat in settings['categories_as_tabs'] for cat in engine.categories):
engine.categories.append(DEFAULT_CATEGORY)
@@ -223,6 +229,25 @@ def is_engine_active(engine: "Engine | types.ModuleType"):
return True
+def call_engine_setup(engine: "Engine | types.ModuleType", engine_data: dict[str, t.Any]) -> bool:
+ setup_ok = False
+ setup_func = getattr(engine, "setup", None)
+
+ if setup_func is None:
+ setup_ok = True
+ elif not callable(setup_func):
+ logger.error("engine's setup method isn't a callable (is of type: %s)", type(setup_func))
+ else:
+ try:
+ setup_ok = engine.setup(engine_data)
+ except Exception as e: # pylint: disable=broad-except
+ logger.exception('exception : {0}'.format(e))
+
+ if not setup_ok:
+ logger.error("%s: Engine setup was not successful, engine is set to inactive.", engine.name)
+ return setup_ok
+
+
def register_engine(engine: "Engine | types.ModuleType"):
if engine.name in engines:
logger.error('Engine config error: ambiguous name: {0}'.format(engine.name))