Passed
Push — main ( 4ebf28...2312e0 )
by Jochen
07:25
created

_util   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

2 Functions

Rating   Name   Duplication   Size   Complexity  
A call_with_app_context() 0 4 2
A app_context() 0 8 2
1
"""
2
byceps.scripts.util
3
~~~~~~~~~~~~~~~~~~~
4
5
Utilities for scripts
6
7
:Copyright: 2006-2022 Jochen Kupperschmidt
8
:License: Revised BSD (see `LICENSE` file for details)
9
"""
10
11
from contextlib import contextmanager
12
from typing import Callable
13
14
from byceps.application import create_app
15
16
17
@contextmanager
18
def app_context():
19
    """Provide a context in which the application is available with the
20
    specified configuration.
21
    """
22
    app = create_app()
23
    with app.app_context():
24
        yield app
25
26
27
def call_with_app_context(func: Callable) -> None:
28
    """Call a callable inside of an application context."""
29
    with app_context():
30
        func()
31