Skip to content

Commit aed5cd5

Browse files
jrcastro2utnapischtim
authored andcommitted
app: add init_functions_loader
* allows to pass entry points to execute functions just after the app is instantiated * closes #171
1 parent 417a61a commit aed5cd5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

invenio_base/app.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def create_app_factory(
3131
blueprints=None,
3232
converter_entry_points=None,
3333
converters=None,
34+
init_functions_entry_points=None,
3435
wsgi_factory=None,
3536
**app_kwargs,
3637
):
@@ -125,6 +126,13 @@ def _create_app(**kwargs):
125126
entry_points=blueprint_entry_points,
126127
modules=blueprints,
127128
)
129+
130+
# Load init functions
131+
init_functions_loader(
132+
app,
133+
entry_points=init_functions_entry_points,
134+
)
135+
128136

129137
app_loaded.send(_create_app, app=app)
130138

@@ -178,6 +186,20 @@ def cli(**params):
178186
return cli
179187

180188

189+
def init_functions_loader(app, entry_points=None):
190+
"""Run functions that should be executed after the application is instantiated.
191+
192+
:param entry_points: List of entry points providing to Flask extensions.
193+
194+
.. versionadded: 2.0.0
195+
"""
196+
def loader_init_func(func):
197+
with app.app_context():
198+
func(app)
199+
200+
_loader(app, loader_init_func, entry_points=entry_points)
201+
202+
181203
def app_loader(app, entry_points=None, modules=None):
182204
"""Run default application loader.
183205

0 commit comments

Comments
 (0)