From b329058c1ad06fe9c1afd56c81e0ad27dbef06b8 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Mon, 31 Aug 2020 18:59:27 +0200 Subject: [PATCH] Revert "[enh] test: load each engine to check for syntax errors" This reverts commit 4fb3ed2c6335b68f6b28ebc68d5d22f2fd621648. --- searx/engines/__init__.py | 13 +++++++------ searx/webapp.py | 9 +++++---- tests/unit/test_engines.py | 13 ------------- 3 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 tests/unit/test_engines.py diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 70b5ba166..48c02e2e7 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -72,8 +72,11 @@ def load_engine(engine_data): engine_module = engine_data['engine'] - # can raise an exception - engine = load_module(engine_module + '.py', engine_dir) + try: + engine = load_module(engine_module + '.py', engine_dir) + except: + logger.exception('Cannot load engine "{}"'.format(engine_module)) + return None for param_name in engine_data: if param_name == 'engine': @@ -251,11 +254,9 @@ def load_engines(engine_list): global engines engines.clear() for engine_data in engine_list: - try: - engine = load_engine(engine_data) + engine = load_engine(engine_data) + if engine is not None: engines[engine.name] = engine - except: - logger.exception('Cannot load engine "{}"'.format(engine_data['engine'])) return engines diff --git a/searx/webapp.py b/searx/webapp.py index 8a07d5ff1..4c0eceaaf 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -136,6 +136,11 @@ app.jinja_env.lstrip_blocks = True app.jinja_env.add_extension('jinja2.ext.loopcontrols') app.secret_key = settings['server']['secret_key'] +if not searx_debug \ + or os.environ.get("WERKZEUG_RUN_MAIN") == "true" \ + or os.environ.get('UWSGI_ORIGINAL_PROC_NAME') is not None: + initialize_engines(settings['engines']) + babel = Babel(app) rtl_locales = ['ar', 'arc', 'bcc', 'bqi', 'ckb', 'dv', 'fa', 'fa_IR', 'glk', 'he', @@ -1046,10 +1051,6 @@ def page_not_found(e): def run(): - if not searx_debug \ - or os.environ.get("WERKZEUG_RUN_MAIN") == "true" \ - or os.environ.get('UWSGI_ORIGINAL_PROC_NAME') is not None: - initialize_engines(settings['engines']) logger.debug('starting webserver on %s:%s', settings['server']['bind_address'], settings['server']['port']) app.run( debug=searx_debug, diff --git a/tests/unit/test_engines.py b/tests/unit/test_engines.py deleted file mode 100644 index 3f5f8dc80..000000000 --- a/tests/unit/test_engines.py +++ /dev/null @@ -1,13 +0,0 @@ -# -*- coding: utf-8 -*- - -import unittest2 as unittest -from unittest2.util import strclass -from searx.engines import load_engine -from searx import settings - - -class TestEngine(unittest.TestCase): - - def test_engines(self): - for engine_data in settings['engines']: - load_engine(engine_data)