diff options
| author | Markus Heiser <markus.heiser@darmarIT.de> | 2026-06-30 19:22:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-30 19:22:23 +0200 |
| commit | d115c61a7049ce798b73713446dbcfc77bb911b7 (patch) | |
| tree | 3de3eaf37515985299583b109f08eef6122e3be9 /searx/engines | |
| parent | c5b1d066e57ecb5f020e71a14e246e38f8c2beca (diff) | |
[fix] clarify the mess of Engine.setup and Engine.init (#6343)
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines')
| -rw-r--r-- | searx/engines/__init__.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 4175c9414..355cecd2c 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -269,21 +269,27 @@ def is_engine_active(engine: "Engine | types.ModuleType"): def call_engine_setup(engine: "Engine | types.ModuleType", engine_data: dict[str, t.Any]) -> bool: - setup_ok = False + + setup_ok: bool | None = 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)) + logger.error(f"engine's setup method isn't a callable (is of type: {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)) + logger.exception(f"(PID {os.getpid()}) {engine.name}: engine SETUP failed, exception: {e}") + setup_ok = False + + # The evaluation of the return value is analogous to Engine.init + if setup_ok is None: + setup_ok = True if not setup_ok: - logger.error("%s: Engine setup was not successful, engine is set to inactive.", engine.name) + logger.error(f"(PID {os.getpid()}) {engine.name}: engine setup was not successful") return setup_ok @@ -311,14 +317,16 @@ def load_engines(engine_list: list[dict[str, t.Any]]): for engine_data in engine_list: if engine_data.get("inactive") is True: continue + engine = load_engine(engine_data) + if engine: register_engine(engine) else: # if an engine can't be loaded (if for example the engine is missing # tor or some other requirements) its set to inactive! logger.error( - f"(PID {os.getpid()}) loading engine %s failed: set engine to inactive!", engine_data.get("name", "???") + f"(PID {os.getpid()}) {engine_data.get('name', '???')}: can't register engine (loading engine failed)" ) engine_data["inactive"] = True return engines |
