~homeworkprod/byceps

26e992ecd4e753757356dc5a7346e5fb926f37b9 — Jochen Kupperschmidt 9 months ago 26c844f
Inline explicit app initialization step
4 files changed, 11 insertions(+), 19 deletions(-)

M app.py
M byceps/application.py
M serve.py
M tests/helpers.py
M app.py => app.py +1 -2
@@ 6,7 6,7 @@ application instance
:License: Revised BSD (see `LICENSE` file for details)
"""

from byceps.application import create_app, init_app
from byceps.application import create_app
from byceps import config
from byceps.database import db
from byceps.services.brand.dbmodels.brand import Brand


@@ 27,7 27,6 @@ from byceps.util.system import get_config_filename_from_env_or_exit
config_filename = get_config_filename_from_env_or_exit()

app = create_app(config_filename)
init_app(app)


if app.env == 'development':

M byceps/application.py => byceps/application.py +8 -11
@@ 72,6 72,14 @@ def create_app(

    _add_static_file_url_rules(app)

    app_mode = config.get_app_mode(app)
    if app_mode.is_admin():
        _init_admin_app(app)
    elif app_mode.is_site():
        _init_site_app(app)

    _load_announce_signal_handlers()

    return app




@@ 89,17 97,6 @@ def _add_static_file_url_rules(app: Flask) -> None:
    )


def init_app(app: Flask) -> None:
    """Initialize application."""
    app_mode = config.get_app_mode(app)
    if app_mode.is_admin():
        _init_admin_app(app)
    elif app_mode.is_site():
        _init_site_app(app)

    _load_announce_signal_handlers()


def _init_admin_app(app: Flask) -> None:
    """Initialize admin application."""
    app.add_url_rule(

M serve.py => serve.py +1 -2
@@ 6,11 6,10 @@ an environment variable.
:License: Revised BSD (see `LICENSE` file for details)
"""

from byceps.application import create_app, init_app
from byceps.application import create_app
from byceps.util.system import get_config_filename_from_env_or_exit


config_filename = get_config_filename_from_env_or_exit()

app = create_app(config_filename)
init_app(app)

M tests/helpers.py => tests/helpers.py +1 -4
@@ 14,7 14,7 @@ from typing import Any, Dict, Optional

from flask import appcontext_pushed, g

from byceps.application import create_app, init_app
from byceps.application import create_app
from byceps.database import db, generate_uuid
from byceps.services.authentication.session.models.current_user import (
    CurrentUser,


@@ 36,13 36,11 @@ CONFIG_FILENAME_TEST_ADMIN = _CONFIG_PATH / 'test_admin.py'

def create_admin_app(config_overrides: Optional[Dict[str, Any]] = None):
    app = create_app(CONFIG_FILENAME_TEST_ADMIN, config_overrides)
    init_app(app)
    return app


def create_site_app(config_overrides: Optional[Dict[str, Any]] = None):
    app = create_app(CONFIG_FILENAME_TEST_SITE, config_overrides)
    init_app(app)
    return app




@@ 53,7 51,6 @@ def generate_token() -> str:
@contextmanager
def app_context(*, config_filename=CONFIG_FILENAME_TEST_SITE):
    app = create_app(config_filename)
    init_app(app)

    with app.app_context():
        yield app