From 33d10c20a1a9689e0e8a0beee079426755059b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Sun, 12 Sep 2021 22:39:23 +0200 Subject: [PATCH] Revert "Make app object easily accessible from gunicorn" This reverts commit 6e25af03c4409258b3e456519d453c7426241516. --- feedleware/__init__.py | 56 ++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/feedleware/__init__.py b/feedleware/__init__.py index 5b85277..70c120f 100644 --- a/feedleware/__init__.py +++ b/feedleware/__init__.py @@ -5,35 +5,37 @@ from os import environ from flask import Flask from . import twitch -# Setup logging -debug = environ.get("FLASK_ENV", "production") == "development" + logger = logging.getLogger(__name__) -level = logging.DEBUG if debug else logging.INFO -logging.basicConfig(level=level) - -# Read configuration -config_path = environ.get("FEEDLEWARE_CONFIG") - -if not config_path: - print( - "Please set the FEEDLEWARE_CONFIG environment variable", - file=sys.stderr, - ) - sys.exit(1) - -config = configparser.ConfigParser() -config.read(config_path) - -# Instantiate app and attach blueprints -app = Flask(__name__) - blueprints = { "twitch": twitch, } -for section in config.sections(): - if section in blueprints: - blueprint = blueprints[section].create_blueprint(config[section]) - app.register_blueprint(blueprint, url_prefix="/" + section) - else: - logger.warning("Unknown service '%s'", section) + +def create_app(): + """Read the app configuration and instantiate service blueprints.""" + debug = environ.get("FLASK_ENV", "production") == "development" + level = logging.DEBUG if debug else logging.INFO + logging.basicConfig(level=level) + + config_path = environ.get("FEEDLEWARE_CONFIG") + + if not config_path: + print( + "Please set the FEEDLEWARE_CONFIG environment variable", + file=sys.stderr, + ) + sys.exit(1) + + config = configparser.ConfigParser() + config.read(config_path) + app = Flask(__name__) + + for section in config.sections(): + if section in blueprints: + blueprint = blueprints[section].create_blueprint(config[section]) + app.register_blueprint(blueprint, url_prefix="/" + section) + else: + logger.warning("Unknown service '%s'", section) + + return app