From b3b86da7c75c5c3dec250b0bdde6e5d27ab8f526 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 23 2018 15:34:13 +0000 Subject: Add support for blueprints defined outside of pagure This is the basis for bringing in support for 3rd party extensions to pagure. Why we used a different configuration file? The content of the configuration file will be something like: ```` from pagure_taiga import taiga PLUGINS = [taiga.TAIGA_NS] ```` It will import the plugin to get its blueprint and store it in PLUGINS. There are high chances that the plugin we import will also import pagure's sources (for example to access the forms or simply the general configuration). So we had this defined in the main configuration file we would very quickly end up with circular imports that would be hard to untangle. Simply using PAGURE_CONFIG and PAGURE_PLUGIN to specify both configuration files solves that issue. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/flask_app.py b/pagure/flask_app.py index c6d4571..3a90c1a 100644 --- a/pagure/flask_app.py +++ b/pagure/flask_app.py @@ -128,6 +128,14 @@ def create_app(config=None): app.register_blueprint(PV) + # Import 3rd party blueprints + plugin_config = flask.config.Config('') + if "PAGURE_PLUGIN" in os.environ: + plugin_config.from_envvar("PAGURE_PLUGIN") + for blueprint in (plugin_config.get('PLUGINS') or []): + logger.info('Loading blueprint: %s', blueprint.name) + app.register_blueprint(blueprint) + themename = pagure_config.get("THEME", "default") here = os.path.abspath( os.path.join(os.path.dirname(os.path.abspath(__file__)))