diff options
| author | Alexandre Flament <alex@al-f.net> | 2021-09-13 19:37:51 +0200 |
|---|---|---|
| committer | Alexandre Flament <alex@al-f.net> | 2021-10-06 19:18:19 +0200 |
| commit | 2b4fef71186be1e4a9ce160ddfa6707e2f138a3e (patch) | |
| tree | f1e3037e04a533849bcd1834e35b2b4af93f87da /searx/webapp.py | |
| parent | adeb084cf4ffc59f1e49b47d049e7541be6dd5dd (diff) | |
plugins: refactor initialization
add a new function "init" call when the app starts.
The function can:
* return False to disable the plugin.
* modify the Flask app.
Diffstat (limited to 'searx/webapp.py')
| -rwxr-xr-x | searx/webapp.py | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/searx/webapp.py b/searx/webapp.py index 2b2fb9cab..61992c99f 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -85,7 +85,7 @@ from searx.utils import ( ) from searx.version import VERSION_STRING, GIT_URL, GIT_BRANCH from searx.query import RawTextQuery -from searx.plugins import plugins +from searx.plugins import plugins, initialize as plugin_initialize from searx.plugins.oa_doi_rewrite import get_doi_resolver from searx.preferences import ( Preferences, @@ -158,25 +158,6 @@ app.jinja_env.lstrip_blocks = True app.jinja_env.add_extension('jinja2.ext.loopcontrols') # pylint: disable=no-member app.secret_key = settings['server']['secret_key'] -# see https://flask.palletsprojects.com/en/1.1.x/cli/ -# True if "FLASK_APP=searx/webapp.py FLASK_ENV=development flask run" -flask_run_development = ( - os.environ.get("FLASK_APP") is not None - and os.environ.get("FLASK_ENV") == 'development' - and is_flask_run_cmdline() -) - -# True if reload feature is activated of werkzeug, False otherwise (including uwsgi, etc..) -# __name__ != "__main__" if searx.webapp is imported (make test, make docs, uwsgi...) -# see run() at the end of this file : searx_debug activates the reload feature. -werkzeug_reloader = flask_run_development or (searx_debug and __name__ == "__main__") - -# initialize the engines except on the first run of the werkzeug server. -if (not werkzeug_reloader - or (werkzeug_reloader - and os.environ.get("WERKZEUG_RUN_MAIN") == "true") ): - search_initialize(enable_checker=True) - babel = Babel(app) # used when translating category names @@ -1351,6 +1332,27 @@ def page_not_found(_e): return render('404.html'), 404 +# see https://flask.palletsprojects.com/en/1.1.x/cli/ +# True if "FLASK_APP=searx/webapp.py FLASK_ENV=development flask run" +flask_run_development = ( + os.environ.get("FLASK_APP") is not None + and os.environ.get("FLASK_ENV") == 'development' + and is_flask_run_cmdline() +) + +# True if reload feature is activated of werkzeug, False otherwise (including uwsgi, etc..) +# __name__ != "__main__" if searx.webapp is imported (make test, make docs, uwsgi...) +# see run() at the end of this file : searx_debug activates the reload feature. +werkzeug_reloader = flask_run_development or (searx_debug and __name__ == "__main__") + +# initialize the engines except on the first run of the werkzeug server. +if (not werkzeug_reloader + or (werkzeug_reloader + and os.environ.get("WERKZEUG_RUN_MAIN") == "true") ): + plugin_initialize(app) + search_initialize(enable_checker=True) + + def run(): logger.debug( 'starting webserver on %s:%s', |