Total Complexity | 4 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |